rates

package
v0.1.8-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRateInvalid = errors.New("rate must be greater that zero")

ErrRateInvalid is the error that signals about invalid rate value

Functions

This section is empty.

Types

type NamespaceRule

type NamespaceRule struct {
	Rule
	// contains filtered or unexported fields
}

NamespaceRule is the one of the rule types

func NewNamespaceRule

func NewNamespaceRule(record RateRecord) (*NamespaceRule, error)

NewNamespaceRule is the constructor for NamespaceRule

func (*NamespaceRule) Match

func (rule *NamespaceRule) Match(namespace string) bool

Match tries to match specified string with namespace regular expression

type NamespacedPodRule

type NamespacedPodRule struct {
	Rule
	// contains filtered or unexported fields
}

NamespacedPodRule is the one of the rule types

func NewNamespacedPodRule

func NewNamespacedPodRule(record RateRecord) (*NamespacedPodRule, error)

NewNamespacedPodRule is the constructor for NamespacedPodRule

func (*NamespacedPodRule) Match

func (rule *NamespacedPodRule) Match(namespace, pod string) bool

Match tries to match specified pair with namespace and pod regular expressions

type PodRule

type PodRule struct {
	Rule
	// contains filtered or unexported fields
}

PodRule is the one of the rule types

func NewPodRule

func NewPodRule(record RateRecord) (*PodRule, error)

NewPodRule is the constructor for PodRule

func (*PodRule) Match

func (rule *PodRule) Match(pod string) bool

Match tries to match specified string with pod regular expression

type RateRecord

type RateRecord struct {
	Namespace string
	Pod       string
	Rate      float64
}

RateRecord is the struct to unmarshal yaml list item to

type RateRecordsProvider

type RateRecordsProvider interface {
	RateRecords() ([]RateRecord, error)
}

RateRecordsProvider is the records provider interface

type RateRecordsProviderStub

type RateRecordsProviderStub struct{}

RateRecordsProviderStub is the stub that returns empty list of rate records

func NewRuleRecordsProviderStub

func NewRuleRecordsProviderStub() *RateRecordsProviderStub

NewRuleRecordsProviderStub is the constructor for RateRecordsProviderStub

func (*RateRecordsProviderStub) RateRecords

func (provider *RateRecordsProviderStub) RateRecords() ([]RateRecord, error)

RateRecords returns empty list of rate records

type RateRecordsProviderYaml

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

RateRecordsProvider is the implementation of records provider that tries to get them from yaml file

func NewRateRecordsProviderYaml

func NewRateRecordsProviderYaml(filePath string) *RateRecordsProviderYaml

NewRateRecordsProviderYaml is the constructor for RateRecordsProvider

func (*RateRecordsProviderYaml) RateRecords

func (provider *RateRecordsProviderYaml) RateRecords() ([]RateRecord, error)

RateRecords should be used to obtain records from list containing yaml

type Rater

type Rater struct {
	sync.RWMutex

	NamespacedPodRules []*NamespacedPodRule
	PodRules           []*PodRule
	NamespaceRules     []*NamespaceRule
	// contains filtered or unexported fields
}

Rater is the structure that is used for getting rates according to regexp rules received from provider

func NewRater

func NewRater(provider RateRecordsProvider, rateDefault float64) (*Rater, error)

NewRater is the constructor for Rater

func (*Rater) Rate

func (rater *Rater) Rate(namespace string, pod string) float64

Rate tries to find a rule that matches namespace and pod and returns corresponding rate

func (*Rater) Retrieve

func (rater *Rater) Retrieve() error

Retrieve may be called periodically to obtain changes in rules

type Rule

type Rule struct {
	Rate float64
}

Rule is the base class of rule

func NewRule

func NewRule(rate float64) (*Rule, error)

NewRule is the constructor for Rule

Jump to

Keyboard shortcuts

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