metric

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 7 Imported by: 2

Documentation

Overview

Package metric provides an interface for describing a schema of metric's parameters.

Package metric provides an interface for describing a schema of metric's parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LenValidator

type LenValidator struct {
	Min *int
	Max *int
}

func (LenValidator) Validate

func (v LenValidator) Validate(value *string) error

type Metric

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

Metric stores a description of a metric and its parameters.

func New

func New(description string, params []*Param, varParam bool) *Metric

New creates an instance of a Metric and returns a pointer to it. It panics if a metric is not satisfied to one of the following rules: 1. Parameters must be named (and names must be unique). 2. It's forbidden to duplicate parameters' names. 3. Session must be placed first. 4. Connection parameters must be placed in a row.

func (*Metric) EvalParams

func (m *Metric) EvalParams(rawParams []string, sessions interface{}) (params map[string]string, extraParams []string,
	err error)

EvalParams returns a mapping of parameters' names to their values passed to a plugin and/or sessions specified in the configuration file and extra remaining parameters. If a session is configured, then an other connection parameters must not be accepted and an error will be returned. Also it returns error in following cases: * incorrect number of parameters are passed; * missing required parameter; * value validation is failed.

type MetricSet

type MetricSet map[string]*Metric

MetricSet stores a mapping of keys to metrics.

func (MetricSet) List

func (ml MetricSet) List() (list []string)

List returns an array of metrics' keys and their descriptions suitable to pass to plugin.RegisterMetrics.

type NumberValidator

type NumberValidator struct{}

func (NumberValidator) Validate

func (v NumberValidator) Validate(value *string) error

type Param

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

Param stores parameters' metadata.

func NewConnParam

func NewConnParam(name, description string) *Param

NewConnParam creates a new connection parameter with given name and validator. Returns a pointer.

func NewParam

func NewParam(name, description string) *Param

NewParam creates a new parameter with given name and validator. Returns a pointer.

func NewSessionOnlyParam

func NewSessionOnlyParam(name, description string) *Param

NewSessionParam creates a new connection parameter with given name and validator. Returns a pointer.

func (*Param) SetRequired

func (p *Param) SetRequired() *Param

SetRequired makes the parameter mandatory. It panics if default value is specified for required parameter.

func (*Param) WithDefault

func (p *Param) WithDefault(value string) *Param

WithDefault sets the default value for a parameter. It panics if a default value is specified for a required parameter.

func (*Param) WithSession

func (p *Param) WithSession() *Param

WithSession transforms a connection typed parameter to a dual purpose parameter which can be either a connection parameter or session name. Returns a pointer.

func (*Param) WithValidator

func (p *Param) WithValidator(validator Validator) *Param

WithValidator sets a validator for a parameter

type PatternValidator

type PatternValidator struct {
	Pattern string
}

func (PatternValidator) Validate

func (v PatternValidator) Validate(value *string) error

type RangeValidator

type RangeValidator struct {
	Min int
	Max int
}

func (RangeValidator) Validate

func (v RangeValidator) Validate(value *string) error

type SetValidator

type SetValidator struct {
	Set             []string
	CaseInsensitive bool
}

func (SetValidator) Validate

func (v SetValidator) Validate(value *string) error

type Validator

type Validator interface {
	Validate(value *string) error
}

Jump to

Keyboard shortcuts

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