Bump github.com/prometheus/common from 0.48.0 to 0.54.0
Bumps [github.com/prometheus/common](https://github.com/prometheus/common) from 0.48.0 to 0.54.0. - [Release notes](https://github.com/prometheus/common/releases) - [Changelog](https://github.com/prometheus/common/blob/main/RELEASE.md) - [Commits](https://github.com/prometheus/common/compare/v0.48.0...v0.54.0) --- updated-dependencies: - dependency-name: github.com/prometheus/common dependency-type: indirect update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
ff592832c2
commit
935d8cb78e
12 changed files with 312 additions and 59 deletions
2
go.mod
2
go.mod
|
|
@ -43,7 +43,7 @@ require (
|
||||||
github.com/gomodule/redigo v2.0.0+incompatible // indirect
|
github.com/gomodule/redigo v2.0.0+incompatible // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.48.0 // indirect
|
github.com/prometheus/common v0.54.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
github.com/stretchr/testify v1.9.0 // indirect
|
github.com/stretchr/testify v1.9.0 // indirect
|
||||||
github.com/yuin/gopher-lua v1.1.1 // indirect
|
github.com/yuin/gopher-lua v1.1.1 // indirect
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -118,8 +118,8 @@ github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQ
|
||||||
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
|
||||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||||
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8=
|
||||||
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
|
github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ=
|
||||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||||
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
|
github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8=
|
||||||
|
|
|
||||||
6
vendor/github.com/prometheus/common/expfmt/decode.go
generated
vendored
6
vendor/github.com/prometheus/common/expfmt/decode.go
generated
vendored
|
|
@ -75,14 +75,14 @@ func ResponseFormat(h http.Header) Format {
|
||||||
func NewDecoder(r io.Reader, format Format) Decoder {
|
func NewDecoder(r io.Reader, format Format) Decoder {
|
||||||
switch format.FormatType() {
|
switch format.FormatType() {
|
||||||
case TypeProtoDelim:
|
case TypeProtoDelim:
|
||||||
return &protoDecoder{r: r}
|
return &protoDecoder{r: bufio.NewReader(r)}
|
||||||
}
|
}
|
||||||
return &textDecoder{r: r}
|
return &textDecoder{r: r}
|
||||||
}
|
}
|
||||||
|
|
||||||
// protoDecoder implements the Decoder interface for protocol buffers.
|
// protoDecoder implements the Decoder interface for protocol buffers.
|
||||||
type protoDecoder struct {
|
type protoDecoder struct {
|
||||||
r io.Reader
|
r protodelim.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode implements the Decoder interface.
|
// Decode implements the Decoder interface.
|
||||||
|
|
@ -90,7 +90,7 @@ func (d *protoDecoder) Decode(v *dto.MetricFamily) error {
|
||||||
opts := protodelim.UnmarshalOptions{
|
opts := protodelim.UnmarshalOptions{
|
||||||
MaxSize: -1,
|
MaxSize: -1,
|
||||||
}
|
}
|
||||||
if err := opts.UnmarshalFrom(bufio.NewReader(d.r), v); err != nil {
|
if err := opts.UnmarshalFrom(d.r, v); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !model.IsValidMetricName(model.LabelValue(v.GetName())) {
|
if !model.IsValidMetricName(model.LabelValue(v.GetName())) {
|
||||||
|
|
|
||||||
10
vendor/github.com/prometheus/common/expfmt/encode.go
generated
vendored
10
vendor/github.com/prometheus/common/expfmt/encode.go
generated
vendored
|
|
@ -139,7 +139,13 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
|
||||||
// interface is kept for backwards compatibility.
|
// interface is kept for backwards compatibility.
|
||||||
// In cases where the Format does not allow for UTF-8 names, the global
|
// In cases where the Format does not allow for UTF-8 names, the global
|
||||||
// NameEscapingScheme will be applied.
|
// NameEscapingScheme will be applied.
|
||||||
func NewEncoder(w io.Writer, format Format) Encoder {
|
//
|
||||||
|
// NewEncoder can be called with additional options to customize the OpenMetrics text output.
|
||||||
|
// For example:
|
||||||
|
// NewEncoder(w, FmtOpenMetrics_1_0_0, WithCreatedLines())
|
||||||
|
//
|
||||||
|
// Extra options are ignored for all other formats.
|
||||||
|
func NewEncoder(w io.Writer, format Format, options ...EncoderOption) Encoder {
|
||||||
escapingScheme := format.ToEscapingScheme()
|
escapingScheme := format.ToEscapingScheme()
|
||||||
|
|
||||||
switch format.FormatType() {
|
switch format.FormatType() {
|
||||||
|
|
@ -178,7 +184,7 @@ func NewEncoder(w io.Writer, format Format) Encoder {
|
||||||
case TypeOpenMetrics:
|
case TypeOpenMetrics:
|
||||||
return encoderCloser{
|
return encoderCloser{
|
||||||
encode: func(v *dto.MetricFamily) error {
|
encode: func(v *dto.MetricFamily) error {
|
||||||
_, err := MetricFamilyToOpenMetrics(w, model.EscapeMetricFamily(v, escapingScheme))
|
_, err := MetricFamilyToOpenMetrics(w, model.EscapeMetricFamily(v, escapingScheme), options...)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
close: func() error {
|
close: func() error {
|
||||||
|
|
|
||||||
22
vendor/github.com/prometheus/common/expfmt/expfmt.go
generated
vendored
22
vendor/github.com/prometheus/common/expfmt/expfmt.go
generated
vendored
|
|
@ -15,6 +15,7 @@
|
||||||
package expfmt
|
package expfmt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
|
@ -63,7 +64,7 @@ const (
|
||||||
type FormatType int
|
type FormatType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeUnknown = iota
|
TypeUnknown FormatType = iota
|
||||||
TypeProtoCompact
|
TypeProtoCompact
|
||||||
TypeProtoDelim
|
TypeProtoDelim
|
||||||
TypeProtoText
|
TypeProtoText
|
||||||
|
|
@ -73,7 +74,8 @@ const (
|
||||||
|
|
||||||
// NewFormat generates a new Format from the type provided. Mostly used for
|
// NewFormat generates a new Format from the type provided. Mostly used for
|
||||||
// tests, most Formats should be generated as part of content negotiation in
|
// tests, most Formats should be generated as part of content negotiation in
|
||||||
// encode.go.
|
// encode.go. If a type has more than one version, the latest version will be
|
||||||
|
// returned.
|
||||||
func NewFormat(t FormatType) Format {
|
func NewFormat(t FormatType) Format {
|
||||||
switch t {
|
switch t {
|
||||||
case TypeProtoCompact:
|
case TypeProtoCompact:
|
||||||
|
|
@ -91,13 +93,21 @@ func NewFormat(t FormatType) Format {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewOpenMetricsFormat generates a new OpenMetrics format matching the
|
||||||
|
// specified version number.
|
||||||
|
func NewOpenMetricsFormat(version string) (Format, error) {
|
||||||
|
if version == OpenMetricsVersion_0_0_1 {
|
||||||
|
return fmtOpenMetrics_0_0_1, nil
|
||||||
|
}
|
||||||
|
if version == OpenMetricsVersion_1_0_0 {
|
||||||
|
return fmtOpenMetrics_1_0_0, nil
|
||||||
|
}
|
||||||
|
return fmtUnknown, fmt.Errorf("unknown open metrics version string")
|
||||||
|
}
|
||||||
|
|
||||||
// FormatType deduces an overall FormatType for the given format.
|
// FormatType deduces an overall FormatType for the given format.
|
||||||
func (f Format) FormatType() FormatType {
|
func (f Format) FormatType() FormatType {
|
||||||
toks := strings.Split(string(f), ";")
|
toks := strings.Split(string(f), ";")
|
||||||
if len(toks) < 2 {
|
|
||||||
return TypeUnknown
|
|
||||||
}
|
|
||||||
|
|
||||||
params := make(map[string]string)
|
params := make(map[string]string)
|
||||||
for i, t := range toks {
|
for i, t := range toks {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
|
|
||||||
198
vendor/github.com/prometheus/common/expfmt/openmetrics_create.go
generated
vendored
198
vendor/github.com/prometheus/common/expfmt/openmetrics_create.go
generated
vendored
|
|
@ -22,11 +22,47 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type encoderOption struct {
|
||||||
|
withCreatedLines bool
|
||||||
|
withUnit bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type EncoderOption func(*encoderOption)
|
||||||
|
|
||||||
|
// WithCreatedLines is an EncoderOption that configures the OpenMetrics encoder
|
||||||
|
// to include _created lines (See
|
||||||
|
// https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#counter-1).
|
||||||
|
// Created timestamps can improve the accuracy of series reset detection, but
|
||||||
|
// come with a bandwidth cost.
|
||||||
|
//
|
||||||
|
// At the time of writing, created timestamp ingestion is still experimental in
|
||||||
|
// Prometheus and need to be enabled with the feature-flag
|
||||||
|
// `--feature-flag=created-timestamp-zero-ingestion`, and breaking changes are
|
||||||
|
// still possible. Therefore, it is recommended to use this feature with caution.
|
||||||
|
func WithCreatedLines() EncoderOption {
|
||||||
|
return func(t *encoderOption) {
|
||||||
|
t.withCreatedLines = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithUnit is an EncoderOption enabling a set unit to be written to the output
|
||||||
|
// and to be added to the metric name, if it's not there already, as a suffix.
|
||||||
|
// Without opting in this way, the unit will not be added to the metric name and,
|
||||||
|
// on top of that, the unit will not be passed onto the output, even if it
|
||||||
|
// were declared in the *dto.MetricFamily struct, i.e. even if in.Unit !=nil.
|
||||||
|
func WithUnit() EncoderOption {
|
||||||
|
return func(t *encoderOption) {
|
||||||
|
t.withUnit = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MetricFamilyToOpenMetrics converts a MetricFamily proto message into the
|
// MetricFamilyToOpenMetrics converts a MetricFamily proto message into the
|
||||||
// OpenMetrics text format and writes the resulting lines to 'out'. It returns
|
// OpenMetrics text format and writes the resulting lines to 'out'. It returns
|
||||||
// the number of bytes written and any error encountered. The output will have
|
// the number of bytes written and any error encountered. The output will have
|
||||||
|
|
@ -59,20 +95,34 @@ import (
|
||||||
// Prometheus to OpenMetrics or vice versa:
|
// Prometheus to OpenMetrics or vice versa:
|
||||||
//
|
//
|
||||||
// - Counters are expected to have the `_total` suffix in their metric name. In
|
// - Counters are expected to have the `_total` suffix in their metric name. In
|
||||||
// the output, the suffix will be truncated from the `# TYPE` and `# HELP`
|
// the output, the suffix will be truncated from the `# TYPE`, `# HELP` and `# UNIT`
|
||||||
// line. A counter with a missing `_total` suffix is not an error. However,
|
// lines. A counter with a missing `_total` suffix is not an error. However,
|
||||||
// its type will be set to `unknown` in that case to avoid invalid OpenMetrics
|
// its type will be set to `unknown` in that case to avoid invalid OpenMetrics
|
||||||
// output.
|
// output.
|
||||||
//
|
//
|
||||||
// - No support for the following (optional) features: `# UNIT` line, `_created`
|
// - According to the OM specs, the `# UNIT` line is optional, but if populated,
|
||||||
// line, info type, stateset type, gaugehistogram type.
|
// the unit has to be present in the metric name as its suffix:
|
||||||
|
// (see https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#unit).
|
||||||
|
// However, in order to accommodate any potential scenario where such a change in the
|
||||||
|
// metric name is not desirable, the users are here given the choice of either explicitly
|
||||||
|
// opt in, in case they wish for the unit to be included in the output AND in the metric name
|
||||||
|
// as a suffix (see the description of the WithUnit function above),
|
||||||
|
// or not to opt in, in case they don't want for any of that to happen.
|
||||||
|
//
|
||||||
|
// - No support for the following (optional) features: info type,
|
||||||
|
// stateset type, gaugehistogram type.
|
||||||
//
|
//
|
||||||
// - The size of exemplar labels is not checked (i.e. it's possible to create
|
// - The size of exemplar labels is not checked (i.e. it's possible to create
|
||||||
// exemplars that are larger than allowed by the OpenMetrics specification).
|
// exemplars that are larger than allowed by the OpenMetrics specification).
|
||||||
//
|
//
|
||||||
// - The value of Counters is not checked. (OpenMetrics doesn't allow counters
|
// - The value of Counters is not checked. (OpenMetrics doesn't allow counters
|
||||||
// with a `NaN` value.)
|
// with a `NaN` value.)
|
||||||
func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int, err error) {
|
func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily, options ...EncoderOption) (written int, err error) {
|
||||||
|
toOM := encoderOption{}
|
||||||
|
for _, option := range options {
|
||||||
|
option(&toOM)
|
||||||
|
}
|
||||||
|
|
||||||
name := in.GetName()
|
name := in.GetName()
|
||||||
if name == "" {
|
if name == "" {
|
||||||
return 0, fmt.Errorf("MetricFamily has no name: %s", in)
|
return 0, fmt.Errorf("MetricFamily has no name: %s", in)
|
||||||
|
|
@ -97,10 +147,13 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
var (
|
var (
|
||||||
n int
|
n int
|
||||||
metricType = in.GetType()
|
metricType = in.GetType()
|
||||||
shortName = name
|
compliantName = name
|
||||||
)
|
)
|
||||||
if metricType == dto.MetricType_COUNTER && strings.HasSuffix(shortName, "_total") {
|
if metricType == dto.MetricType_COUNTER && strings.HasSuffix(compliantName, "_total") {
|
||||||
shortName = name[:len(name)-6]
|
compliantName = name[:len(name)-6]
|
||||||
|
}
|
||||||
|
if toOM.withUnit && in.Unit != nil && !strings.HasSuffix(compliantName, fmt.Sprintf("_%s", *in.Unit)) {
|
||||||
|
compliantName = compliantName + fmt.Sprintf("_%s", *in.Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments, first HELP, then TYPE.
|
// Comments, first HELP, then TYPE.
|
||||||
|
|
@ -110,7 +163,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = writeName(w, shortName)
|
n, err = writeName(w, compliantName)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -136,7 +189,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = writeName(w, shortName)
|
n, err = writeName(w, compliantName)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -163,55 +216,89 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if toOM.withUnit && in.Unit != nil {
|
||||||
|
n, err = w.WriteString("# UNIT ")
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
n, err = writeName(w, compliantName)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = w.WriteByte(' ')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
n, err = writeEscapedString(w, *in.Unit, true)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = w.WriteByte('\n')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var createdTsBytesWritten int
|
||||||
|
|
||||||
// Finally the samples, one line for each.
|
// Finally the samples, one line for each.
|
||||||
|
if metricType == dto.MetricType_COUNTER && strings.HasSuffix(name, "_total") {
|
||||||
|
compliantName = compliantName + "_total"
|
||||||
|
}
|
||||||
for _, metric := range in.Metric {
|
for _, metric := range in.Metric {
|
||||||
switch metricType {
|
switch metricType {
|
||||||
case dto.MetricType_COUNTER:
|
case dto.MetricType_COUNTER:
|
||||||
if metric.Counter == nil {
|
if metric.Counter == nil {
|
||||||
return written, fmt.Errorf(
|
return written, fmt.Errorf(
|
||||||
"expected counter in metric %s %s", name, metric,
|
"expected counter in metric %s %s", compliantName, metric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Note that we have ensured above that either the name
|
|
||||||
// ends on `_total` or that the rendered type is
|
|
||||||
// `unknown`. Therefore, no `_total` must be added here.
|
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "", metric, "", 0,
|
w, compliantName, "", metric, "", 0,
|
||||||
metric.Counter.GetValue(), 0, false,
|
metric.Counter.GetValue(), 0, false,
|
||||||
metric.Counter.Exemplar,
|
metric.Counter.Exemplar,
|
||||||
)
|
)
|
||||||
|
if toOM.withCreatedLines && metric.Counter.CreatedTimestamp != nil {
|
||||||
|
createdTsBytesWritten, err = writeOpenMetricsCreated(w, compliantName, "_total", metric, "", 0, metric.Counter.GetCreatedTimestamp())
|
||||||
|
n += createdTsBytesWritten
|
||||||
|
}
|
||||||
case dto.MetricType_GAUGE:
|
case dto.MetricType_GAUGE:
|
||||||
if metric.Gauge == nil {
|
if metric.Gauge == nil {
|
||||||
return written, fmt.Errorf(
|
return written, fmt.Errorf(
|
||||||
"expected gauge in metric %s %s", name, metric,
|
"expected gauge in metric %s %s", compliantName, metric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "", metric, "", 0,
|
w, compliantName, "", metric, "", 0,
|
||||||
metric.Gauge.GetValue(), 0, false,
|
metric.Gauge.GetValue(), 0, false,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
case dto.MetricType_UNTYPED:
|
case dto.MetricType_UNTYPED:
|
||||||
if metric.Untyped == nil {
|
if metric.Untyped == nil {
|
||||||
return written, fmt.Errorf(
|
return written, fmt.Errorf(
|
||||||
"expected untyped in metric %s %s", name, metric,
|
"expected untyped in metric %s %s", compliantName, metric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "", metric, "", 0,
|
w, compliantName, "", metric, "", 0,
|
||||||
metric.Untyped.GetValue(), 0, false,
|
metric.Untyped.GetValue(), 0, false,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
case dto.MetricType_SUMMARY:
|
case dto.MetricType_SUMMARY:
|
||||||
if metric.Summary == nil {
|
if metric.Summary == nil {
|
||||||
return written, fmt.Errorf(
|
return written, fmt.Errorf(
|
||||||
"expected summary in metric %s %s", name, metric,
|
"expected summary in metric %s %s", compliantName, metric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
for _, q := range metric.Summary.Quantile {
|
for _, q := range metric.Summary.Quantile {
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "", metric,
|
w, compliantName, "", metric,
|
||||||
model.QuantileLabel, q.GetQuantile(),
|
model.QuantileLabel, q.GetQuantile(),
|
||||||
q.GetValue(), 0, false,
|
q.GetValue(), 0, false,
|
||||||
nil,
|
nil,
|
||||||
|
|
@ -222,7 +309,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "_sum", metric, "", 0,
|
w, compliantName, "_sum", metric, "", 0,
|
||||||
metric.Summary.GetSampleSum(), 0, false,
|
metric.Summary.GetSampleSum(), 0, false,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
@ -231,20 +318,24 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "_count", metric, "", 0,
|
w, compliantName, "_count", metric, "", 0,
|
||||||
0, metric.Summary.GetSampleCount(), true,
|
0, metric.Summary.GetSampleCount(), true,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
if toOM.withCreatedLines && metric.Summary.CreatedTimestamp != nil {
|
||||||
|
createdTsBytesWritten, err = writeOpenMetricsCreated(w, compliantName, "", metric, "", 0, metric.Summary.GetCreatedTimestamp())
|
||||||
|
n += createdTsBytesWritten
|
||||||
|
}
|
||||||
case dto.MetricType_HISTOGRAM:
|
case dto.MetricType_HISTOGRAM:
|
||||||
if metric.Histogram == nil {
|
if metric.Histogram == nil {
|
||||||
return written, fmt.Errorf(
|
return written, fmt.Errorf(
|
||||||
"expected histogram in metric %s %s", name, metric,
|
"expected histogram in metric %s %s", compliantName, metric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
infSeen := false
|
infSeen := false
|
||||||
for _, b := range metric.Histogram.Bucket {
|
for _, b := range metric.Histogram.Bucket {
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "_bucket", metric,
|
w, compliantName, "_bucket", metric,
|
||||||
model.BucketLabel, b.GetUpperBound(),
|
model.BucketLabel, b.GetUpperBound(),
|
||||||
0, b.GetCumulativeCount(), true,
|
0, b.GetCumulativeCount(), true,
|
||||||
b.Exemplar,
|
b.Exemplar,
|
||||||
|
|
@ -259,7 +350,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
}
|
}
|
||||||
if !infSeen {
|
if !infSeen {
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "_bucket", metric,
|
w, compliantName, "_bucket", metric,
|
||||||
model.BucketLabel, math.Inf(+1),
|
model.BucketLabel, math.Inf(+1),
|
||||||
0, metric.Histogram.GetSampleCount(), true,
|
0, metric.Histogram.GetSampleCount(), true,
|
||||||
nil,
|
nil,
|
||||||
|
|
@ -270,7 +361,7 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "_sum", metric, "", 0,
|
w, compliantName, "_sum", metric, "", 0,
|
||||||
metric.Histogram.GetSampleSum(), 0, false,
|
metric.Histogram.GetSampleSum(), 0, false,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
@ -279,13 +370,17 @@ func MetricFamilyToOpenMetrics(out io.Writer, in *dto.MetricFamily) (written int
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n, err = writeOpenMetricsSample(
|
n, err = writeOpenMetricsSample(
|
||||||
w, name, "_count", metric, "", 0,
|
w, compliantName, "_count", metric, "", 0,
|
||||||
0, metric.Histogram.GetSampleCount(), true,
|
0, metric.Histogram.GetSampleCount(), true,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
if toOM.withCreatedLines && metric.Histogram.CreatedTimestamp != nil {
|
||||||
|
createdTsBytesWritten, err = writeOpenMetricsCreated(w, compliantName, "", metric, "", 0, metric.Histogram.GetCreatedTimestamp())
|
||||||
|
n += createdTsBytesWritten
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return written, fmt.Errorf(
|
return written, fmt.Errorf(
|
||||||
"unexpected type in metric %s %s", name, metric,
|
"unexpected type in metric %s %s", compliantName, metric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
written += n
|
written += n
|
||||||
|
|
@ -350,7 +445,7 @@ func writeOpenMetricsSample(
|
||||||
return written, err
|
return written, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if exemplar != nil {
|
if exemplar != nil && len(exemplar.Label) > 0 {
|
||||||
n, err = writeExemplar(w, exemplar)
|
n, err = writeExemplar(w, exemplar)
|
||||||
written += n
|
written += n
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -473,6 +568,49 @@ func writeOpenMetricsNameAndLabelPairs(
|
||||||
return written, nil
|
return written, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeOpenMetricsCreated writes the created timestamp for a single time series
|
||||||
|
// following OpenMetrics text format to w, given the metric name, the metric proto
|
||||||
|
// message itself, optionally a suffix to be removed, e.g. '_total' for counters,
|
||||||
|
// an additional label name with a float64 value (use empty string as label name if
|
||||||
|
// not required) and the timestamp that represents the created timestamp.
|
||||||
|
// The function returns the number of bytes written and any error encountered.
|
||||||
|
func writeOpenMetricsCreated(w enhancedWriter,
|
||||||
|
name, suffixToTrim string, metric *dto.Metric,
|
||||||
|
additionalLabelName string, additionalLabelValue float64,
|
||||||
|
createdTimestamp *timestamppb.Timestamp,
|
||||||
|
) (int, error) {
|
||||||
|
written := 0
|
||||||
|
n, err := writeOpenMetricsNameAndLabelPairs(
|
||||||
|
w, strings.TrimSuffix(name, suffixToTrim)+"_created", metric.Label, additionalLabelName, additionalLabelValue,
|
||||||
|
)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = w.WriteByte(' ')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(beorn7): Format this directly from components of ts to
|
||||||
|
// avoid overflow/underflow and precision issues of the float
|
||||||
|
// conversion.
|
||||||
|
n, err = writeOpenMetricsFloat(w, float64(createdTimestamp.AsTime().UnixNano())/1e9)
|
||||||
|
written += n
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = w.WriteByte('\n')
|
||||||
|
written++
|
||||||
|
if err != nil {
|
||||||
|
return written, err
|
||||||
|
}
|
||||||
|
return written, nil
|
||||||
|
}
|
||||||
|
|
||||||
// writeExemplar writes the provided exemplar in OpenMetrics format to w. The
|
// writeExemplar writes the provided exemplar in OpenMetrics format to w. The
|
||||||
// function returns the number of bytes written and any error encountered.
|
// function returns the number of bytes written and any error encountered.
|
||||||
func writeExemplar(w enhancedWriter, e *dto.Exemplar) (int, error) {
|
func writeExemplar(w enhancedWriter, e *dto.Exemplar) (int, error) {
|
||||||
|
|
|
||||||
27
vendor/github.com/prometheus/common/model/alert.go
generated
vendored
27
vendor/github.com/prometheus/common/model/alert.go
generated
vendored
|
|
@ -75,7 +75,12 @@ func (a *Alert) ResolvedAt(ts time.Time) bool {
|
||||||
|
|
||||||
// Status returns the status of the alert.
|
// Status returns the status of the alert.
|
||||||
func (a *Alert) Status() AlertStatus {
|
func (a *Alert) Status() AlertStatus {
|
||||||
if a.Resolved() {
|
return a.StatusAt(time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusAt returns the status of the alert at the given timestamp.
|
||||||
|
func (a *Alert) StatusAt(ts time.Time) AlertStatus {
|
||||||
|
if a.ResolvedAt(ts) {
|
||||||
return AlertResolved
|
return AlertResolved
|
||||||
}
|
}
|
||||||
return AlertFiring
|
return AlertFiring
|
||||||
|
|
@ -127,6 +132,17 @@ func (as Alerts) HasFiring() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasFiringAt returns true iff one of the alerts is not resolved
|
||||||
|
// at the time ts.
|
||||||
|
func (as Alerts) HasFiringAt(ts time.Time) bool {
|
||||||
|
for _, a := range as {
|
||||||
|
if !a.ResolvedAt(ts) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Status returns StatusFiring iff at least one of the alerts is firing.
|
// Status returns StatusFiring iff at least one of the alerts is firing.
|
||||||
func (as Alerts) Status() AlertStatus {
|
func (as Alerts) Status() AlertStatus {
|
||||||
if as.HasFiring() {
|
if as.HasFiring() {
|
||||||
|
|
@ -134,3 +150,12 @@ func (as Alerts) Status() AlertStatus {
|
||||||
}
|
}
|
||||||
return AlertResolved
|
return AlertResolved
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatusAt returns StatusFiring iff at least one of the alerts is firing
|
||||||
|
// at the time ts.
|
||||||
|
func (as Alerts) StatusAt(ts time.Time) AlertStatus {
|
||||||
|
if as.HasFiringAt(ts) {
|
||||||
|
return AlertFiring
|
||||||
|
}
|
||||||
|
return AlertResolved
|
||||||
|
}
|
||||||
|
|
|
||||||
11
vendor/github.com/prometheus/common/model/labelset.go
generated
vendored
11
vendor/github.com/prometheus/common/model/labelset.go
generated
vendored
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet
|
// A LabelSet is a collection of LabelName and LabelValue pairs. The LabelSet
|
||||||
|
|
@ -129,16 +128,6 @@ func (l LabelSet) Merge(other LabelSet) LabelSet {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l LabelSet) String() string {
|
|
||||||
lstrs := make([]string, 0, len(l))
|
|
||||||
for l, v := range l {
|
|
||||||
lstrs = append(lstrs, fmt.Sprintf("%s=%q", l, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(lstrs)
|
|
||||||
return fmt.Sprintf("{%s}", strings.Join(lstrs, ", "))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fingerprint returns the LabelSet's fingerprint.
|
// Fingerprint returns the LabelSet's fingerprint.
|
||||||
func (ls LabelSet) Fingerprint() Fingerprint {
|
func (ls LabelSet) Fingerprint() Fingerprint {
|
||||||
return labelSetToFingerprint(ls)
|
return labelSetToFingerprint(ls)
|
||||||
|
|
|
||||||
45
vendor/github.com/prometheus/common/model/labelset_string.go
generated
vendored
Normal file
45
vendor/github.com/prometheus/common/model/labelset_string.go
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright 2024 The Prometheus Authors
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build go1.21
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// String will look like `{foo="bar", more="less"}`. Names are sorted alphabetically.
|
||||||
|
func (l LabelSet) String() string {
|
||||||
|
var lna [32]string // On stack to avoid memory allocation for sorting names.
|
||||||
|
labelNames := lna[:0]
|
||||||
|
for name := range l {
|
||||||
|
labelNames = append(labelNames, string(name))
|
||||||
|
}
|
||||||
|
slices.Sort(labelNames)
|
||||||
|
var bytea [1024]byte // On stack to avoid memory allocation while building the output.
|
||||||
|
b := bytes.NewBuffer(bytea[:0])
|
||||||
|
b.WriteByte('{')
|
||||||
|
for i, name := range labelNames {
|
||||||
|
if i > 0 {
|
||||||
|
b.WriteString(", ")
|
||||||
|
}
|
||||||
|
b.WriteString(name)
|
||||||
|
b.WriteByte('=')
|
||||||
|
b.Write(strconv.AppendQuote(b.AvailableBuffer(), string(l[LabelName(name)])))
|
||||||
|
}
|
||||||
|
b.WriteByte('}')
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
39
vendor/github.com/prometheus/common/model/labelset_string_go120.go
generated
vendored
Normal file
39
vendor/github.com/prometheus/common/model/labelset_string_go120.go
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright 2024 The Prometheus Authors
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build !go1.21
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// String was optimized using functions not available for go 1.20
|
||||||
|
// or lower. We keep the old implementation for compatibility with client_golang.
|
||||||
|
// Once client golang drops support for go 1.20 (scheduled for August 2024), this
|
||||||
|
// file can be removed.
|
||||||
|
func (l LabelSet) String() string {
|
||||||
|
labelNames := make([]string, 0, len(l))
|
||||||
|
for name := range l {
|
||||||
|
labelNames = append(labelNames, string(name))
|
||||||
|
}
|
||||||
|
sort.Strings(labelNames)
|
||||||
|
lstrs := make([]string, 0, len(l))
|
||||||
|
for _, name := range labelNames {
|
||||||
|
lstrs = append(lstrs, fmt.Sprintf("%s=%q", name, l[LabelName(name)]))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("{%s}", strings.Join(lstrs, ", "))
|
||||||
|
}
|
||||||
1
vendor/github.com/prometheus/common/model/metric.go
generated
vendored
1
vendor/github.com/prometheus/common/model/metric.go
generated
vendored
|
|
@ -204,6 +204,7 @@ func EscapeMetricFamily(v *dto.MetricFamily, scheme EscapingScheme) *dto.MetricF
|
||||||
out := &dto.MetricFamily{
|
out := &dto.MetricFamily{
|
||||||
Help: v.Help,
|
Help: v.Help,
|
||||||
Type: v.Type,
|
Type: v.Type,
|
||||||
|
Unit: v.Unit,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the name is nil, copy as-is, don't try to escape.
|
// If the name is nil, copy as-is, don't try to escape.
|
||||||
|
|
|
||||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
|
@ -181,7 +181,7 @@ github.com/prometheus/client_golang/prometheus/internal
|
||||||
# github.com/prometheus/client_model v0.6.1
|
# github.com/prometheus/client_model v0.6.1
|
||||||
## explicit; go 1.19
|
## explicit; go 1.19
|
||||||
github.com/prometheus/client_model/go
|
github.com/prometheus/client_model/go
|
||||||
# github.com/prometheus/common v0.48.0
|
# github.com/prometheus/common v0.54.0
|
||||||
## explicit; go 1.20
|
## explicit; go 1.20
|
||||||
github.com/prometheus/common/expfmt
|
github.com/prometheus/common/expfmt
|
||||||
github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
|
github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue