transform

package
v0.0.0-...-85a7ce0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package transform turns decoded data into metrics with a collector's metric rules — jq, yq, XPath, CSS, CSV, regex and Prometheus pass-through — or with a Python script, run in a pool of worker processes. It also checks rules, scripts and names when the configuration loads.

Index

Constants

View Source
const (
	NameEscapingFail        = "fail"
	NameEscapingUnderscores = "underscores"
	NameEscapingValues      = "values"
	NameEscapingDots        = "dots"
	NameEscapingAllowUTF8   = "allow-utf-8"
)

The values of name_escaping. NameEscapingDots and NameEscapingAllowUTF8 are no values of it: they are, with underscores and values, the escaping schemes a scraper can ask an answer for (EscapeName), the first rewriting every name with an underscore in it and the second none.

View Source
const (

	// PythonDefaultMaxIdleWorkers is the default of --python.max-idle-workers.
	PythonDefaultMaxIdleWorkers = 1
	// PythonDefaultIdleTimeout is the default of --python.idle-timeout.
	PythonDefaultIdleTimeout = 2 * time.Minute
)
View Source
const MaxLintLabelValues = 100

MaxLintLabelValues is how many distinct values one label of one metric may have in one run before unbounded-label calls it unbounded. A label with a value per host, pod or status code stays well under it; one with a value per request, user or session does not.

View Source
const MinPythonOutputBytes = max(len(pythonReadyLine), len(pythonRequestTaken), len(pythonEmptyMetricsAnswer), len(pythonNoDataAnswer))

MinPythonOutputBytes is the least a limits.max_output_bytes that is set may be, 38 bytes: the longest of the lines every worker has to get through it, without the line break, which is not counted (readAnswers). Under 27 bytes the worker's line that it is ready does not fit, so no worker starts and every scrape fails as a start that failed; from 27 a worker starts and says of each request that it has it (17 bytes), and its errors are cut to fit (failed), but an answer is not: the shortest a pre-script gets is 34 bytes, with a number of one digit left in data, 35 with {}, [] or "" and 37 with None, and the shortest a transform's script gets is the 38 of no metric at all. Those are of a script that prints nothing: what it prints is in the answer's log. So a smaller limit is one under which a transform's script could do nothing but fail and a pre-script could leave in data nothing that is written longer than None is, and the configuration is refused with it when it loads (config.Validate), by the schema too where the size is written as a number.

The loader holds this floor, not the worker and not the pool: a worker runs under whatever limit it is given, cutting an error to it, which the tests of that rely on. A test holds the constant to what the launcher writes, so it cannot stay behind when an answer gains or loses a key.

Variables

View Source
var (
	PythonStopReasons = []string{pythonStopTimeout, pythonStopDeadline, pythonStopCrash, pythonStopOutputLimit, pythonStopCancelled, pythonStopRetired, pythonStopSurplus, pythonStopIdle, pythonStopReload, pythonStopEvicted}
	PythonRunOutcomes = []string{pythonRunOK, pythonRunScriptError, pythonRunTimeout, pythonRunDeadline, pythonRunOutputLimit, pythonRunFailed}
)

PythonStopReasons and PythonRunOutcomes are every reason a worker stops and every way a run ends, so each has a series from the start.

View Source
var MetricsPrefixRE = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9]*(?:_[a-zA-Z0-9]+)*$`)

MetricsPrefixRE matches a valid metrics_prefix.

A collector's metrics_prefix namespaces everything it exports: with metrics_prefix: grafana, a metric declared as statuspage_status is exported as grafana_statuspage_status. It applies to every transform, including the names a Python script emits and the names a prometheus transform passes through, and to /probe and OTLP alike. It does not apply to the exporter's own http_exporter_* metrics, which describe the exporter, not the target.

The prefix is a name fragment, not a raw string: it must start with a letter and consist of letters and digits in segments joined by single underscores, and the exporter adds the "_" that joins it to the name. That rules out

  • a leading underscore, since names starting with "__" are reserved by Prometheus and a single one reads as a private metric;
  • a trailing underscore, which with the joining "_" would give a double one;
  • "__" anywhere, for the same reason;
  • ":", which Prometheus reserves for recording rules; and
  • a leading digit, which no metric name may have.
View Source
var PythonLibraries = map[string]bool{"lxml": true, "PyYAML": true, "yaml": true, "python-dateutil": true, "dateutil": true}

PythonLibraries are the third-party libraries the image installs, under the names a collector may declare them by: the package name or the import name.

Functions

func CheckDecoder

func CheckDecoder(x *model.Collector) error

CheckDecoder refuses, when a configuration loads, a decoder.type the collector's transform can never read: every scrape would fail whatever the target answered. A decoder left to each response (auto) is checked on the scrape instead. A jq or yq transform with a pre_script is let be: its rules read the mapping or list the script leaves, whatever was decoded (applyPreScript); for every other transform the script's result is read as the decoder's own kind of document.

func CheckDerived

func CheckDerived(x *model.Collector) error

CheckDerived refuses a derived list that could not be computed, or whose series every scrape would refuse, and gives an entry without a type the type gauge. It is checked once the rules are, their types filled in.

An operand is a rule's name or an earlier entry's. The series of a python script and of a prometheus pass-through are named by the target and the script, at run time, so an operand of such a collector that no rule names is taken, and read from the series of that name each scrape makes; one a rule names is checked as any other's. Only a counter, a gauge or an untyped family can be an operand: a histogram or a summary has no one value to add. Such a family that only a scrape shows is read as no series, and is reported as a failure of the entry, under error_mode log (deriveSeries).

func CheckExportedLabelName

func CheckExportedLabelName(x *model.Collector, name string) error

CheckExportedLabelName refuses a label name the collector takes (TakesLabelName) that is exported as one Prometheus reserves, beginning with "__": a classic name written so, in the words it always was, and a name underscores escapes to one, which the scrape would refuse of every series that has the label. It refuses as well a name exported longer than the collector's limits.max_label_name_length, which the scrape would refuse of every such series too: the name as escaped, which is what the scrape measures.

func CheckLabelNameBeforeRenames

func CheckLabelNameBeforeRenames(x *model.Collector, name string) error

CheckLabelNameBeforeRenames is CheckExportedLabelName of a label name a series has before remove_labels and rename_labels, which refuses nothing of a name either takes off.

func CheckLabelValueMapsAgree

func CheckLabelValueMapsAgree(x *model.Collector) error

CheckLabelValueMapsAgree refuses two rules of one name that map one label differently: a label's value_map is found by its rule's name, so the series of both would take the first rule's map without a word.

func CheckMetricRule

func CheckMetricRule(x *model.Collector, r *model.MetricRule) error

CheckMetricRule validates one rule's name and compiles its expressions. It reports every mistake it finds in the rule, not just the first (model.JoinProblems), each naming the rule and, where there is one, the expression. The rule is named by its metric name, whatever that is: the loader, which knows the rule's place among its collector's, checks it with CheckMetricRuleAt.

func CheckMetricRuleAt

func CheckMetricRuleAt(x *model.Collector, index int) error

CheckMetricRuleAt is CheckMetricRule of the rule at index of the collector's metrics, named in each message as RuleWhere names it: a rule that has a name reads as it does from CheckMetricRule, and one that has none is told of by its place.

func CheckTransformSettings

func CheckTransformSettings(x *model.Collector) error

CheckTransformSettings checks the collector-wide transform settings. include, exclude and rename pick and rename the metrics a prometheus transform passes through, so they apply only to one without metrics rules, where the rules would do both; anywhere else they are refused rather than ignored. The label settings apply to every transform: their label names are checked, and two renames to one label are refused, since which value it would get has no right answer.

func CollectorScripts

func CollectorScripts(c *model.Config) []pythonScript

CollectorScripts lists every Python source in the configuration. Only pre-scripts are required to produce `data`: a Python transform emits through metric(...) instead, so it is checked for syntax only.

func DerivedWhere

func DerivedWhere(x *model.Collector, index int) string

DerivedWhere is how a message names the derived entry at index of a collector's derived list: by its name, or by its place, counted from 1, when it has none.

func DescribeDerived

func DescribeDerived(d *model.DerivedRule) string

DescribeDerived says what a derived entry computes, as a debug probe's report shows it: "ratio of a, b", "sum of a by (queue)".

func EscapeName

func EscapeName(name, scheme string, metric bool) string

EscapeName escapes a metric name (metric true) or a label name that is not classic as a scraper's escaping asks: underscores, dots or values, as Prometheus's own model escapes them; a classic name, and any name under allow-utf-8, is returned as it is. dots writes _dot_ for a dot, __ for an underscore and for any other character a classic name may not have.

func EscapingAdvice

func EscapingAdvice(name string) string

EscapingAdvice is what the load adds to its refusal of a name that is not classic, in the words the scrape's refusal of such a name has (model.MetricSet.Validate), and for the names it has them for: one that is valid UTF-8, which escaping exports. A name of blanks is refused under every name_escaping, and is told nothing of it.

func ExportedMetricName

func ExportedMetricName(c *model.Collector, name string) string

ExportedMetricName is the name the series a rule of the collector names name are exported under: the collector's metrics_prefix joined to it, and the whole escaped as the collector's name_escaping escapes a name that is not classic, as Transform does with every series, in that order.

func IsolatePythonWorkers

func IsolatePythonWorkers() (restore func())

IsolatePythonWorkers puts a fresh worker pool in place of the current one and returns what puts the previous pool back, stopping the fresh pool's workers. It is for tests, which read the pool's counts, and must not run in parallel with anything else using the pool.

func LeaveRuleLoggingToCaller

func LeaveRuleLoggingToCaller(ctx context.Context) context.Context

LeaveRuleLoggingToCaller returns a context whose Transforms log none of their rules' failures: the caller logs those that carried on from its RuleReport, where it knows the target and can tell a repeat from a new failure, and a rule under fail fails the Transform with an error that names it, which the caller logs as the scrape's failure.

func MappedStaticLabelValue

func MappedStaticLabelValue(x *model.Collector, metric string, label model.LabelRule) string

MappedStaticLabelValue is the value the static label of metric rules has on its series once mapLabelValues has run: mapped by the first value_map any rule of that name gives the label, which CheckLabelValueMapsAgree requires to agree with the others, or left as it is.

func PythonWorkerKeys

func PythonWorkerKeys(pythonPath string, c *model.Config) map[string]bool

PythonWorkerKeys are the worker keys a configuration uses.

func ReadableDecoders

func ReadableDecoders(transformType string) []string

ReadableDecoders is the decoders whose documents a transform of the given type reads, and nil for one that reads them all, as python does.

func ReadsTimings

func ReadsTimings(c *model.Collector) bool

ReadsTimings says whether a rule or a script of c may read what only the trace of its request sees: the timings, $timings or Python's response.timings, and the address the connection was made to, $remote_ip or response.remote_ip. A request is traced only when something reads them (model.Collector.TimingsUnread).

A Python script may reach response.timings by a name it makes, so a collector with one always reads them. A jq or yq program can name a variable only as it is written, so one that reads $timings or $remote_ip holds that text: every text of the collector is looked through for them, whichever key holds it, so a key that comes to hold a program is never missed. A text that holds one and is no program, or that names another variable of that name of its own, only costs the trace it did not need.

func ReportedRules

func ReportedRules(c *model.Collector) []model.MetricRule

ReportedRules are the rules of c whose failures a scrape may report: its metric rules, and a rule for each derived entry (derivedRule), so that an entry that failed is counted, logged and seen to recover as a rule is.

func RuleName

func RuleName(r *model.MetricRule, index int) string

RuleName is RuleWhere without the collector: `metric "up"`, or `metrics rule 2` for the rule at index that has no name.

func RuleWhere

func RuleWhere(x *model.Collector, index int) string

RuleWhere is how a message of the load names the rule at index of a collector's metrics: the collector and the rule's metric name, `collector "node" metric "up"`, or, for a rule that has no name to be named by, the collector and the rule's place among its rules, counted from 1 as CheckLabelValueMapsAgree counts them, `collector "node" metrics rule 2`. A rule has no name when name is left out or "", which a prometheus rule may be, or is nothing but blanks, which is no rule's name: `metric ""` said which rule of thirty it was to nobody. A name that is no metric's for another reason is quoted as it is written, and finds its rule.

func TakesLabelName

func TakesLabelName(x *model.Collector, name string) bool

TakesLabelName reports whether a label name written in the collector's configuration is one a scrape of the collector exports: a classic name, or, under name_escaping underscores or values, any that is not blanks alone. A name it takes may still be one Prometheus reserves (CheckExportedLabelName).

func TakesLabelNameBeforeRenames

func TakesLabelNameBeforeRenames(x *model.Collector, name string) bool

TakesLabelNameBeforeRenames is TakesLabelName of a label name a series has before remove_labels and rename_labels: one either takes off is taken whatever its characters, unless it is blanks alone.

func Transform

func Transform(ctx context.Context, d *decode.Decoded, r *fetch.HTTPResponse, c *model.Collector, pythonPath string) (*model.MetricSet, error)

Transform turns a decoded response into the collector's metrics, named as they are exported: every transform's output passes through here, so the collector's metrics_prefix is applied in exactly one place, before the limits are checked, the set is cached, or it is written to /probe or OTLP.

A collector whose label values hold {{param_...}} placeholders is read with them filled in from the probe's parameters (labelparams.go).

func UTF8Names

func UTF8Names(c *model.Collector) bool

UTF8Names reports whether the collector's metric_name_validation_scheme is utf8: its names may be any UTF-8, kept as they are until an answer is written.

func ValidateIdleTimeout

func ValidateIdleTimeout(timeout time.Duration) error

ValidateIdleTimeout refuses a --python.idle-timeout under a second.

func ValidateMaxIdleWorkers

func ValidateMaxIdleWorkers(limit int) error

ValidateMaxIdleWorkers refuses a negative --python.max-idle-workers.

func ValidateMaxWorkers

func ValidateMaxWorkers(limit int) error

ValidateMaxWorkers refuses a negative --python.max-workers.

func ValidateMetricsPrefix

func ValidateMetricsPrefix(c *model.Collector) error

ValidateMetricsPrefix checks a collector's prefix and, when one is set, that every metric name the configuration declares still fits limits.max_metric_name_length once prefixed, and escaped where the collector's name_escaping escapes it. Names produced at scrape time — by a Python script or passed through by a prometheus transform — are checked against the same limit when the scrape happens.

func ValidateNameEscaping

func ValidateNameEscaping(c *model.Collector) error

ValidateNameEscaping checks a collector's name_escaping and metric_name_validation_scheme, and fills in their defaults, fail and legacy.

func ValidatePythonScripts

func ValidatePythonScripts(pythonPath string, c *model.Config) error

ValidatePythonScripts rejects a configuration whose Python sources cannot work. It is a no-op for a configuration containing none, so a deployment that uses no Python needs no interpreter present.

func WithLabelParams

func WithLabelParams(ctx context.Context, params map[string]string) context.Context

WithLabelParams returns a context carrying the param_<name> parameters of a probe, or of a static target, for the Transform of a collector whose label values hold placeholders. A caller need not make one for a collector whose LabelParams is nil, which reads no parameter.

func WithRuleLogger

func WithRuleLogger(ctx context.Context, logger *slog.Logger) context.Context

WithRuleLogger returns a context whose Transforms log their rules' failures to logger rather than slog's default logger, as a debug probe's report takes them.

func WithScrapeClock

func WithScrapeClock(ctx context.Context, now, since time.Time) context.Context

WithScrapeClock returns a context whose Transform reads now as the time its scrape began and since as the time the last successful scrape of the same collector, target and parameters began, zero for none: $scrape_time and $last_success in a jq or yq expression, scrape_time and last_success in a Python script, each in seconds since the epoch.

Types

type LintFinding

type LintFinding struct {
	Collector string `json:"collector"`
	Rule      string `json:"rule"`
	Metric    string `json:"metric"`
	Message   string `json:"message"`
}

LintFinding is one piece of advice: the collector it is about, the rule that gave it, the metric and what is wrong with it and what to do instead.

func LintCollector

func LintCollector(c *model.Collector, conf *model.Config) []LintFinding

LintCollector is the advice the configuration gives about c: the name rules on the names its rules and its derived entries make, and the names a collector of conf other than c, or one of c's name, makes in another way. c need not be one of conf's: a collector written on the debug page is compared with those in force.

func LintConfiguration

func LintConfiguration(conf *model.Config) []LintFinding

LintConfiguration is the advice the configuration alone gives, for every collector in its order: the name rules on the names its rules and its derived entries make, and the names another collector makes in another way. The series a run makes are not known here, so unbounded-label gives none.

func LintRun

func LintRun(c *model.Collector, conf *model.Config, set *model.MetricSet) []LintFinding

LintRun is the advice of a debug run of c: LintCollector's, the name rules on the metrics the run made, which include those of a python script or of a prometheus transform's pass-through, and unbounded-label on their labels. A finding of a name both give is shown once.

func (LintFinding) String

func (f LintFinding) String() string

String is the finding on one line, as a log or a report shows it.

type MetricFailure

type MetricFailure struct {
	Collector string
	Metric    string
	Err       error
}

MetricFailure is a metric rule that could not produce its value and whose error mode does not allow the scrape to carry on without it. It is its own type so the probe handler can tell it apart from a failure of the transform as a whole: the rule asked for the scrape to fail, and that request is not something a collector-wide on_transform_error policy gets to overrule.

func (*MetricFailure) Error

func (f *MetricFailure) Error() string

func (*MetricFailure) Unwrap

func (f *MetricFailure) Unwrap() error

type PythonPool

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

PythonPool keeps the Python workers that run collector scripts, idle ones ready for the next run of the same script, and counts what they do for the self-metrics.

func PythonWorkers

func PythonWorkers() *PythonPool

PythonWorkers returns the worker pool.

func (*PythonPool) Departed

func (p *PythonPool) Departed() *PythonStats

Departed returns the statistics of a run whose collector a reload removed before the run took any: retired from the start, so what the run counts is shown under no collector, leaves nothing under the collector's name, and is counted for the pool as a whole.

func (*PythonPool) Kept

func (p *PythonPool) Kept(collector string) *PythonStats

Kept returns the statistics kept under a collector's name, and nil when there are none: for a reader, which makes none by asking. Like Stats, it is for whoever knows that the collector of that name is the one it means (exporter/pythonstats.go).

func (*PythonPool) PoolSnapshot

func (p *PythonPool) PoolSnapshot() pythonWorkerSnapshot

PoolSnapshot sums the statistics of every collector the pool has served, including collectors a reload has since removed, whose counts the pool keeps together (departed), so its counters never go backwards.

func (*PythonPool) ReapInterval

func (p *PythonPool) ReapInterval() time.Duration

ReapInterval is how often ReapLoop should check the idle workers: every minute, or every half the idle timeout when that is shorter, so a worker is stopped at most half its timeout late, rather than a minute late for a timeout of a few seconds.

func (*PythonPool) ReapLoop

func (p *PythonPool) ReapLoop(ctx context.Context, interval time.Duration)

ReapLoop stops idle workers on a timer until ctx ends, so they are stopped even when nothing asks for a worker any more.

func (*PythonPool) Retain

func (p *PythonPool) Retain(keys map[string]bool)

Retain makes keys the scripts in use: idle workers of any other are stopped at once, and busy ones when they finish.

func (*PythonPool) Retire

func (p *PythonPool) Retire(collectors map[string]bool)

Retire drops the statistics kept under the names of collectors a reload removed: they are shown no more, a collector added again under one of the names starts from zero, and nothing is kept for a name that does not come back. What they had counted stays counted for the pool as a whole, and so is what the runs and workers that still hold them count from now on, a run that waits for a worker, runs its script or ends, and a worker that is stopped when its run ends: under no collector's name.

No worker outlives its statistics idle. The ones that are idle now are stopped here, for the reload that removed their collector (pythonStopReload), where the reload has not stopped them already (Retain, which the configuration manager calls before the exporter retires anything): a run of the removed collector may have left one since. A busy one is stopped when its run ends (release).

func (*PythonPool) SetIdleTimeout

func (p *PythonPool) SetIdleTimeout(timeout time.Duration)

SetIdleTimeout is how long an idle worker is kept unused before it is stopped.

func (*PythonPool) SetLeastScriptTimeout

func (p *PythonPool) SetLeastScriptTimeout(least time.Duration)

SetLeastScriptTimeout gives every script the pool runs at least this long, whatever its limits.script_timeout, and 0 holds each to its own again. It is for tests. A script of a millisecond overruns the default 100ms on a machine busy enough, as a test runner is under the race detector with other packages' tests beside it; a test that is not about the timeout then fails by it. Such a test runs against a pool that leaves its scripts a minute, which a slow machine makes slower and never fails, and a test of the timeout itself sets 0.

func (*PythonPool) SetMaxIdleWorkers

func (p *PythonPool) SetMaxIdleWorkers(limit int)

SetMaxIdleWorkers is how many workers of each script are kept idle once their runs end; 0 keeps none, so each worker stops when its run ends. It bounds the workers that go idle after it is set, and is set before the exporter runs any script.

func (*PythonPool) SetMaxWorkers

func (p *PythonPool) SetMaxWorkers(limit int)

SetMaxWorkers bounds the workers alive at once, of every collector together; 0 leaves them unbounded.

func (*PythonPool) SetStartTimeout

func (p *PythonPool) SetStartTimeout(limit time.Duration)

SetStartTimeout is how long an interpreter the pool starts may take to say it is ready, which is ten seconds in the exporter. It is for tests. An interpreter that starts in a tenth of a second has taken more than the ten on a machine busy enough, and a test that is not about the start then fails by it; such a test runs against a pool that leaves the start a minute, as it leaves a script (SetLeastScriptTimeout). A test of the limit itself sets a short one, and starts something that never says it is ready.

func (*PythonPool) Snapshot

func (p *PythonPool) Snapshot(collector string) pythonWorkerSnapshot

Snapshot copies the statistics kept under a collector's name and counts the idle workers that count in them. A name nothing is kept under has counted nothing, and asking makes nothing kept under it: a reader may name a collector a reload has just removed.

func (*PythonPool) SnapshotOf

func (p *PythonPool) SnapshotOf(st *PythonStats) pythonWorkerSnapshot

SnapshotOf is Snapshot for the statistics a reader holds (Kept): what they count is read from them, whatever is kept under the collector's name by now, so a reader shows the counts of the collector it means. Retired since the reader took them, they are what they were then; nil, or of another pool, they have counted nothing.

func (*PythonPool) Stats

func (p *PythonPool) Stats(collector string) *PythonStats

Stats returns the statistics kept under a collector's name, making them when there are none. It is for whoever knows that the collector of that name is the one a run is of, which a name alone does not say once a reload may have removed the collector and another brought one back: the exporter asks while it holds what a reload retires a collector's statistics under, for a trip whose collector has been there since the trip read it (exporter/pythonstats.go), and hands them to the trip's runs (WithScriptTimer). A run that is handed none asks by its collector's name when it begins, as every run did.

func (*PythonPool) StatsKept

func (p *PythonPool) StatsKept() int

StatsKept is how many collectors the pool keeps statistics for. It is for tests, which hold it to the collectors there are: the names a reload removed must not add up.

type PythonScriptProblem

type PythonScriptProblem struct {
	Collector string `json:"collector"`
	Message   string `json:"message"`
}

PythonScriptProblem is one fault the check found in a collector's Python: the message, which names the collector, and the collector's name on its own, for a caller that has to say where the collector is defined.

func CheckPythonScripts

func CheckPythonScripts(pythonPath string, c *model.Config) ([]PythonScriptProblem, error)

CheckPythonScripts is ValidatePythonScripts with the faults kept apart: err is the interpreter itself failing, and problems are the individual script faults, in the order of the collectors, each naming its collector in its message and beside it. --dry-run reports the latter one by one. The interpreter is run once, whatever it finds.

type PythonStats

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

PythonStats is one collector's worker statistics, as a run counts in them: a run takes them once, when its trip begins, and counts in those and no others however the run ends, and a worker counts in those of the run that started it, for as long as it lives: it serves the runs that count in them and no others (acquire). So a run or a worker that outlives its collector, which a reload removed, is counted nowhere a collector shows, and not for a collector added again under the name, which has statistics of its own, and workers of its own: every worker a collector's series show is one they counted the start of, and will count the stop of.

type RuleFailure

type RuleFailure struct {
	// Metric is the rule's name, empty for a prometheus rule without one.
	Metric string
	// Expression and Items are the rule's, which with Metric tell it from
	// the collector's other rules.
	Expression, Items string
	Failures, Missing uint64
	// First is the first of the failures, as a debug probe shows it.
	First error
	// Logged says the rule has error_mode log, or a rule alike in all three
	// has, so its failures are to be logged, First being the first of them.
	Logged bool
}

RuleFailure is how many series of one rule failed, and how many of those because the response did not contain the value.

A collector may have several rules of one metric name, one for each column or path its series come from, and each fails for reasons of its own: so a rule is told apart as the transform tells it apart while it gathers the failures (ruleFailures), by its name, its expression and its items, and each has an entry of its own. Two rules alike in all three are one rule.

type RuleReport

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

RuleReport counts, for its caller, the series metric rules could not produce and carried on without, under error_mode log or ignore, across the Transforms made with its context (WithRuleReport). A rule that fails the scrape is not in it: that failure is the Transform's error.

func WithRuleReport

func WithRuleReport(ctx context.Context) (context.Context, *RuleReport)

WithRuleReport returns a context whose Transforms report their rules' failures in the returned RuleReport.

func (*RuleReport) DerivedAbsent

func (r *RuleReport) DerivedAbsent() map[string][]string

DerivedAbsent returns the operands of each derived entry, by the entry's name as it is written, that had no series in the scrapes the Transforms made, in the order the entry reads them, an entry read counting those of its own. Such an entry gives no series, and does not fail for it.

func (*RuleReport) Failures

func (r *RuleReport) Failures() []RuleFailure

Failures returns the failures reported, one entry per rule, in the order the rules first failed.

func (*RuleReport) UTF8Repairs

func (r *RuleReport) UTF8Repairs() (uint64, string)

UTF8Repairs returns how many label values and help texts the Transforms repaired for invalid UTF-8, and the first metric repaired.

type ScriptTimer

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

ScriptTimer adds up how long a probe's Python ran.

A probe reports how long its Python ran in http_exporter_script_duration_seconds. The scripts run deep inside the transform, so the probe hands them a timer through the context, and they add the time each script ran, as limits.script_timeout measures it: the pre-script and the python transform together, without starting an interpreter or handing it the response.

The timer also carries, the same way and for the same scripts, the worker statistics the probe's runs count in (PythonStats), which the probe took for the collector it read: a run finds them with the timer, and asks for none by its collector's name, which a reload may have given to another collector since.

func WithScriptTimer

func WithScriptTimer(ctx context.Context, stats *PythonStats) (context.Context, *ScriptTimer)

WithScriptTimer returns a context carrying a fresh timer, and with it stats, the worker statistics the runs under the context count in; nil for runs that count in those kept under their collector's name.

func (*ScriptTimer) Seconds

func (t *ScriptTimer) Seconds() (float64, bool)

Seconds reports the time the scripts took, and whether any ran.

Jump to

Keyboard shortcuts

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