value

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: Unlicense Imports: 9 Imported by: 0

Documentation

Overview

The `value` package contains the types for holding individual metric values (either just a float64 or the numeric state for a histogram). These values have no information about labels. (The label names are held in a LabelSet and the list of values for an individual metric are encoded as a RuneList which is only used as the key to a map[label.RuneList]value.Metric.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Populate

func Populate(
	metricMap map[label.RuneList]Metric,
	metricKind mon.MetricKind,
	valueType mon.ValueType,
	scaler func(float64) float64,
	ls *label.Set,
	subBuckets []int,
	ts *sd.TimeSeries,
	pt *sd.Point,
)

Populate() takes a GCP metric value (*TimeSeries) and computes a label.RuneList from the label values (both metric and resource labels) and converts the numeric data to a value.Metric and then stores that in the metricMap using the RuneList as the key.

func StampEpoch

func StampEpoch(stamp string) int64

Converts a timestamp string into Unix epoch seconds.

Types

type Histogram

type Histogram struct {
	Simple
	SampleCount uint64
	BucketHits  []uint64
}

A value.Histogram holds the current state of a histogram metric. It implmenets the value.Metric interface. It is read-only (but can be converted into a value.RwHistogram).

func (*Histogram) AsReadOnly

func (hv *Histogram) AsReadOnly() Metric

func (*Histogram) Copy

func (hv *Histogram) Copy(samplePeriod time.Duration) Metric

func (*Histogram) Export

func (hv *Histogram) Export(
	metricKind mon.MetricKind,
	valueType mon.ValueType,
	ls *label.Set,
	rl label.RuneList,
	bounds []float64,
) dto.Metric

Histogram's Export() returns a Protobuf version of a histogram metric.

func (*Histogram) IsReadOnly

func (_ *Histogram) IsReadOnly() bool

type Metric

type Metric interface {
	// Export() constructs a dto.Metric from a value.Metric, the label names
	// in a label.Set, and the label values encoded in a label.RuneList.
	Export(
		metricKind mon.MetricKind,
		valueType mon.ValueType,
		ls *label.Set,
		rl label.RuneList,
		bounds []float64,
	) dto.Metric

	// Copy() returns a deep, read-only copy of a value.Metric.
	Copy(time.Duration) Metric

	// Float() returns the float64 value of the value.Metric (for histograms,
	// this is the sum of the observations).
	Float() float64

	// GcpEpoch() returns the Unix epoch seconds of the "end" timestamp of
	// the metric as reported by GCP.  This usually equals the end of the
	// most recent available sample period (except for Gauge metrics that
	// usually have metric values with startTime == endTime and sometimes
	// multiple such values in a single sample period).
	//
	GcpEpoch() int64

	// IsReadOnly() returns true if the value is a read-only copy.  It
	// returns false if the value can receive updates.
	IsReadOnly() bool

	// AsReadOnly() returns the invocant but type-cast to be read-only.
	AsReadOnly() Metric
}

A value.Metric is the interface for a single metric value.

type RwHistogram

type RwHistogram struct{ Histogram }

A value.RwHistogram is a value.Histogram that can receive updates.

func (*RwHistogram) AddFloat

func (hv *RwHistogram) AddFloat(f float64)

func (*RwHistogram) Convert

func (hv *RwHistogram) Convert(
	subBuckets []int,
	dv *sd.Distribution,
) float64

Convert() converts a GCP Distribution value into a Prometheus histogram value which is then added to the invoking value.RwHistogram. The sum of the (new) observations is returned so the caller can scale it and then add it in as well.

func (*RwHistogram) IsReadOnly

func (_ *RwHistogram) IsReadOnly() bool

func (*RwHistogram) SetEpoch

func (hv *RwHistogram) SetEpoch(e int64)

type RwMetric

type RwMetric interface {
	Metric
	AddFloat(float64)
	SetEpoch(int64)
}

A value.RwMetric is the interface to a value.Metric that also supports receiving updates.

type RwSimple

type RwSimple struct{ Simple }

A value.RwSimple is a value.Simple that can receive updates.

func (*RwSimple) AddFloat

func (sv *RwSimple) AddFloat(f float64)

func (*RwSimple) IsReadOnly

func (_ *RwSimple) IsReadOnly() bool

func (*RwSimple) SetEpoch

func (sv *RwSimple) SetEpoch(e int64)

type Simple

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

A value.Simple just contains a float64 metric value and a timestamp. It implmenets the value.Metric interface. It is read-only (but can be converted into a value.RwSimple).

func (*Simple) AsReadOnly

func (sv *Simple) AsReadOnly() Metric

func (*Simple) Copy

func (sv *Simple) Copy(samplePeriod time.Duration) Metric

func (*Simple) Export

func (sv *Simple) Export(
	metricKind mon.MetricKind,
	valueType mon.ValueType,
	ls *label.Set,
	rl label.RuneList,
	_ []float64,
) (m dto.Metric)

Simple's Export() returns a Protobuf version of a simple metric.

func (*Simple) Float

func (sv *Simple) Float() float64

func (*Simple) GcpEpoch

func (sv *Simple) GcpEpoch() int64

The following 3 methods work on all 4 Metric types:

func (*Simple) IsReadOnly

func (_ *Simple) IsReadOnly() bool

func (*Simple) PromEpoch

func (sv *Simple) PromEpoch() int64

type Writer

type Writer struct {
	PDesc  *prom.Desc
	Metric dto.Metric
}

A minimal object that can be collected as a prometheus metric.

func (Writer) Desc

func (mw Writer) Desc() *prom.Desc

func (Writer) Write

func (mw Writer) Write(out *dto.Metric) error

Jump to

Keyboard shortcuts

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