meter

package
v1.0.0-beta.201 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMeterNotFoundError

func IsMeterNotFoundError(err error) bool

IsMeterNotFoundError returns true if the error is a MeterNotFoundError.

func NewMeterNotFoundError

func NewMeterNotFoundError(meterSlug string) error

NewMeterNotFoundError returns a new MeterNotFoundError.

func ParseEvent

func ParseEvent(meter Meter, ev event.Event) (*float64, *string, map[string]string, error)

ParseEvent validates and parses an event against a meter.

Types

type CreateMeterInput

type CreateMeterInput struct {
	Namespace     string
	Name          string
	Key           string
	Description   *string
	Aggregation   MeterAggregation
	EventType     string
	EventFrom     *time.Time
	ValueProperty *string
	GroupBy       map[string]string
}

CreateMeterInput is a parameter object for creating a meter.

func (CreateMeterInput) Validate

func (i CreateMeterInput) Validate() error

Validate validates the create meter input.

type DeleteMeterInput

type DeleteMeterInput struct {
	Namespace string
	IDOrSlug  string
}

DeleteMeterInput is a parameter object for deleting a meter.

func (DeleteMeterInput) Validate

func (i DeleteMeterInput) Validate() error

Validate validates the delete meter input.

type GetMeterInput

type GetMeterInput struct {
	Namespace string
	IDOrSlug  string
}

GetMeterInput is a parameter object for getting a meter.

func (GetMeterInput) Validate

func (i GetMeterInput) Validate() error

Validate validates the get meter input.

type ListMetersParams

type ListMetersParams struct {
	pagination.Page
	Namespace string

	SlugFilter *[]string

	// WithoutNamespace is a flag to list meters without a namespace.
	// We do this instead of letting the namespace be empty to avoid
	// accidental listing of all meters across all namespaces.
	WithoutNamespace bool
}

ListMetersParams is a parameter object for listing meters.

func (ListMetersParams) Validate

func (p ListMetersParams) Validate() error

Validate validates the list meters parameters.

type ManageService

type ManageService interface {
	Service

	CreateMeter(ctx context.Context, input CreateMeterInput) (Meter, error)
	UpdateMeter(ctx context.Context, input UpdateMeterInput) (Meter, error)
	DeleteMeter(ctx context.Context, input DeleteMeterInput) error

	// Observer hooks
	// Useful to coordinate with other services
	RegisterPreUpdateMeterHook(hook PreUpdateMeterHook) error
}

ManageService is an interface to manage meter service.

type Meter

type Meter struct {
	models.ManagedResource `mapstructure:",squash"`

	Key           string `mapstructure:"slug"`
	Aggregation   MeterAggregation
	EventType     string
	EventFrom     *time.Time
	ValueProperty *string
	GroupBy       map[string]string

	// Deprecated, always set to MINUTE
	WindowSize WindowSize
}

func ListAll

func ListAll(ctx context.Context, service Service, params ListMetersParams) ([]Meter, error)

ListAll returns a list of meters. Helper function for listing all meters. Page param will be ignored.

func ListMetersForAllNamespaces

func ListMetersForAllNamespaces(ctx context.Context, service Service) ([]Meter, error)

ListMetersForAllNamespaces returns a list of meters. Helper function for listing all meters across all namespaces.

func (Meter) Equal

func (m1 Meter) Equal(m2 Meter) error

func (*Meter) SupportsWindowSize

func (m *Meter) SupportsWindowSize(w *WindowSize) error

func (*Meter) Validate

func (m *Meter) Validate() error

type MeterAggregation

type MeterAggregation string
const (
	MeterAggregationSum         MeterAggregation = "SUM"
	MeterAggregationCount       MeterAggregation = "COUNT"
	MeterAggregationAvg         MeterAggregation = "AVG"
	MeterAggregationMin         MeterAggregation = "MIN"
	MeterAggregationMax         MeterAggregation = "MAX"
	MeterAggregationUniqueCount MeterAggregation = "UNIQUE_COUNT"
)

Note: keep values up to date in the meter package

func (MeterAggregation) IsValid

func (MeterAggregation) IsValid(input string) bool

func (MeterAggregation) Values

func (MeterAggregation) Values() (kinds []string)

Values provides list valid values for Enum

type MeterNotFoundError

type MeterNotFoundError struct {
	// contains filtered or unexported fields
}

MeterNotFoundError is returned when a meter is not found.

func (*MeterNotFoundError) Error

func (e *MeterNotFoundError) Error() string

Error returns the error message.

func (*MeterNotFoundError) Unwrap

func (e *MeterNotFoundError) Unwrap() error

Unwrap returns the wrapped error.

type MeterQueryRow

type MeterQueryRow struct {
	Value       float64            `json:"value"`
	WindowStart time.Time          `json:"windowStart"`
	WindowEnd   time.Time          `json:"windowEnd"`
	Subject     *string            `json:"subject"`
	GroupBy     map[string]*string `json:"groupBy"`
}

MeterQueryRow returns a single row from the meter dataset.

type PreUpdateMeterHook

type PreUpdateMeterHook = func(context.Context, UpdateMeterInput) error

PreUpdateMeterHook is a hook function to be called before updating a meter.

type Service

type Service interface {
	ListMeters(ctx context.Context, params ListMetersParams) (pagination.PagedResponse[Meter], error)
	GetMeterByIDOrSlug(ctx context.Context, input GetMeterInput) (Meter, error)
}

Meter is an interface for the meter service.

type UpdateMeterInput

type UpdateMeterInput struct {
	ID          models.NamespacedID
	Name        string
	Description *string
	GroupBy     map[string]string
}

UpdateMeterInput is a parameter object for creating a meter.

func (UpdateMeterInput) Validate

func (i UpdateMeterInput) Validate(valueProperty *string) error

Validate validates the create meter input.

type WindowSize

type WindowSize string
const (
	WindowSizeMinute WindowSize = "MINUTE"
	WindowSizeHour   WindowSize = "HOUR"
	WindowSizeDay    WindowSize = "DAY"
)

Note: keep values up to date in the meter package

func WindowSizeFromDuration

func WindowSizeFromDuration(duration time.Duration) (WindowSize, error)

func (WindowSize) AddTo

func (w WindowSize) AddTo(t time.Time) (time.Time, error)

func (WindowSize) Duration

func (w WindowSize) Duration() time.Duration

Duration returns the duration of the window size BEWARE: a day is NOT 24 hours

func (WindowSize) Truncate

func (w WindowSize) Truncate(t time.Time) (time.Time, error)

func (WindowSize) Values

func (WindowSize) Values() (kinds []string)

Values provides list valid values for Enum

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL