diff options
| author | 2024-09-16 11:06:00 +0200 | |
|---|---|---|
| committer | 2024-09-16 09:06:00 +0000 | |
| commit | b2572b9e074ebbce8bcf1b9979d4d8ea066650d6 (patch) | |
| tree | 0c2a08ed63b582676ce7661252a6917db751c62a /vendor/github.com/prometheus/common/expfmt/expfmt.go | |
| parent | [chore]: Bump golang.org/x/net from 0.28.0 to 0.29.0 (#3303) (diff) | |
| download | gotosocial-b2572b9e074ebbce8bcf1b9979d4d8ea066650d6.tar.xz | |
[chore] Bump otel deps -> v1.30.0/v0.52.0 (#3307)
Diffstat (limited to 'vendor/github.com/prometheus/common/expfmt/expfmt.go')
| -rw-r--r-- | vendor/github.com/prometheus/common/expfmt/expfmt.go | 76 | 
1 files changed, 53 insertions, 23 deletions
| diff --git a/vendor/github.com/prometheus/common/expfmt/expfmt.go b/vendor/github.com/prometheus/common/expfmt/expfmt.go index 051b38cd1..d942af8ed 100644 --- a/vendor/github.com/prometheus/common/expfmt/expfmt.go +++ b/vendor/github.com/prometheus/common/expfmt/expfmt.go @@ -32,24 +32,31 @@ type Format string  // it on the wire, new content-type strings will have to be agreed upon and  // added here.  const ( -	TextVersion              = "0.0.4" -	ProtoType                = `application/vnd.google.protobuf` -	ProtoProtocol            = `io.prometheus.client.MetricFamily` -	protoFmt                 = ProtoType + "; proto=" + ProtoProtocol + ";" +	TextVersion   = "0.0.4" +	ProtoType     = `application/vnd.google.protobuf` +	ProtoProtocol = `io.prometheus.client.MetricFamily` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoCompact) instead. +	ProtoFmt                 = ProtoType + "; proto=" + ProtoProtocol + ";"  	OpenMetricsType          = `application/openmetrics-text`  	OpenMetricsVersion_0_0_1 = "0.0.1"  	OpenMetricsVersion_1_0_0 = "1.0.0" -	// The Content-Type values for the different wire protocols. Note that these -	// values are now unexported. If code was relying on comparisons to these -	// constants, instead use FormatType(). -	fmtUnknown           Format = `<unknown>` -	fmtText              Format = `text/plain; version=` + TextVersion + `; charset=utf-8` -	fmtProtoDelim        Format = protoFmt + ` encoding=delimited` -	fmtProtoText         Format = protoFmt + ` encoding=text` -	fmtProtoCompact      Format = protoFmt + ` encoding=compact-text` -	fmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8` -	fmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8` +	// The Content-Type values for the different wire protocols. Do not do direct +	// comparisons to these constants, instead use the comparison functions. +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeUnknown) instead. +	FmtUnknown Format = `<unknown>` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeTextPlain) instead. +	FmtText Format = `text/plain; version=` + TextVersion + `; charset=utf-8` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoDelim) instead. +	FmtProtoDelim Format = ProtoFmt + ` encoding=delimited` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoText) instead. +	FmtProtoText Format = ProtoFmt + ` encoding=text` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeProtoCompact) instead. +	FmtProtoCompact Format = ProtoFmt + ` encoding=compact-text` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeOpenMetrics) instead. +	FmtOpenMetrics_1_0_0 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_1_0_0 + `; charset=utf-8` +	// Deprecated: Use expfmt.NewFormat(expfmt.TypeOpenMetrics) instead. +	FmtOpenMetrics_0_0_1 Format = OpenMetricsType + `; version=` + OpenMetricsVersion_0_0_1 + `; charset=utf-8`  )  const ( @@ -79,17 +86,17 @@ const (  func NewFormat(t FormatType) Format {  	switch t {  	case TypeProtoCompact: -		return fmtProtoCompact +		return FmtProtoCompact  	case TypeProtoDelim: -		return fmtProtoDelim +		return FmtProtoDelim  	case TypeProtoText: -		return fmtProtoText +		return FmtProtoText  	case TypeTextPlain: -		return fmtText +		return FmtText  	case TypeOpenMetrics: -		return fmtOpenMetrics_1_0_0 +		return FmtOpenMetrics_1_0_0  	default: -		return fmtUnknown +		return FmtUnknown  	}  } @@ -97,12 +104,35 @@ func NewFormat(t FormatType) Format {  // specified version number.  func NewOpenMetricsFormat(version string) (Format, error) {  	if version == OpenMetricsVersion_0_0_1 { -		return fmtOpenMetrics_0_0_1, nil +		return FmtOpenMetrics_0_0_1, nil  	}  	if version == OpenMetricsVersion_1_0_0 { -		return fmtOpenMetrics_1_0_0, nil +		return FmtOpenMetrics_1_0_0, nil  	} -	return fmtUnknown, fmt.Errorf("unknown open metrics version string") +	return FmtUnknown, fmt.Errorf("unknown open metrics version string") +} + +// WithEscapingScheme returns a copy of Format with the specified escaping +// scheme appended to the end. If an escaping scheme already exists it is +// removed. +func (f Format) WithEscapingScheme(s model.EscapingScheme) Format { +	var terms []string +	for _, p := range strings.Split(string(f), ";") { +		toks := strings.Split(p, "=") +		if len(toks) != 2 { +			trimmed := strings.TrimSpace(p) +			if len(trimmed) > 0 { +				terms = append(terms, trimmed) +			} +			continue +		} +		key := strings.TrimSpace(toks[0]) +		if key != model.EscapingKey { +			terms = append(terms, strings.TrimSpace(p)) +		} +	} +	terms = append(terms, model.EscapingKey+"="+s.String()) +	return Format(strings.Join(terms, "; "))  }  // FormatType deduces an overall FormatType for the given format. | 
