Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregation ¶
type Aggregation struct {
Type types.AggregationType `json:"type"`
// Field is the key in $event.properties on which the aggregation is to be applied
// For ex if the aggregation type is sum for API usage, the field could be "duration_ms"
Field string `json:"field,omitempty"`
// Multiplier is the multiplier for the aggregation
// For ex if the aggregation type is sum_with_multiplier for API usage, the multiplier could be 1000
// to scale up by a factor of 1000. If not provided, it will be null.
Multiplier *decimal.Decimal `json:"multiplier,omitempty" swaggertype:"string"`
// BucketSize is used only for MAX aggregation when windowed aggregation is needed
// It defines the size of time windows to calculate max values within
BucketSize types.WindowSize `json:"bucket_size,omitempty"`
}
type Filter ¶
type Filter struct {
// Key is the key for the filter from $event.properties
// Currently we support only first level keys in the properties and not nested keys
Key string `json:"key"`
// Values are the possible values for the filter to be considered for the meter
// For ex "model_name" could have values "o1-mini", "gpt-4o" etc
Values []string `json:"values"`
}
type Meter ¶
type Meter struct {
// ID is the unique identifier for the meter
ID string `db:"id" json:"id"`
// EventName is the unique identifier for the event that this meter is tracking
// It is a mandatory field in the events table and hence being used as the primary matching field
// We can have multiple meters tracking the same event but with different filters and aggregation
EventName string `db:"event_name" json:"event_name"`
// Name is the display name of the meter
Name string `db:"name" json:"name"`
// Aggregation defines the aggregation type and field for the meter
// It is used to aggregate the events into a single value for calculating the usage
Aggregation Aggregation `db:"aggregation" json:"aggregation"`
// Filters define the criteria for the meter to be applied on the events before aggregation
// It also defines the possible values on which later the charges will be applied
Filters []Filter `db:"filters" json:"filters"`
// ResetUsage defines whether the usage should be reset periodically or not
// For ex meters tracking total storage used do not get reset but meters tracking
// total API requests do.
ResetUsage types.ResetUsage `db:"reset_usage" json:"reset_usage"`
// EnvironmentID is the environment identifier for the meter
EnvironmentID string `db:"environment_id" json:"environment_id"`
// BaseModel is the base model for the meter
types.BaseModel
}
func FromEntList ¶
FromEntList converts a list of Ent Meters to domain Meters
func (*Meter) HasBucketSize ¶ added in v1.0.22
HasBucketSize returns true if this meter has a bucket size configured
func (*Meter) IsBucketedMaxMeter ¶ added in v1.0.22
IsBucketedMaxMeter returns true if this is a max aggregation meter with bucket size
func (*Meter) IsBucketedSumMeter ¶ added in v1.0.47
IsBucketedSumMeter returns true if this is a sum aggregation meter with bucket size
func (*Meter) ToEntAggregation ¶
func (m *Meter) ToEntAggregation() schema.MeterAggregation
ToEntAggregation converts domain Aggregation to Ent Aggregation
func (*Meter) ToEntFilters ¶
func (m *Meter) ToEntFilters() []schema.MeterFilter
ToEntFilters converts domain Filters to Ent Filters
type Repository ¶
type Repository interface {
CreateMeter(ctx context.Context, meter *Meter) error
GetMeter(ctx context.Context, id string) (*Meter, error)
List(ctx context.Context, filter *types.MeterFilter) ([]*Meter, error)
ListAll(ctx context.Context, filter *types.MeterFilter) ([]*Meter, error)
Count(ctx context.Context, filter *types.MeterFilter) (int, error)
DisableMeter(ctx context.Context, id string) error
UpdateMeter(ctx context.Context, id string, filters []Filter) error
}
Click to show internal directories.
Click to hide internal directories.