meter

package
v1.0.0-beta.199 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 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.

func ValidateMeter

func ValidateMeter(
	key string,
	name string,
	description *string,
	aggregation MeterAggregation,
	eventType string,
	eventFrom *time.Time,
	valueProperty *string,
	groupBy map[string]string,
) error

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)
	DeleteMeter(ctx context.Context, input DeleteMeterInput) 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 MeterOptions

type MeterOptions struct {
	ID          string
	Description *string
	GroupBy     map[string]string
}

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 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 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