Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/client/go/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions api/client/go/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
cloudevents "github.com/cloudevents/sdk-go/v2/event"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"

"github.com/openmeterio/openmeter/openmeter/meter"
)

func TestIngest(t *testing.T) {
Expand Down Expand Up @@ -120,7 +118,7 @@ func TestGetMeter(t *testing.T) {
meter := Meter{
Slug: "meter-1",
Description: lo.ToPtr("Test Meter"),
Aggregation: MeterAggregation(meter.MeterAggregationSum),
Aggregation: MeterAggregationSum,
ValueProperty: lo.ToPtr("$.tokens"),
GroupBy: lo.ToPtr(map[string]string{"model": "$.model", "type": "$.type"}),
}
Expand Down Expand Up @@ -156,14 +154,14 @@ func TestListMeters(t *testing.T) {
{
Slug: "meter-1",
Description: lo.ToPtr("Test Meter"),
Aggregation: MeterAggregation(meter.MeterAggregationSum),
Aggregation: MeterAggregationSum,
ValueProperty: lo.ToPtr("$.tokens"),
GroupBy: lo.ToPtr(map[string]string{"model": "$.model", "type": "$.type"}),
},
{
Slug: "meter-2",
Description: lo.ToPtr("Test Meter 2"),
Aggregation: MeterAggregation(meter.MeterAggregationSum),
Aggregation: MeterAggregationSum,
ValueProperty: lo.ToPtr("$.tokens"),
GroupBy: lo.ToPtr(map[string]string{"model": "$.model", "type": "$.type"}),
},
Expand Down
4 changes: 4 additions & 0 deletions api/client/go/codegen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ compatibility:
# See: https://github.com/oapi-codegen/oapi-codegen/issues/778
disable-required-readonly-as-pointer: true
always-prefix-enum-values: true
# Redirect internal pkg/models types to the client-local models package so
# that the generated client has no dependency on the root openmeter module.
import-mapping:
github.com/openmeterio/openmeter/pkg/models: github.com/openmeterio/openmeter/api/client/go/models
output: ./client.gen.go
12 changes: 12 additions & 0 deletions api/client/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/openmeterio/openmeter/api/client/go

go 1.25.5

require (
github.com/alpacahq/alpacadecimal v0.0.9
github.com/cloudevents/sdk-go/v2 v2.16.2
github.com/getkin/kin-openapi v0.134.0
github.com/oapi-codegen/runtime v1.4.0
github.com/samber/lo v1.49.1
github.com/stretchr/testify v1.10.0
)
40 changes: 40 additions & 0 deletions api/client/go/models/percentage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package models

import (
"fmt"

"github.com/alpacahq/alpacadecimal"
)

type Percentage struct {
alpacadecimal.Decimal
}

// NewPercentage creates a new Percentage from a numeric value, representation:
// 50% is represented as 50
func NewPercentage[T float64 | int | alpacadecimal.Decimal](value T) Percentage {
p := Percentage{}

switch v := any(value).(type) {
case int:
p = Percentage{Decimal: alpacadecimal.NewFromInt(int64(v))}
case float64:
p = Percentage{Decimal: alpacadecimal.NewFromFloat(v)}
case alpacadecimal.Decimal:
p = Percentage{Decimal: v}
}

return p
}

func (p Percentage) MarshalJSON() ([]byte, error) {
return []byte(p.Decimal.String()), nil
}

func (p *Percentage) UnmarshalJSON(data []byte) error {
return p.Decimal.UnmarshalJSON(data)
}

func (p Percentage) String() string {
return fmt.Sprintf("%s%%", p.Decimal.String())
}
28 changes: 28 additions & 0 deletions api/client/go/models/problem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package models

import "fmt"

// ProblemType contains a URI that identifies the problem type.
type ProblemType string

const ProblemTypeDefault = ProblemType("about:blank")

// StatusProblem is the RFC 7807 problem detail object.
type StatusProblem struct {
Err error `json:"-"`

Type ProblemType `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail,omitempty"`
Instance string `json:"instance,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}

func (p *StatusProblem) Error() string {
if p.Err == nil {
return fmt.Sprintf("[%s] %s", p.Title, p.Detail)
}

return fmt.Sprintf("[%s] %s - %s", p.Title, p.Err.Error(), p.Detail)
}
9 changes: 9 additions & 0 deletions deploy/charts/openmeter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ kafka:
# **Not recommended for production environments.**
enabled: true

image:
registry: registry.bitnami.com

listeners:
client:
name: plain
Expand Down Expand Up @@ -210,6 +213,9 @@ redis:
# All further values can be configured in the `redis` section.
enabled: true

image:
registry: registry.bitnami.com

auth:
enabled: false

Expand All @@ -221,6 +227,9 @@ postgresql:
# All further values can be configured in the `postgres` section.
enabled: true

image:
registry: registry.bitnami.com

nameOverride: postgres

primary:
Expand Down