util

package
v0.0.0-...-11fc026 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OrdinaryIdentifierRegex = regexp.MustCompile(`^[A-Za-z_][A-Za-z_0-9]*(\.[A-Za-z_][A-Za-z_0-9]*)*$`)

Functions

func EscapeIdentifier

func EscapeIdentifier(identifier string) string

Types

type Clock

type Clock interface {
	// Now returns the current local time.
	Now() time.Time
}

Clock provides the functions from the time package. Exists so we can mock out time.Now

type ConversionError

type ConversionError interface {
	Code() ConversionErrorCode
	error
}

ConversionError is the actual error object, wrapping ConversionErrorCode and related metadata.

type ConversionErrorCode

type ConversionErrorCode int

ConversionErrorCode is the error enum raised while the metrics are converted between the graphite format to tagged metrics format.

const (
	// MissingTag is returned during the reverse mapping, when a pattern required in the graphite key is not provided.
	MissingTag ConversionErrorCode = iota + 1
	// CannotInterpolate is returned when the tag interpolation fails.
	CannotInterpolate
	// NoMatch is returned when no rule can reverse the given tagged metric.
	NoMatch
	// UnusedTag is returned during the reverse mapping, when a tag is present in the taglist but is not used
	UnusedTag
)

type GraphiteConverter

type GraphiteConverter interface {
	// Convert the given tag-based metric name to graphite metric name,
	// using the configured rules. May error out.
	ToGraphiteName(metric api.TaggedMetric) (GraphiteMetric, error)
	// Converts the given graphite metric to the tag-based meric,
	// using the configured rules. May error out.
	ToTaggedName(metric GraphiteMetric) (api.TaggedMetric, error)
}

type GraphiteConverterConfig

type GraphiteConverterConfig struct {
	ConversionRulesPath string `yaml:"conversion_rules_path"`
}

type GraphiteMetric

type GraphiteMetric string

GraphiteMetric is a flat, dot-separated identifier to a series of metric.

type RawRule

type RawRule struct {
	Pattern          string            `yaml:"pattern"`
	MetricKeyPattern string            `yaml:"metric_key"`
	Regex            map[string]string `yaml:"regex,omitempty"`
	DoNotMatch       map[string]string `yaml:"do_not_match,omitempty"`
}

RawRule is the input provided by the YAML file to specify the rul.

type RawRules

type RawRules struct {
	RawRules []RawRule `yaml:"rules"`
}

RawRules is list of RawRule

type RealClock

type RealClock struct{}

RealClock is a wrapper over the time package

func (RealClock) Now

func (r RealClock) Now() time.Time

Now returns the current time.Time

type Rule

type Rule struct {
	MetricKeyRegex *regexp.Regexp

	Statistics RuleStatistics
	// contains filtered or unexported fields
}

Rule is a sanitized version of RawRule. Only valid rules can be converted to Rule.

func Compile

func Compile(rule RawRule) (Rule, error)

Compile a given RawRule into a regex and exposed tagset. error is an instance of RuleError.

func (*Rule) AddMatch

func (rule *Rule) AddMatch(matchedResult string)

func (Rule) Description

func (rule Rule) Description() string

func (*Rule) DisableStats

func (rule *Rule) DisableStats()

func (*Rule) EnableStats

func (rule *Rule) EnableStats()

func (Rule) GraphitePatternTags

func (rule Rule) GraphitePatternTags() []string

GraphitePatternTags return a list of tags available in the original metric.

func (*Rule) MatchRule

func (rule *Rule) MatchRule(input string) (api.TaggedMetric, bool)

MatchRule sees if a given graphite string matches the rule, and if so, returns the generated tag.

func (Rule) ToGraphiteName

func (rule Rule) ToGraphiteName(taggedMetric api.TaggedMetric) (GraphiteMetric, error)

ToGraphiteName transforms the given tagged metric back to its graphite metric.

type RuleBasedGraphiteConverter

type RuleBasedGraphiteConverter struct {
	Ruleset RuleSet
}

func (*RuleBasedGraphiteConverter) EnableStats

func (g *RuleBasedGraphiteConverter) EnableStats()

func (*RuleBasedGraphiteConverter) ToGraphiteName

func (g *RuleBasedGraphiteConverter) ToGraphiteName(metric api.TaggedMetric) (GraphiteMetric, error)

func (*RuleBasedGraphiteConverter) ToTaggedName

func (g *RuleBasedGraphiteConverter) ToTaggedName(metric GraphiteMetric) (api.TaggedMetric, error)

type RuleError

type RuleError interface {
	// Error code describing the error.
	Code() RuleErrorCode
	// Rule Metric Key, if applicable
	MetricKey() string
	error
}

RuleError is the actual error object, wrapping RuleErrorCode and related metadata.

type RuleErrorCode

type RuleErrorCode int

RuleErrorCode is the error enum raised while YAML rule files is being compiled.

const (
	// InvalidYaml is returned when the given YAML file fails to parse
	InvalidYaml RuleErrorCode = iota + 1
	// InvalidPattern is returned when an invalid rule pattern is provided.
	InvalidPattern
	// InvalidMetricKey is retruned when an invalid metric key is provided.
	InvalidMetricKey
	// InvalidCustomRegex is retruned when the custom regex is invalid.
	InvalidCustomRegex
)

type RuleSet

type RuleSet struct {
	Rules []Rule
	// contains filtered or unexported fields
}

RuleSet is a sanitized version of RawRules. Rules are matched sequentially until a correct one is matched.

func LoadRules

func LoadRules(conversionRulesPath string) (RuleSet, error)

func LoadYAML

func LoadYAML(input []byte) (RuleSet, error)

LoadYAML loads a RuleSet from the byte array of the YAML file. error is an interface of RuleError.

func (*RuleSet) DisableStats

func (ruleSet *RuleSet) DisableStats()

func (*RuleSet) EnableStats

func (ruleSet *RuleSet) EnableStats()

func (*RuleSet) MatchRule

func (ruleSet *RuleSet) MatchRule(input string) (api.TaggedMetric, bool)

MatchRule sees if a given graphite string matches any of the specified rules.

func (RuleSet) ToGraphiteName

func (ruleSet RuleSet) ToGraphiteName(taggedMetric api.TaggedMetric) (GraphiteMetric, error)

ToGraphiteName transforms the given tagged metric back to its graphite name, checking against all the rules.

type RuleStatistics

type RuleStatistics struct {
	Matches           int
	SuccessfulMatches []string
	// contains filtered or unexported fields
}

func (*RuleStatistics) AddMatch

func (ruleStat *RuleStatistics) AddMatch(matchedResult string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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