rules

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2019 License: Apache-2.0 Imports: 25 Imported by: 18

Documentation

Overview

Package rules is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// EmptyMatchResult is the result when no matches were found.
	EmptyMatchResult = NewMatchResult(kv.UninitializedVersion, timeNanosMax, metadata.DefaultStagedMetadatas, nil)
)

Functions

This section is empty.

Types

type IDWithMetadatas

type IDWithMetadatas struct {
	ID        []byte
	Metadatas metadata.StagedMetadatas
}

IDWithMetadatas is a pair of metric ID and the associated staged metadatas.

type IDWithMetadatasByIDAsc

type IDWithMetadatasByIDAsc []IDWithMetadatas

IDWithMetadatasByIDAsc sorts a list of ID with metadatas by metric ID in ascending order.

func (IDWithMetadatasByIDAsc) Len

func (a IDWithMetadatasByIDAsc) Len() int

func (IDWithMetadatasByIDAsc) Less

func (a IDWithMetadatasByIDAsc) Less(i, j int) bool

func (IDWithMetadatasByIDAsc) Swap

func (a IDWithMetadatasByIDAsc) Swap(i, j int)

type MatchResult

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

MatchResult represents a match result.

func NewMatchResult

func NewMatchResult(
	version int,
	expireAtNanos int64,
	forExistingID metadata.StagedMetadatas,
	forNewRollupIDs []IDWithMetadatas,
) MatchResult

NewMatchResult creates a new match result.

func (*MatchResult) ExpireAtNanos

func (r *MatchResult) ExpireAtNanos() int64

ExpireAtNanos returns the expiration time of the match result in nanoseconds.

func (*MatchResult) ForExistingIDAt

func (r *MatchResult) ForExistingIDAt(timeNanos int64) metadata.StagedMetadatas

ForExistingIDAt returns the staged metadatas for existing ID at a given time.

func (*MatchResult) ForNewRollupIDsAt

func (r *MatchResult) ForNewRollupIDsAt(idx int, timeNanos int64) IDWithMetadatas

ForNewRollupIDsAt returns the the new rollup ID alongside its staged metadatas for a given index at a given time.

func (*MatchResult) HasExpired

func (r *MatchResult) HasExpired(timeNanos int64) bool

HasExpired returns whether the match result has expired for a given time.

func (*MatchResult) NumNewRollupIDs

func (r *MatchResult) NumNewRollupIDs() int

NumNewRollupIDs returns the number of new rollup metric IDs generated as a result of rule matching.

func (*MatchResult) Version

func (r *MatchResult) Version() int

Version returns the version of the match result.

type Matcher

type Matcher interface {
	// ForwardMatch matches the applicable policies for a metric id between [fromNanos, toNanos).
	ForwardMatch(id []byte, fromNanos, toNanos int64) MatchResult

	// ReverseMatch reverse matches the applicable policies for a metric id between [fromNanos, toNanos),
	// with aware of the metric type and aggregation type for the given id.
	ReverseMatch(
		id []byte,
		fromNanos, toNanos int64,
		mt metric.Type,
		at aggregation.Type,
		isMultiAggregationTypesAllowed bool,
		aggTypesOpts aggregation.TypesOptions,
	) MatchResult
}

Matcher matches metrics against rules to determine applicable policies.

type MockStore

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

MockStore is a mock of Store interface

func NewMockStore

func NewMockStore(ctrl *gomock.Controller) *MockStore

NewMockStore creates a new mock instance

func (*MockStore) Close

func (m *MockStore) Close()

Close mocks base method

func (*MockStore) EXPECT

func (m *MockStore) EXPECT() *MockStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockStore) ReadNamespaces

func (m *MockStore) ReadNamespaces() (*Namespaces, error)

ReadNamespaces mocks base method

func (*MockStore) ReadRuleSet

func (m *MockStore) ReadRuleSet(arg0 string) (RuleSet, error)

ReadRuleSet mocks base method

func (*MockStore) WriteAll

func (m *MockStore) WriteAll(arg0 *Namespaces, arg1 MutableRuleSet) error

WriteAll mocks base method

func (*MockStore) WriteRuleSet

func (m *MockStore) WriteRuleSet(arg0 MutableRuleSet) error

WriteRuleSet mocks base method

type MockStoreMockRecorder

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

MockStoreMockRecorder is the mock recorder for MockStore

func (*MockStoreMockRecorder) Close

func (mr *MockStoreMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close

func (*MockStoreMockRecorder) ReadNamespaces

func (mr *MockStoreMockRecorder) ReadNamespaces() *gomock.Call

ReadNamespaces indicates an expected call of ReadNamespaces

func (*MockStoreMockRecorder) ReadRuleSet

func (mr *MockStoreMockRecorder) ReadRuleSet(arg0 interface{}) *gomock.Call

ReadRuleSet indicates an expected call of ReadRuleSet

func (*MockStoreMockRecorder) WriteAll

func (mr *MockStoreMockRecorder) WriteAll(arg0, arg1 interface{}) *gomock.Call

WriteAll indicates an expected call of WriteAll

func (*MockStoreMockRecorder) WriteRuleSet

func (mr *MockStoreMockRecorder) WriteRuleSet(arg0 interface{}) *gomock.Call

WriteRuleSet indicates an expected call of WriteRuleSet

type MutableRuleSet

type MutableRuleSet interface {
	RuleSet

	// Clone returns a copy of this MutableRuleSet.
	Clone() MutableRuleSet

	// AppendMappingRule creates a new mapping rule and adds it to this ruleset.
	// Should return the id of the newly created rule.
	AddMappingRule(view.MappingRule, UpdateMetadata) (string, error)

	// UpdateMappingRule creates a new mapping rule and adds it to this ruleset.
	UpdateMappingRule(view.MappingRule, UpdateMetadata) error

	// DeleteMappingRule deletes a mapping rule
	DeleteMappingRule(string, UpdateMetadata) error

	// AppendRollupRule creates a new rollup rule and adds it to this ruleset.
	// Should return the id of the newly created rule.
	AddRollupRule(view.RollupRule, UpdateMetadata) (string, error)

	// UpdateRollupRule creates a new rollup rule and adds it to this ruleset.
	UpdateRollupRule(view.RollupRule, UpdateMetadata) error

	// DeleteRollupRule deletes a rollup rule
	DeleteRollupRule(string, UpdateMetadata) error

	// Tombstone tombstones this ruleset and all of its rules.
	Delete(UpdateMetadata) error

	// Revive removes the tombstone from this ruleset. It does not revive any rules.
	Revive(UpdateMetadata) error

	// ApplyRuleSetChanges takes set of rule set changes and applies them to a ruleset.
	ApplyRuleSetChanges(changes.RuleSetChanges, UpdateMetadata) error
}

MutableRuleSet is mutable ruleset.

func NewEmptyRuleSet

func NewEmptyRuleSet(namespaceName string, meta UpdateMetadata) MutableRuleSet

NewEmptyRuleSet returns an empty ruleset to be used with a new namespace.

type Namespace

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

Namespace stores namespace snapshots.

func (Namespace) Name

func (n Namespace) Name() []byte

Name is the name of the namespace.

func (Namespace) NamespaceView

func (n Namespace) NamespaceView(snapshotIdx int) (view.Namespace, error)

NamespaceView returns the view representation of a namespace object.

func (Namespace) Proto

func (n Namespace) Proto() (*rulepb.Namespace, error)

Proto returns the given Namespace in protobuf form

func (Namespace) Snapshots

func (n Namespace) Snapshots() []NamespaceSnapshot

Snapshots return the namespace snapshots.

func (Namespace) Tombstoned

func (n Namespace) Tombstoned() bool

Tombstoned returns the tombstoned state for a given namespace.

type NamespaceSnapshot

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

NamespaceSnapshot defines a namespace snapshot for which rules are defined.

func (NamespaceSnapshot) ForRuleSetVersion

func (s NamespaceSnapshot) ForRuleSetVersion() int

ForRuleSetVersion is the ruleset version this namespace change is related to.

func (NamespaceSnapshot) LastUpdatedAtNanos

func (s NamespaceSnapshot) LastUpdatedAtNanos() int64

LastUpdatedAtNanos returns the time when the namespace is last updated in nanoseconds.

func (NamespaceSnapshot) LastUpdatedBy

func (s NamespaceSnapshot) LastUpdatedBy() string

LastUpdatedBy returns the user who last updated the namespace.

func (NamespaceSnapshot) Proto

Proto returns the given Namespace in protobuf form

func (NamespaceSnapshot) Tombstoned

func (s NamespaceSnapshot) Tombstoned() bool

Tombstoned determines whether the namespace has been tombstoned.

type Namespaces

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

Namespaces store the list of namespaces for which rules are defined.

func NewNamespaces

func NewNamespaces(version int, namespaces *rulepb.Namespaces) (Namespaces, error)

NewNamespaces creates new namespaces.

func (*Namespaces) AddNamespace

func (nss *Namespaces) AddNamespace(nsName string, meta UpdateMetadata) (bool, error)

AddNamespace adds a new namespace to the namespaces structure and persists it. This function returns a boolean indicating whether or not the namespace was revived. The revived flag should be used to decided if the corresponding" ruleset should also be revived.

func (Namespaces) Clone

func (nss Namespaces) Clone() Namespaces

Clone creates a deep copy of this Namespaces object.

func (*Namespaces) DeleteNamespace

func (nss *Namespaces) DeleteNamespace(nsName string, currRuleSetVersion int, meta UpdateMetadata) error

DeleteNamespace tombstones the given namespace mapping it to the next ruleset version.

func (*Namespaces) Namespace

func (nss *Namespaces) Namespace(name string) (*Namespace, error)

Namespace returns a namespace with a given name.

func (Namespaces) Namespaces

func (nss Namespaces) Namespaces() []Namespace

Namespaces returns the list of namespaces.

func (Namespaces) NamespacesView

func (nss Namespaces) NamespacesView() (view.Namespaces, error)

NamespacesView returns a view representation of a given Namespaces object.

func (Namespaces) Proto

func (nss Namespaces) Proto() (*rulepb.Namespaces, error)

Proto returns the given Namespaces slice in protobuf form.

func (Namespaces) Version

func (nss Namespaces) Version() int

Version returns the namespaces version.

type Options

type Options interface {
	// SetTagsFilterOptions sets the tags filter options.
	SetTagsFilterOptions(value filters.TagsFilterOptions) Options

	// TagsFilterOptions returns the tags filter options.
	TagsFilterOptions() filters.TagsFilterOptions

	// SetNewRollupIDFn sets the new rollup id function.
	SetNewRollupIDFn(value id.NewIDFn) Options

	// NewRollupIDFn returns the new rollup id function.
	NewRollupIDFn() id.NewIDFn

	// SetIsRollupIDFn sets the function that determines whether an id is a rollup id.
	SetIsRollupIDFn(value id.MatchIDFn) Options

	// IsRollupIDFn returns the function that determines whether an id is a rollup id.
	IsRollupIDFn() id.MatchIDFn
}

Options provide a set of options for rule matching.

func NewOptions

func NewOptions() Options

NewOptions creates a new set of options.

type RuleSet

type RuleSet interface {
	// Namespace is the metrics namespace the ruleset applies to.
	Namespace() []byte

	// Version returns the ruleset version.
	Version() int

	// CutoverNanos returns when the ruleset takes effect.
	CutoverNanos() int64

	// TombStoned returns whether the ruleset is tombstoned.
	Tombstoned() bool

	// CreatedAtNanos returns the creation time for this ruleset.
	CreatedAtNanos() int64

	// LastUpdatedAtNanos returns the time when this ruleset was last updated.
	LastUpdatedAtNanos() int64

	// Proto returns the rulepb.Ruleset representation of this ruleset.
	Proto() (*rulepb.RuleSet, error)

	// MappingRuleHistory returns a map of mapping rule id to states that rule has been in.
	MappingRules() (view.MappingRules, error)

	// RollupRuleHistory returns a map of rollup rule id to states that rule has been in.
	RollupRules() (view.RollupRules, error)

	// Latest returns the latest snapshot of a ruleset containing the latest snapshots
	// of each rule in the ruleset.
	Latest() (view.RuleSet, error)

	// ActiveSet returns the active ruleset at a given time.
	ActiveSet(timeNanos int64) Matcher

	// ToMutableRuleSet returns a mutable version of this ruleset.
	ToMutableRuleSet() MutableRuleSet
}

RuleSet is a read-only set of rules associated with a namespace.

func NewRuleSetFromProto

func NewRuleSetFromProto(version int, rs *rulepb.RuleSet, opts Options) (RuleSet, error)

NewRuleSetFromProto creates a new RuleSet from a proto object.

type RuleSetUpdateHelper

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

RuleSetUpdateHelper stores the necessary details to create an UpdateMetadata.

func NewRuleSetUpdateHelper

func NewRuleSetUpdateHelper(propagationDelay time.Duration) RuleSetUpdateHelper

NewRuleSetUpdateHelper creates a new RuleSetUpdateHelper struct.

func (RuleSetUpdateHelper) NewUpdateMetadata

func (r RuleSetUpdateHelper) NewUpdateMetadata(updateTime int64, updatedBy string) UpdateMetadata

NewUpdateMetadata creates a properly initialized UpdateMetadata object.

type Store

type Store interface {
	// ReadNamespaces returns the persisted namespaces in kv store.
	ReadNamespaces() (*Namespaces, error)

	// ReadRuleSet returns the persisted ruleset in kv store.
	ReadRuleSet(nsName string) (RuleSet, error)

	// WriteRuleSet saves the given ruleset to the backing store.
	WriteRuleSet(rs MutableRuleSet) error

	// WriteAll saves both the given ruleset and namespace to the backing store.
	WriteAll(nss *Namespaces, rs MutableRuleSet) error

	// Close closes the store.
	Close()
}

Store performs read/write operations for rules and namespaces.

type UpdateMetadata

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

UpdateMetadata contains descriptive information that needs to be updated with any modification of the ruleset.

type Validator

type Validator interface {
	// Validate validates a ruleset.
	Validate(rs RuleSet) error

	// ValidateSnapshot validates a ruleset snapshot.
	ValidateSnapshot(snapshot view.RuleSet) error

	// Close closes the validator.
	Close()
}

Validator validates a ruleset.

Directories

Path Synopsis
store
kv

Jump to

Keyboard shortcuts

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