From d74a7fb0b6229d8d9fd96c221d55ff78af576722 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sun, 26 Nov 2023 14:49:09 +0100 Subject: [PATCH 01/27] start adding support for units Signed-off-by: Arianna Vespri --- go.mod | 4 ++++ go.sum | 8 +++---- prometheus/build_info_collector.go | 1 + prometheus/collectors/dbstats_collector.go | 9 ++++++++ prometheus/counter.go | 3 +++ prometheus/desc.go | 15 ++++++++---- prometheus/desc_test.go | 1 + prometheus/example_clustermanager_test.go | 2 ++ prometheus/example_metricvec_test.go | 5 ++-- prometheus/examples_test.go | 9 ++++++-- prometheus/expvar_collector_test.go | 3 +++ prometheus/gauge.go | 3 +++ prometheus/gauge_test.go | 2 +- prometheus/go_collector.go | 27 ++++++++++++++++++++++ prometheus/go_collector_latest.go | 1 + prometheus/histogram.go | 5 ++++ prometheus/metric.go | 3 +++ prometheus/metric_test.go | 2 +- prometheus/process_collector.go | 7 ++++++ prometheus/promhttp/http_test.go | 10 ++++---- prometheus/registry_test.go | 2 +- prometheus/summary.go | 5 ++++ prometheus/testutil/testutil_test.go | 4 ++-- prometheus/untyped.go | 1 + prometheus/value_test.go | 2 ++ prometheus/wrap.go | 3 ++- 26 files changed, 113 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index a70491263..88ae88504 100644 --- a/go.mod +++ b/go.mod @@ -30,3 +30,7 @@ require ( ) exclude github.com/prometheus/client_golang v1.12.1 + +replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20231121140958-784d3aad4c30 + +replace github.com/prometheus/client_model => github.com/vesari/client_model v0.0.0-20231118150741-19723af61627 diff --git a/go.sum b/go.sum index 7e031b561..c8f442a49 100644 --- a/go.sum +++ b/go.sum @@ -33,10 +33,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= -github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= -github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -44,6 +40,10 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/vesari/client_model v0.0.0-20231118150741-19723af61627 h1:pJsecGZFkJIN3ipp7fS8hLDK0Dcnk2JVxXds3Dev3dQ= +github.com/vesari/client_model v0.0.0-20231118150741-19723af61627/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/vesari/common v0.0.0-20231121140958-784d3aad4c30 h1:WaoSRlUM9CilXfZwJ5WIsFJKLnwJ6/WZjyT1oiiRO7s= +github.com/vesari/common v0.0.0-20231121140958-784d3aad4c30/go.mod h1:F2CatmaM24xsPNg4EqskJKMF+Tl27WbRF+Exgus+vOw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= diff --git a/prometheus/build_info_collector.go b/prometheus/build_info_collector.go index 450189f35..3f1fe169a 100644 --- a/prometheus/build_info_collector.go +++ b/prometheus/build_info_collector.go @@ -30,6 +30,7 @@ func NewBuildInfoCollector() Collector { NewDesc( "go_build_info", "Build information about the main Go module.", + "", nil, Labels{"path": path, "version": version, "checksum": sum}, ), GaugeValue, 1)} diff --git a/prometheus/collectors/dbstats_collector.go b/prometheus/collectors/dbstats_collector.go index d5a7279fb..22ab51139 100644 --- a/prometheus/collectors/dbstats_collector.go +++ b/prometheus/collectors/dbstats_collector.go @@ -46,46 +46,55 @@ func NewDBStatsCollector(db *sql.DB, dbName string) prometheus.Collector { maxOpenConnections: prometheus.NewDesc( fqName("max_open_connections"), "Maximum number of open connections to the database.", + "", nil, prometheus.Labels{"db_name": dbName}, ), openConnections: prometheus.NewDesc( fqName("open_connections"), "The number of established connections both in use and idle.", + "", nil, prometheus.Labels{"db_name": dbName}, ), inUseConnections: prometheus.NewDesc( fqName("in_use_connections"), "The number of connections currently in use.", + "", nil, prometheus.Labels{"db_name": dbName}, ), idleConnections: prometheus.NewDesc( fqName("idle_connections"), "The number of idle connections.", + "", nil, prometheus.Labels{"db_name": dbName}, ), waitCount: prometheus.NewDesc( fqName("wait_count_total"), "The total number of connections waited for.", + "", nil, prometheus.Labels{"db_name": dbName}, ), waitDuration: prometheus.NewDesc( fqName("wait_duration_seconds_total"), "The total time blocked waiting for a new connection.", + "seconds", nil, prometheus.Labels{"db_name": dbName}, ), maxIdleClosed: prometheus.NewDesc( fqName("max_idle_closed_total"), "The total number of connections closed due to SetMaxIdleConns.", + "", nil, prometheus.Labels{"db_name": dbName}, ), maxIdleTimeClosed: prometheus.NewDesc( fqName("max_idle_time_closed_total"), "The total number of connections closed due to SetConnMaxIdleTime.", + "", nil, prometheus.Labels{"db_name": dbName}, ), maxLifetimeClosed: prometheus.NewDesc( fqName("max_lifetime_closed_total"), "The total number of connections closed due to SetConnMaxLifetime.", + "", nil, prometheus.Labels{"db_name": dbName}, ), } diff --git a/prometheus/counter.go b/prometheus/counter.go index 4ce84e7a8..eef38bc30 100644 --- a/prometheus/counter.go +++ b/prometheus/counter.go @@ -88,6 +88,7 @@ func NewCounter(opts CounterOpts) Counter { desc := NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ) @@ -203,6 +204,7 @@ func (v2) NewCounterVec(opts CounterVecOpts) *CounterVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, opts.VariableLabels, opts.ConstLabels, ) @@ -352,6 +354,7 @@ func NewCounterFunc(opts CounterOpts, function func() float64) CounterFunc { return newValueFunc(NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ), CounterValue, function) diff --git a/prometheus/desc.go b/prometheus/desc.go index 68ffe3c24..c32dbf63e 100644 --- a/prometheus/desc.go +++ b/prometheus/desc.go @@ -47,6 +47,8 @@ type Desc struct { fqName string // help provides some helpful information about this metric. help string + // unit provides the unit of this metric. + unit string // constLabelPairs contains precalculated DTO label pairs based on // the constant labels. constLabelPairs []*dto.LabelPair @@ -75,8 +77,8 @@ type Desc struct { // // For constLabels, the label values are constant. Therefore, they are fully // specified in the Desc. See the Collector example for a usage pattern. -func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *Desc { - return V2.NewDesc(fqName, help, UnconstrainedLabels(variableLabels), constLabels) +func NewDesc(fqName, help, unit string, variableLabels []string, constLabels Labels) *Desc { + return V2.NewDesc(fqName, help, unit, UnconstrainedLabels(variableLabels), constLabels) } // NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc @@ -89,10 +91,11 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) * // // For constLabels, the label values are constant. Therefore, they are fully // specified in the Desc. See the Collector example for a usage pattern. -func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels) *Desc { +func (v2) NewDesc(fqName, help, unit string, variableLabels ConstrainableLabels, constLabels Labels) *Desc { d := &Desc{ fqName: fqName, help: help, + unit: unit, variableLabels: variableLabels.compile(), } if !model.IsValidMetricName(model.LabelValue(fqName)) { @@ -149,10 +152,11 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const d.id = xxh.Sum64() // Sort labelNames so that order doesn't matter for the hash. sort.Strings(labelNames) - // Now hash together (in this order) the help string and the sorted + // Now hash together (in this order) the help string, the unit string and the sorted // label names. xxh.Reset() xxh.WriteString(help) + xxh.WriteString(unit) xxh.Write(separatorByteSlice) for _, labelName := range labelNames { xxh.WriteString(labelName) @@ -198,9 +202,10 @@ func (d *Desc) String() string { } } return fmt.Sprintf( - "Desc{fqName: %q, help: %q, constLabels: {%s}, variableLabels: {%s}}", + "Desc{fqName: %q, help: %q, unit: %q, constLabels: {%s}, variableLabels: {%s}}", d.fqName, d.help, + d.unit, strings.Join(lpStrings, ","), strings.Join(vlStrings, ","), ) diff --git a/prometheus/desc_test.go b/prometheus/desc_test.go index 5f854db0b..6443318f6 100644 --- a/prometheus/desc_test.go +++ b/prometheus/desc_test.go @@ -21,6 +21,7 @@ func TestNewDescInvalidLabelValues(t *testing.T) { desc := NewDesc( "sample_label", "sample label", + "", nil, Labels{"a": "\xFF"}, ) diff --git a/prometheus/example_clustermanager_test.go b/prometheus/example_clustermanager_test.go index 92b61ca85..b995677fa 100644 --- a/prometheus/example_clustermanager_test.go +++ b/prometheus/example_clustermanager_test.go @@ -66,11 +66,13 @@ var ( oomCountDesc = prometheus.NewDesc( "clustermanager_oom_crashes_total", "Number of OOM crashes.", + "", []string{"host"}, nil, ) ramUsageDesc = prometheus.NewDesc( "clustermanager_ram_usage_bytes", "RAM usage as reported to the cluster manager.", + "bytes", []string{"host"}, nil, ) ) diff --git a/prometheus/example_metricvec_test.go b/prometheus/example_metricvec_test.go index 59e43f8f8..8bf8e9739 100644 --- a/prometheus/example_metricvec_test.go +++ b/prometheus/example_metricvec_test.go @@ -52,8 +52,8 @@ type InfoVec struct { *prometheus.MetricVec } -func NewInfoVec(name, help string, labelNames []string) *InfoVec { - desc := prometheus.NewDesc(name, help, labelNames, nil) +func NewInfoVec(name, help, unit string, labelNames []string) *InfoVec { + desc := prometheus.NewDesc(name, help, unit, labelNames, nil) return &InfoVec{ MetricVec: prometheus.NewMetricVec(desc, func(lvs ...string) prometheus.Metric { if len(lvs) != len(labelNames) { @@ -110,6 +110,7 @@ func ExampleMetricVec() { infoVec := NewInfoVec( "library_version_info", "Versions of the libraries used in this binary.", + "", []string{"library", "version"}, ) diff --git a/prometheus/examples_test.go b/prometheus/examples_test.go index e4fed3e95..c4c06851b 100644 --- a/prometheus/examples_test.go +++ b/prometheus/examples_test.go @@ -308,9 +308,9 @@ func ExampleRegister() { // Output: // taskCounter registered. - // taskCounterVec not registered: a previously registered descriptor with the same fully-qualified name as Desc{fqName: "worker_pool_completed_tasks_total", help: "Total number of tasks completed.", constLabels: {}, variableLabels: {worker_id}} has different label names or a different help string + // taskCounterVec not registered: a previously registered descriptor with the same fully-qualified name as Desc{fqName: "worker_pool_completed_tasks_total", help: "Total number of tasks completed.", unit: "", constLabels: {}, variableLabels: {worker_id}} has different label names or a different help string // taskCounter unregistered. - // taskCounterVec not registered: a previously registered descriptor with the same fully-qualified name as Desc{fqName: "worker_pool_completed_tasks_total", help: "Total number of tasks completed.", constLabels: {}, variableLabels: {worker_id}} has different label names or a different help string + // taskCounterVec not registered: a previously registered descriptor with the same fully-qualified name as Desc{fqName: "worker_pool_completed_tasks_total", help: "Total number of tasks completed.", unit: "", constLabels: {}, variableLabels: {worker_id}} has different label names or a different help string // taskCounterVec registered. // Worker initialization failed: inconsistent label cardinality: expected 1 label values but got 2 in []string{"42", "spurious arg"} // notMyCounter is nil. @@ -382,6 +382,7 @@ func ExampleNewConstSummary() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A summary of the HTTP request durations.", + "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -433,6 +434,7 @@ func ExampleNewConstHistogram() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", + "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -460,6 +462,7 @@ func ExampleNewConstHistogram_WithExemplar() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", + "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -630,6 +633,7 @@ func ExampleNewMetricWithTimestamp() { desc := prometheus.NewDesc( "temperature_kelvin", "Current temperature in Kelvin.", + "kelvin", nil, nil, ) @@ -663,6 +667,7 @@ func ExampleNewConstMetricWithCreatedTimestamp() { desc := prometheus.NewDesc( "time_since_epoch_seconds", "Current epoch time in seconds.", + "seconds", nil, nil, ) diff --git a/prometheus/expvar_collector_test.go b/prometheus/expvar_collector_test.go index a8d0ed294..88d25019a 100644 --- a/prometheus/expvar_collector_test.go +++ b/prometheus/expvar_collector_test.go @@ -29,16 +29,19 @@ func ExampleNewExpvarCollector() { "memstats": prometheus.NewDesc( "expvar_memstats", "All numeric memstats as one metric family. Not a good role-model, actually... ;-)", + "", []string{"type"}, nil, ), "lone-int": prometheus.NewDesc( "expvar_lone_int", "Just an expvar int as an example.", + "", nil, nil, ), "http-request-map": prometheus.NewDesc( "expvar_http_request_total", "How many http requests processed, partitioned by status code and http method.", + "", []string{"code", "method"}, nil, ), }) diff --git a/prometheus/gauge.go b/prometheus/gauge.go index dd2eac940..f643509bc 100644 --- a/prometheus/gauge.go +++ b/prometheus/gauge.go @@ -79,6 +79,7 @@ func NewGauge(opts GaugeOpts) Gauge { desc := NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ) @@ -161,6 +162,7 @@ func (v2) NewGaugeVec(opts GaugeVecOpts) *GaugeVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, opts.VariableLabels, opts.ConstLabels, ) @@ -305,6 +307,7 @@ func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc { return newValueFunc(NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ), GaugeValue, function) diff --git a/prometheus/gauge_test.go b/prometheus/gauge_test.go index 26759fbbc..3e2285b7c 100644 --- a/prometheus/gauge_test.go +++ b/prometheus/gauge_test.go @@ -171,7 +171,7 @@ func TestGaugeFunc(t *testing.T) { func() float64 { return 3.1415 }, ) - if expected, got := `Desc{fqName: "test_name", help: "test help", constLabels: {a="1",b="2"}, variableLabels: {}}`, gf.Desc().String(); expected != got { + if expected, got := `Desc{fqName: "test_name", help: "test help", unit: "", constLabels: {a="1",b="2"}, variableLabels: {}}`, gf.Desc().String(); expected != got { t.Errorf("expected %q, got %q", expected, got) } diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index ad9a71a5e..000842aa1 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -29,6 +29,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("alloc_bytes"), "Number of bytes allocated and still in use.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Alloc) }, @@ -37,6 +38,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("alloc_bytes_total"), "Total number of bytes allocated, even if freed.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.TotalAlloc) }, @@ -45,6 +47,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("sys_bytes"), "Number of bytes obtained from system.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Sys) }, @@ -53,6 +56,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("lookups_total"), "Total number of pointer lookups.", + "", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Lookups) }, @@ -61,6 +65,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mallocs_total"), "Total number of mallocs.", + "", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Mallocs) }, @@ -69,6 +74,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("frees_total"), "Total number of frees.", + "", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Frees) }, @@ -77,6 +83,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_alloc_bytes"), "Number of heap bytes allocated and still in use.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapAlloc) }, @@ -85,6 +92,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_sys_bytes"), "Number of heap bytes obtained from system.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapSys) }, @@ -93,6 +101,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_idle_bytes"), "Number of heap bytes waiting to be used.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapIdle) }, @@ -101,6 +110,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_inuse_bytes"), "Number of heap bytes that are in use.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapInuse) }, @@ -109,6 +119,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_released_bytes"), "Number of heap bytes released to OS.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapReleased) }, @@ -117,6 +128,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_objects"), "Number of allocated objects.", + "", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapObjects) }, @@ -125,6 +137,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("stack_inuse_bytes"), "Number of bytes in use by the stack allocator.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackInuse) }, @@ -133,6 +146,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("stack_sys_bytes"), "Number of bytes obtained from system for stack allocator.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackSys) }, @@ -141,6 +155,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mspan_inuse_bytes"), "Number of bytes in use by mspan structures.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanInuse) }, @@ -149,6 +164,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mspan_sys_bytes"), "Number of bytes used for mspan structures obtained from system.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanSys) }, @@ -157,6 +173,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mcache_inuse_bytes"), "Number of bytes in use by mcache structures.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheInuse) }, @@ -165,6 +182,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mcache_sys_bytes"), "Number of bytes used for mcache structures obtained from system.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheSys) }, @@ -173,6 +191,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("buck_hash_sys_bytes"), "Number of bytes used by the profiling bucket hash table.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.BuckHashSys) }, @@ -181,6 +200,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("gc_sys_bytes"), "Number of bytes used for garbage collection system metadata.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.GCSys) }, @@ -189,6 +209,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("other_sys_bytes"), "Number of bytes used for other system allocations.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.OtherSys) }, @@ -197,6 +218,7 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("next_gc_bytes"), "Number of heap bytes when next garbage collection will take place.", + "bytes", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.NextGC) }, @@ -218,22 +240,27 @@ func newBaseGoCollector() baseGoCollector { goroutinesDesc: NewDesc( "go_goroutines", "Number of goroutines that currently exist.", + "", nil, nil), threadsDesc: NewDesc( "go_threads", "Number of OS threads created.", + "", nil, nil), gcDesc: NewDesc( "go_gc_duration_seconds", "A summary of the pause duration of garbage collection cycles.", + "seconds", nil, nil), gcLastTimeDesc: NewDesc( "go_memstats_last_gc_time_seconds", "Number of seconds since 1970 of last garbage collection.", + "seconds", nil, nil), goInfoDesc: NewDesc( "go_info", "Information about the Go environment.", + "", nil, Labels{"version": runtime.Version()}), } } diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 2d8d9f64f..ab4b34766 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -215,6 +215,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { NewDesc( BuildFQName(namespace, subsystem, name), d.Description.Description, + "", nil, nil, ), diff --git a/prometheus/histogram.go b/prometheus/histogram.go index b5c8bcb39..696ce1af7 100644 --- a/prometheus/histogram.go +++ b/prometheus/histogram.go @@ -372,6 +372,9 @@ type HistogramOpts struct { // string. Help string + // Unit provides the unit of this Histogram. + Unit string + // ConstLabels are used to attach fixed labels to this metric. Metrics // with the same fully-qualified name must have the same label names in // their ConstLabels. @@ -503,6 +506,7 @@ func NewHistogram(opts HistogramOpts) Histogram { NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ), @@ -1127,6 +1131,7 @@ func (v2) NewHistogramVec(opts HistogramVecOpts) *HistogramVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, opts.VariableLabels, opts.ConstLabels, ) diff --git a/prometheus/metric.go b/prometheus/metric.go index f018e5723..d24ac2395 100644 --- a/prometheus/metric.go +++ b/prometheus/metric.go @@ -81,6 +81,9 @@ type Opts struct { // string. Help string + // Unit provides the unit of this metric. + Unit string + // ConstLabels are used to attach fixed labels to this metric. Metrics // with the same fully-qualified name must have the same label names in // their ConstLabels. diff --git a/prometheus/metric_test.go b/prometheus/metric_test.go index 629aa4f84..8186567a5 100644 --- a/prometheus/metric_test.go +++ b/prometheus/metric_test.go @@ -45,7 +45,7 @@ func TestWithExemplarsMetric(t *testing.T) { t.Run("histogram", func(t *testing.T) { // Create a constant histogram from values we got from a 3rd party telemetry system. h := MustNewConstHistogram( - NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", nil, nil), + NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", "seconds", nil, nil), 4711, 403.34, // Four buckets, but we expect five as the +Inf bucket will be created if we see value outside of those buckets. map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233}, diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index 8548dd18e..97f28e18e 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -68,36 +68,43 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector { cpuTotal: NewDesc( ns+"process_cpu_seconds_total", "Total user and system CPU time spent in seconds.", + "seconds", nil, nil, ), openFDs: NewDesc( ns+"process_open_fds", "Number of open file descriptors.", + "", nil, nil, ), maxFDs: NewDesc( ns+"process_max_fds", "Maximum number of open file descriptors.", + "", nil, nil, ), vsize: NewDesc( ns+"process_virtual_memory_bytes", "Virtual memory size in bytes.", + "bytes", nil, nil, ), maxVsize: NewDesc( ns+"process_virtual_memory_max_bytes", "Maximum amount of virtual memory available in bytes.", + "bytes", nil, nil, ), rss: NewDesc( ns+"process_resident_memory_bytes", "Resident memory size in bytes.", + "bytes", nil, nil, ), startTime: NewDesc( ns+"process_start_time_seconds", "Start time of the process since unix epoch in seconds.", + "seconds", nil, nil, ), } diff --git a/prometheus/promhttp/http_test.go b/prometheus/promhttp/http_test.go index 8ca192748..726a5708d 100644 --- a/prometheus/promhttp/http_test.go +++ b/prometheus/promhttp/http_test.go @@ -32,12 +32,12 @@ import ( type errorCollector struct{} func (e errorCollector) Describe(ch chan<- *prometheus.Desc) { - ch <- prometheus.NewDesc("invalid_metric", "not helpful", nil, nil) + ch <- prometheus.NewDesc("invalid_metric", "not helpful", "", nil, nil) } func (e errorCollector) Collect(ch chan<- prometheus.Metric) { ch <- prometheus.NewInvalidMetric( - prometheus.NewDesc("invalid_metric", "not helpful", nil, nil), + prometheus.NewDesc("invalid_metric", "not helpful", "", nil, nil), errors.New("collect error"), ) } @@ -47,7 +47,7 @@ type blockingCollector struct { } func (b blockingCollector) Describe(ch chan<- *prometheus.Desc) { - ch <- prometheus.NewDesc("dummy_desc", "not helpful", nil, nil) + ch <- prometheus.NewDesc("dummy_desc", "not helpful", "", nil, nil) } func (b blockingCollector) Collect(ch chan<- prometheus.Metric) { @@ -128,11 +128,11 @@ func TestHandlerErrorHandling(t *testing.T) { t.Fatalf("unexpected number of done invokes, want 0, got %d", got) } - wantMsg := `error gathering metrics: error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", constLabels: {}, variableLabels: {}}: collect error + wantMsg := `error gathering metrics: error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", unit: "", constLabels: {}, variableLabels: {}}: collect error ` wantErrorBody := `An error has occurred while serving metrics: -error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", constLabels: {}, variableLabels: {}}: collect error +error collecting metric Desc{fqName: "invalid_metric", help: "not helpful", unit: "", constLabels: {}, variableLabels: {}}: collect error ` wantOKBody1 := `# HELP name docstring # TYPE name counter diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index dca36fe58..415972185 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -1309,7 +1309,7 @@ func TestCheckMetricConsistency(t *testing.T) { reg := prometheus.NewRegistry() timestamp := time.Now() - desc := prometheus.NewDesc("metric_a", "", nil, nil) + desc := prometheus.NewDesc("metric_a", "", "", nil, nil) metric := prometheus.MustNewConstMetric(desc, prometheus.CounterValue, 1) validCollector := &customCollector{ diff --git a/prometheus/summary.go b/prometheus/summary.go index 146270444..c9259008e 100644 --- a/prometheus/summary.go +++ b/prometheus/summary.go @@ -101,6 +101,9 @@ type SummaryOpts struct { // string. Help string + // Unit provides the unit of this Summary. + Unit string + // ConstLabels are used to attach fixed labels to this metric. Metrics // with the same fully-qualified name must have the same label names in // their ConstLabels. @@ -184,6 +187,7 @@ func NewSummary(opts SummaryOpts) Summary { NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ), @@ -573,6 +577,7 @@ func (v2) NewSummaryVec(opts SummaryVecOpts) *SummaryVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, opts.VariableLabels, opts.ConstLabels, ) diff --git a/prometheus/testutil/testutil_test.go b/prometheus/testutil/testutil_test.go index f2e1cbaff..70c33561c 100644 --- a/prometheus/testutil/testutil_test.go +++ b/prometheus/testutil/testutil_test.go @@ -26,12 +26,12 @@ import ( type untypedCollector struct{} func (u untypedCollector) Describe(c chan<- *prometheus.Desc) { - c <- prometheus.NewDesc("name", "help", nil, nil) + c <- prometheus.NewDesc("name", "help", "", nil, nil) } func (u untypedCollector) Collect(c chan<- prometheus.Metric) { c <- prometheus.MustNewConstMetric( - prometheus.NewDesc("name", "help", nil, nil), + prometheus.NewDesc("name", "help", "", nil, nil), prometheus.UntypedValue, 2001, ) diff --git a/prometheus/untyped.go b/prometheus/untyped.go index 0f9ce63f4..c9ea7d4bb 100644 --- a/prometheus/untyped.go +++ b/prometheus/untyped.go @@ -36,6 +36,7 @@ func NewUntypedFunc(opts UntypedOpts, function func() float64) UntypedFunc { return newValueFunc(NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, + opts.Unit, nil, opts.ConstLabels, ), UntypedValue, function) diff --git a/prometheus/value_test.go b/prometheus/value_test.go index 004c3bb35..53d213faf 100644 --- a/prometheus/value_test.go +++ b/prometheus/value_test.go @@ -45,6 +45,7 @@ func TestNewConstMetricInvalidLabelValues(t *testing.T) { metricDesc := NewDesc( "sample_value", "sample value", + "", []string{"a"}, Labels{}, ) @@ -88,6 +89,7 @@ func TestNewConstMetricWithCreatedTimestamp(t *testing.T) { metricDesc := NewDesc( "sample_value", "sample value", + "", nil, nil, ) diff --git a/prometheus/wrap.go b/prometheus/wrap.go index 25da157f1..fb9a38861 100644 --- a/prometheus/wrap.go +++ b/prometheus/wrap.go @@ -196,6 +196,7 @@ func wrapDesc(desc *Desc, prefix string, labels Labels) *Desc { return &Desc{ fqName: desc.fqName, help: desc.help, + unit: desc.unit, variableLabels: desc.variableLabels, constLabelPairs: desc.constLabelPairs, err: fmt.Errorf("attempted wrapping with already existing label name %q", ln), @@ -204,7 +205,7 @@ func wrapDesc(desc *Desc, prefix string, labels Labels) *Desc { constLabels[ln] = lv } // NewDesc will do remaining validations. - newDesc := V2.NewDesc(prefix+desc.fqName, desc.help, desc.variableLabels, constLabels) + newDesc := V2.NewDesc(prefix+desc.fqName, desc.help, desc.unit, desc.variableLabels, constLabels) // Propagate errors if there was any. This will override any errer // created by NewDesc above, i.e. earlier errors get precedence. if desc.err != nil { From 5d8c6deab9dc78b9846ef60e6f741983c30a00ce Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 30 Nov 2023 14:47:38 +0100 Subject: [PATCH 02/27] do not assume units for now Signed-off-by: Arianna Vespri --- prometheus/example_clustermanager_test.go | 2 +- prometheus/examples_test.go | 10 +++++----- prometheus/metric_test.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/prometheus/example_clustermanager_test.go b/prometheus/example_clustermanager_test.go index b995677fa..3dd2acd4d 100644 --- a/prometheus/example_clustermanager_test.go +++ b/prometheus/example_clustermanager_test.go @@ -72,7 +72,7 @@ var ( ramUsageDesc = prometheus.NewDesc( "clustermanager_ram_usage_bytes", "RAM usage as reported to the cluster manager.", - "bytes", + "", []string{"host"}, nil, ) ) diff --git a/prometheus/examples_test.go b/prometheus/examples_test.go index c4c06851b..dc4115181 100644 --- a/prometheus/examples_test.go +++ b/prometheus/examples_test.go @@ -382,7 +382,7 @@ func ExampleNewConstSummary() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A summary of the HTTP request durations.", - "seconds", + "", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -434,7 +434,7 @@ func ExampleNewConstHistogram() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", - "seconds", + "", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -462,7 +462,7 @@ func ExampleNewConstHistogram_WithExemplar() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", - "seconds", + "", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -633,7 +633,7 @@ func ExampleNewMetricWithTimestamp() { desc := prometheus.NewDesc( "temperature_kelvin", "Current temperature in Kelvin.", - "kelvin", + "", nil, nil, ) @@ -667,7 +667,7 @@ func ExampleNewConstMetricWithCreatedTimestamp() { desc := prometheus.NewDesc( "time_since_epoch_seconds", "Current epoch time in seconds.", - "seconds", + "", nil, nil, ) diff --git a/prometheus/metric_test.go b/prometheus/metric_test.go index 8186567a5..75e81751c 100644 --- a/prometheus/metric_test.go +++ b/prometheus/metric_test.go @@ -45,7 +45,7 @@ func TestWithExemplarsMetric(t *testing.T) { t.Run("histogram", func(t *testing.T) { // Create a constant histogram from values we got from a 3rd party telemetry system. h := MustNewConstHistogram( - NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", "seconds", nil, nil), + NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", "", nil, nil), 4711, 403.34, // Four buckets, but we expect five as the +Inf bucket will be created if we see value outside of those buckets. map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233}, From f78b6669bdfa1def26ecb5af1b652e4e164ea4d9 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 30 Nov 2023 16:48:25 +0100 Subject: [PATCH 03/27] again, do not assume units Signed-off-by: Arianna Vespri --- prometheus/process_collector.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index 97f28e18e..706a66bf4 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -68,7 +68,7 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector { cpuTotal: NewDesc( ns+"process_cpu_seconds_total", "Total user and system CPU time spent in seconds.", - "seconds", + "", nil, nil, ), openFDs: NewDesc( @@ -86,25 +86,25 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector { vsize: NewDesc( ns+"process_virtual_memory_bytes", "Virtual memory size in bytes.", - "bytes", + "", nil, nil, ), maxVsize: NewDesc( ns+"process_virtual_memory_max_bytes", "Maximum amount of virtual memory available in bytes.", - "bytes", + "", nil, nil, ), rss: NewDesc( ns+"process_resident_memory_bytes", "Resident memory size in bytes.", - "bytes", + "", nil, nil, ), startTime: NewDesc( ns+"process_start_time_seconds", "Start time of the process since unix epoch in seconds.", - "seconds", + "", nil, nil, ), } From e876012f273b8b5b4bbc1f040a20dd547b4f50b8 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sat, 2 Dec 2023 15:43:15 +0100 Subject: [PATCH 04/27] assume the units Signed-off-by: Arianna Vespri --- prometheus/go_collector_latest.go | 3 ++- prometheus/process_collector.go | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index ab4b34766..3ff6e97f2 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -215,7 +215,8 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { NewDesc( BuildFQName(namespace, subsystem, name), d.Description.Description, - "", + // TODO(vesari): can we assume that this is a suitable unit? + unit, nil, nil, ), diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index 706a66bf4..97f28e18e 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -68,7 +68,7 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector { cpuTotal: NewDesc( ns+"process_cpu_seconds_total", "Total user and system CPU time spent in seconds.", - "", + "seconds", nil, nil, ), openFDs: NewDesc( @@ -86,25 +86,25 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector { vsize: NewDesc( ns+"process_virtual_memory_bytes", "Virtual memory size in bytes.", - "", + "bytes", nil, nil, ), maxVsize: NewDesc( ns+"process_virtual_memory_max_bytes", "Maximum amount of virtual memory available in bytes.", - "", + "bytes", nil, nil, ), rss: NewDesc( ns+"process_resident_memory_bytes", "Resident memory size in bytes.", - "", + "bytes", nil, nil, ), startTime: NewDesc( ns+"process_start_time_seconds", "Start time of the process since unix epoch in seconds.", - "", + "seconds", nil, nil, ), } From b1f5a86103385f33a99d88bc69ee7ae67c3f11e4 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sat, 2 Dec 2023 16:03:01 +0100 Subject: [PATCH 05/27] add units in more places Signed-off-by: Arianna Vespri --- examples/exemplars/main.go | 1 + examples/random/main.go | 2 ++ prometheus/example_clustermanager_test.go | 2 +- prometheus/examples_test.go | 13 +++++++------ prometheus/metric_test.go | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/exemplars/main.go b/examples/exemplars/main.go index 798c2dfd0..2b6941253 100644 --- a/examples/exemplars/main.go +++ b/examples/exemplars/main.go @@ -32,6 +32,7 @@ func main() { requestDurations := prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "http_request_duration_seconds", Help: "A histogram of the HTTP request durations in seconds.", + Unit: "seconds", Buckets: prometheus.ExponentialBuckets(0.1, 1.5, 5), }) diff --git a/examples/random/main.go b/examples/random/main.go index b4f6280c7..6cd6f056c 100644 --- a/examples/random/main.go +++ b/examples/random/main.go @@ -44,6 +44,7 @@ func NewMetrics(reg prometheus.Registerer, normMean, normDomain float64) *metric prometheus.SummaryOpts{ Name: "rpc_durations_seconds", Help: "RPC latency distributions.", + Unit: "seconds", Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, }, []string{"service"}, @@ -62,6 +63,7 @@ func NewMetrics(reg prometheus.Registerer, normMean, normDomain float64) *metric rpcDurationsHistogram: prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "rpc_durations_histogram_seconds", Help: "RPC latency distributions.", + Unit: "seconds", Buckets: prometheus.LinearBuckets(normMean-5*normDomain, .5*normDomain, 20), NativeHistogramBucketFactor: 1.1, }), diff --git a/prometheus/example_clustermanager_test.go b/prometheus/example_clustermanager_test.go index 3dd2acd4d..b995677fa 100644 --- a/prometheus/example_clustermanager_test.go +++ b/prometheus/example_clustermanager_test.go @@ -72,7 +72,7 @@ var ( ramUsageDesc = prometheus.NewDesc( "clustermanager_ram_usage_bytes", "RAM usage as reported to the cluster manager.", - "", + "bytes", []string{"host"}, nil, ) ) diff --git a/prometheus/examples_test.go b/prometheus/examples_test.go index dc4115181..bdaaff303 100644 --- a/prometheus/examples_test.go +++ b/prometheus/examples_test.go @@ -382,7 +382,7 @@ func ExampleNewConstSummary() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A summary of the HTTP request durations.", - "", + "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -410,7 +410,8 @@ func ExampleHistogram() { temps := prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "pond_temperature_celsius", Help: "The temperature of the frog pond.", // Sorry, we can't measure how badly it smells. - Buckets: prometheus.LinearBuckets(20, 5, 5), // 5 buckets, each 5 centigrade wide. + Unit: "celsius", + Buckets: prometheus.LinearBuckets(20, 5, 5), // 5 buckets, each 5 centigrade wide. }) // Simulate some observations. @@ -434,7 +435,7 @@ func ExampleNewConstHistogram() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", - "", + "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -462,7 +463,7 @@ func ExampleNewConstHistogram_WithExemplar() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", - "", + "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, ) @@ -633,7 +634,7 @@ func ExampleNewMetricWithTimestamp() { desc := prometheus.NewDesc( "temperature_kelvin", "Current temperature in Kelvin.", - "", + "kelvin", nil, nil, ) @@ -667,7 +668,7 @@ func ExampleNewConstMetricWithCreatedTimestamp() { desc := prometheus.NewDesc( "time_since_epoch_seconds", "Current epoch time in seconds.", - "", + "seconds", nil, nil, ) diff --git a/prometheus/metric_test.go b/prometheus/metric_test.go index 75e81751c..8186567a5 100644 --- a/prometheus/metric_test.go +++ b/prometheus/metric_test.go @@ -45,7 +45,7 @@ func TestWithExemplarsMetric(t *testing.T) { t.Run("histogram", func(t *testing.T) { // Create a constant histogram from values we got from a 3rd party telemetry system. h := MustNewConstHistogram( - NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", "", nil, nil), + NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", "seconds", nil, nil), 4711, 403.34, // Four buckets, but we expect five as the +Inf bucket will be created if we see value outside of those buckets. map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233}, From 788d53bf3ea78e739ccb0e291468bfc8b477f57c Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sat, 2 Dec 2023 17:02:40 +0100 Subject: [PATCH 06/27] fix dependencies in go.mod Signed-off-by: Arianna Vespri --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 88ae88504..2b8a702fe 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/prometheus/client_model v0.5.0 github.com/prometheus/common v0.45.0 github.com/prometheus/procfs v0.12.0 - golang.org/x/sys v0.13.0 + golang.org/x/sys v0.14.0 google.golang.org/protobuf v1.31.0 ) @@ -22,15 +22,15 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/oauth2 v0.12.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) exclude github.com/prometheus/client_golang v1.12.1 -replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20231121140958-784d3aad4c30 +replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20231202155551-b16280ec87cf -replace github.com/prometheus/client_model => github.com/vesari/client_model v0.0.0-20231118150741-19723af61627 +replace github.com/prometheus/client_model => github.com/vesari/client_model v0.0.0-20231202151802-003f160da988 diff --git a/go.sum b/go.sum index c8f442a49..067bbc676 100644 --- a/go.sum +++ b/go.sum @@ -40,23 +40,23 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/vesari/client_model v0.0.0-20231118150741-19723af61627 h1:pJsecGZFkJIN3ipp7fS8hLDK0Dcnk2JVxXds3Dev3dQ= -github.com/vesari/client_model v0.0.0-20231118150741-19723af61627/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/vesari/common v0.0.0-20231121140958-784d3aad4c30 h1:WaoSRlUM9CilXfZwJ5WIsFJKLnwJ6/WZjyT1oiiRO7s= -github.com/vesari/common v0.0.0-20231121140958-784d3aad4c30/go.mod h1:F2CatmaM24xsPNg4EqskJKMF+Tl27WbRF+Exgus+vOw= +github.com/vesari/client_model v0.0.0-20231202151802-003f160da988 h1:uGmTMMEergUEb2pEH90ZLVSBGvDqN16P12UsBjEQp0Y= +github.com/vesari/client_model v0.0.0-20231202151802-003f160da988/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/vesari/common v0.0.0-20231202155551-b16280ec87cf h1:sYE4ThdyfiELu0vhvbL0Ul40rXnmOYYd+YputPO1g+o= +github.com/vesari/common v0.0.0-20231202155551-b16280ec87cf/go.mod h1:1yNdKjOnjEPZHRFHLVcTU6L+APxLWQMQstMukA7axAM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= -golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= From 5971215a64f2e852808c115155fdf3bc928da0ba Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sat, 20 Jan 2024 13:42:13 +0100 Subject: [PATCH 07/27] Update version of common in go.mod Signed-off-by: Arianna Vespri --- go.mod | 6 ++---- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index d4ec44de1..ae96e8337 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 github.com/davecgh/go-spew v1.1.1 github.com/json-iterator/go v1.1.12 - github.com/prometheus/client_model v0.5.0 + github.com/prometheus/client_model v0.5.1-0.20231205151710-c26a8eea9e44 github.com/prometheus/common v0.46.0 github.com/prometheus/procfs v0.12.0 golang.org/x/sys v0.16.0 @@ -30,6 +30,4 @@ require ( exclude github.com/prometheus/client_golang v1.12.1 -replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20231202155551-b16280ec87cf - -replace github.com/prometheus/client_model => github.com/vesari/client_model v0.0.0-20231202151802-003f160da988 +replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20240116093321-6b0e211556c7 diff --git a/go.sum b/go.sum index b52aac156..e6f5b6e3e 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.5.1-0.20231205151710-c26a8eea9e44 h1:SQMgsr70ptWRWXsEsydAwKiRaomBk/Cfsv1BSNCNM3Y= +github.com/prometheus/client_model v0.5.1-0.20231205151710-c26a8eea9e44/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -38,10 +40,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/vesari/client_model v0.0.0-20231202151802-003f160da988 h1:uGmTMMEergUEb2pEH90ZLVSBGvDqN16P12UsBjEQp0Y= -github.com/vesari/client_model v0.0.0-20231202151802-003f160da988/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/vesari/common v0.0.0-20231202155551-b16280ec87cf h1:sYE4ThdyfiELu0vhvbL0Ul40rXnmOYYd+YputPO1g+o= -github.com/vesari/common v0.0.0-20231202155551-b16280ec87cf/go.mod h1:1yNdKjOnjEPZHRFHLVcTU6L+APxLWQMQstMukA7axAM= +github.com/vesari/common v0.0.0-20240116093321-6b0e211556c7 h1:faLDyUG5gJL5hs5DxiF7gWGZ+BMp/JZjOix2SZRx074= +github.com/vesari/common v0.0.0-20240116093321-6b0e211556c7/go.mod h1:Zoj+isvSAUD7ZoNxOaI614zZ9ci29ei8YEeRIRDAtBc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= From efb64f3d00472d6cd649d08e6fa71dd5a54c43be Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sat, 27 Jan 2024 12:22:59 +0100 Subject: [PATCH 08/27] Start modifying handler Signed-off-by: Arianna Vespri --- go.mod | 2 +- go.sum | 4 ++-- prometheus/promhttp/http.go | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index ae96e8337..a030754d2 100644 --- a/go.mod +++ b/go.mod @@ -30,4 +30,4 @@ require ( exclude github.com/prometheus/client_golang v1.12.1 -replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20240116093321-6b0e211556c7 +replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20240125095408-46862a5fd9d9 diff --git a/go.sum b/go.sum index e6f5b6e3e..5b870ce49 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/vesari/common v0.0.0-20240116093321-6b0e211556c7 h1:faLDyUG5gJL5hs5DxiF7gWGZ+BMp/JZjOix2SZRx074= -github.com/vesari/common v0.0.0-20240116093321-6b0e211556c7/go.mod h1:Zoj+isvSAUD7ZoNxOaI614zZ9ci29ei8YEeRIRDAtBc= +github.com/vesari/common v0.0.0-20240125095408-46862a5fd9d9 h1:FuTWd2KvOZGizulFqShjLLvd8HJdeF7IaRAp27YvVPY= +github.com/vesari/common v0.0.0-20240125095408-46862a5fd9d9/go.mod h1:Zoj+isvSAUD7ZoNxOaI614zZ9ci29ei8YEeRIRDAtBc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 09b8d2fbe..7cd33dcff 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -180,7 +180,11 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO w = gz } - enc := expfmt.NewEncoder(w, contentType) + OMopts := []expfmt.ToOpenMetricsOption{} + if opts.EnableOpenMetrics && opts.WithUnit { + OMopts = append(OMopts, expfmt.ToOpenMetricsWithUnit()) + } + enc := expfmt.NewEncoder(w, contentType, OMopts...) // handleError handles the error according to opts.ErrorHandling // and returns true if we have to abort after the handling. @@ -379,6 +383,8 @@ type HandlerOpts struct { // NOTE: This feature is experimental and not covered by OpenMetrics or Prometheus // exposition format. ProcessStartTime time.Time + // WithUnit: if true.... TODO: explain what it implies + WithUnit bool } // gzipAccepted returns whether the client will accept gzip-encoded content. From 51861d55076e626dd7cd4e12f458c923eff800ae Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 7 Mar 2024 10:13:00 +0100 Subject: [PATCH 09/27] Use different common Signed-off-by: Arianna Vespri --- go.mod | 2 +- go.sum | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index a030754d2..a4a0114a0 100644 --- a/go.mod +++ b/go.mod @@ -30,4 +30,4 @@ require ( exclude github.com/prometheus/client_golang v1.12.1 -replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20240125095408-46862a5fd9d9 +replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20240213112139-1755cb64f14c diff --git a/go.sum b/go.sum index 5b870ce49..46848074c 100644 --- a/go.sum +++ b/go.sum @@ -11,7 +11,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -40,8 +40,8 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/vesari/common v0.0.0-20240125095408-46862a5fd9d9 h1:FuTWd2KvOZGizulFqShjLLvd8HJdeF7IaRAp27YvVPY= -github.com/vesari/common v0.0.0-20240125095408-46862a5fd9d9/go.mod h1:Zoj+isvSAUD7ZoNxOaI614zZ9ci29ei8YEeRIRDAtBc= +github.com/vesari/common v0.0.0-20240213112139-1755cb64f14c h1:2iQpIuYBGrinOMj+N6eqnNpluNTIFcqYAfeR06HscbE= +github.com/vesari/common v0.0.0-20240213112139-1755cb64f14c/go.mod h1:i+3zs2+M/Vol8+pL8tTrLna3I66qWt8zxcEVFxBMLZI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= From a2bfd3a708f4b9b100dd9067ebacf19a60955600 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 14 Mar 2024 09:31:35 +0100 Subject: [PATCH 10/27] Use the newly named func for OM encoding Signed-off-by: Arianna Vespri --- go.mod | 16 ++++++++-------- go.sum | 23 +++++++++++++---------- prometheus/promhttp/http.go | 4 ++-- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 5bdb3d7dc..f6ce2ef26 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/prometheus/client_golang -go 1.20 +go 1.21 + +toolchain go1.22.0 require ( github.com/beorn7/perks v1.0.1 @@ -8,10 +10,10 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/json-iterator/go v1.1.12 github.com/prometheus/client_model v0.6.0 - github.com/prometheus/common v0.48.0 + github.com/prometheus/common v0.50.0 github.com/prometheus/procfs v0.12.0 - golang.org/x/sys v0.17.0 - google.golang.org/protobuf v1.32.0 + golang.org/x/sys v0.18.0 + google.golang.org/protobuf v1.33.0 ) require ( @@ -21,13 +23,11 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/oauth2 v0.16.0 // indirect + golang.org/x/net v0.22.0 // indirect + golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) exclude github.com/prometheus/client_golang v1.12.1 - -replace github.com/prometheus/common => github.com/vesari/common v0.0.0-20240213112139-1755cb64f14c diff --git a/go.sum b/go.sum index d3c71ff72..dc38af74c 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -33,24 +34,25 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= -github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= +github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ= +github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= -golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= +golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= @@ -61,9 +63,10 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6 google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 7cd33dcff..bfe82b82a 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -180,9 +180,9 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO w = gz } - OMopts := []expfmt.ToOpenMetricsOption{} + OMopts := []expfmt.EncoderOption{} if opts.EnableOpenMetrics && opts.WithUnit { - OMopts = append(OMopts, expfmt.ToOpenMetricsWithUnit()) + OMopts = append(OMopts, expfmt.WithUnit()) } enc := expfmt.NewEncoder(w, contentType, OMopts...) From 19d710270bc1fc603fe8c0d1382a396947ad5e95 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 14 Mar 2024 14:28:51 +0100 Subject: [PATCH 11/27] Fix examples and comments Signed-off-by: Arianna Vespri --- examples/exemplars/main.go | 1 + examples/random/main.go | 2 -- prometheus/go_collector_latest.go | 2 +- prometheus/promhttp/http.go | 13 +++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/exemplars/main.go b/examples/exemplars/main.go index 2b6941253..8a841ee13 100644 --- a/examples/exemplars/main.go +++ b/examples/exemplars/main.go @@ -63,6 +63,7 @@ func main() { registry, promhttp.HandlerOpts{ EnableOpenMetrics: true, + WithUnit: true, }), ) // To test: curl -H 'Accept: application/openmetrics-text' localhost:8080/metrics diff --git a/examples/random/main.go b/examples/random/main.go index 6cd6f056c..b4f6280c7 100644 --- a/examples/random/main.go +++ b/examples/random/main.go @@ -44,7 +44,6 @@ func NewMetrics(reg prometheus.Registerer, normMean, normDomain float64) *metric prometheus.SummaryOpts{ Name: "rpc_durations_seconds", Help: "RPC latency distributions.", - Unit: "seconds", Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, }, []string{"service"}, @@ -63,7 +62,6 @@ func NewMetrics(reg prometheus.Registerer, normMean, normDomain float64) *metric rpcDurationsHistogram: prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "rpc_durations_histogram_seconds", Help: "RPC latency distributions.", - Unit: "seconds", Buckets: prometheus.LinearBuckets(normMean-5*normDomain, .5*normDomain, 20), NativeHistogramBucketFactor: 1.1, }), diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 3ff6e97f2..e1baba368 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -215,7 +215,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { NewDesc( BuildFQName(namespace, subsystem, name), d.Description.Description, - // TODO(vesari): can we assume that this is a suitable unit? + // Can we assume that this is a suitable unit? unit, nil, nil, diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index bfe82b82a..678a0e2db 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -160,8 +160,12 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO } var contentType expfmt.Format + var encoderOpts []expfmt.EncoderOption if opts.EnableOpenMetrics { contentType = expfmt.NegotiateIncludingOpenMetrics(req.Header) + if opts.WithUnit { + encoderOpts = append(encoderOpts, expfmt.WithUnit()) + } } else { contentType = expfmt.Negotiate(req.Header) } @@ -180,11 +184,7 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO w = gz } - OMopts := []expfmt.EncoderOption{} - if opts.EnableOpenMetrics && opts.WithUnit { - OMopts = append(OMopts, expfmt.WithUnit()) - } - enc := expfmt.NewEncoder(w, contentType, OMopts...) + enc := expfmt.NewEncoder(w, contentType, encoderOpts...) // handleError handles the error according to opts.ErrorHandling // and returns true if we have to abort after the handling. @@ -383,7 +383,8 @@ type HandlerOpts struct { // NOTE: This feature is experimental and not covered by OpenMetrics or Prometheus // exposition format. ProcessStartTime time.Time - // WithUnit: if true.... TODO: explain what it implies + // If true, WithUnit adds the unit to the encoder options, ultimately allowing the + // unit into the final output, provided that EnableOpenMetrics is also true. WithUnit bool } From 031e0d358bc0355a7dc734b0172dc70e774e00af Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 14 Mar 2024 14:34:34 +0100 Subject: [PATCH 12/27] Fix go.mod Signed-off-by: Arianna Vespri --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index f6ce2ef26..1c32a62ae 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/prometheus/client_golang go 1.21 -toolchain go1.22.0 - require ( github.com/beorn7/perks v1.0.1 github.com/cespare/xxhash/v2 v2.2.0 From fd60a57eb4d652a1ae80c997866f6823f42ca762 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 14 Mar 2024 14:44:37 +0100 Subject: [PATCH 13/27] Adapt go.mod as much as possible Signed-off-by: Arianna Vespri --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index 1c32a62ae..f6ce2ef26 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/prometheus/client_golang go 1.21 +toolchain go1.22.0 + require ( github.com/beorn7/perks v1.0.1 github.com/cespare/xxhash/v2 v2.2.0 From f7e28488e44c61e53f18944a0dc8c9b1b8ea4b5b Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 15 Mar 2024 13:33:49 +0100 Subject: [PATCH 14/27] Use go 1.20 Signed-off-by: Arianna Vespri --- go.mod | 4 +--- go.sum | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f6ce2ef26..08367da77 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/prometheus/client_golang -go 1.21 - -toolchain go1.22.0 +go 1.20 require ( github.com/beorn7/perks v1.0.1 diff --git a/go.sum b/go.sum index dc38af74c..0f4f04136 100644 --- a/go.sum +++ b/go.sum @@ -12,7 +12,6 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -40,7 +39,6 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -67,6 +65,5 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= From 5f589961890e21809c3cc666c83f01fdade57f9e Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 15 Mar 2024 13:43:08 +0100 Subject: [PATCH 15/27] Use go 1.21 Signed-off-by: Arianna Vespri --- go.mod | 2 +- go.sum | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 08367da77..1c32a62ae 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/prometheus/client_golang -go 1.20 +go 1.21 require ( github.com/beorn7/perks v1.0.1 diff --git a/go.sum b/go.sum index 0f4f04136..dc38af74c 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -39,6 +40,7 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -65,5 +67,6 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= From ac9d1d8ed9a48bd498b59ad43a0275a2a287a2ea Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 15 Mar 2024 13:47:20 +0100 Subject: [PATCH 16/27] Upgrade github workflows to go 1.21 needed for common Signed-off-by: Arianna Vespri --- .github/workflows/go.yml | 2 +- .github/workflows/golangci-lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c72b96cc7..8af9be65a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: - go_version: ["1.20", "1.21", "1.22"] + go_version: ["1.21", "1.22"] steps: - name: Checkout code diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 09bf7e8a8..acf38e6fe 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -28,7 +28,7 @@ jobs: - name: install Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: - go-version: 1.20.x + go-version: 1.21.x - name: Install snmp_exporter/generator dependencies run: sudo apt-get update && sudo apt-get -y install libsnmp-dev if: github.repository == 'prometheus/snmp_exporter' From 3db440e1796a38b2511192378ff7358727b849fc Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 15 Mar 2024 13:55:09 +0100 Subject: [PATCH 17/27] Delete test funcs which are unused according to lint Signed-off-by: Arianna Vespri --- .../collectors/go_collector_go121_test.go | 23 -------------- .../collectors/go_collector_go122_test.go | 30 ------------------- 2 files changed, 53 deletions(-) diff --git a/prometheus/collectors/go_collector_go121_test.go b/prometheus/collectors/go_collector_go121_test.go index 6facf6798..07687b7c7 100644 --- a/prometheus/collectors/go_collector_go121_test.go +++ b/prometheus/collectors/go_collector_go121_test.go @@ -149,26 +149,3 @@ func withSchedulerMetrics() []string { "go_threads", } } - -func withDebugMetrics() []string { - return []string{ - "go_godebug_non_default_behavior_execerrdot_events_total", - "go_godebug_non_default_behavior_gocachehash_events_total", - "go_godebug_non_default_behavior_gocachetest_events_total", - "go_godebug_non_default_behavior_gocacheverify_events_total", - "go_godebug_non_default_behavior_http2client_events_total", - "go_godebug_non_default_behavior_http2server_events_total", - "go_godebug_non_default_behavior_installgoroot_events_total", - "go_godebug_non_default_behavior_jstmpllitinterp_events_total", - "go_godebug_non_default_behavior_multipartmaxheaders_events_total", - "go_godebug_non_default_behavior_multipartmaxparts_events_total", - "go_godebug_non_default_behavior_multipathtcp_events_total", - "go_godebug_non_default_behavior_panicnil_events_total", - "go_godebug_non_default_behavior_randautoseed_events_total", - "go_godebug_non_default_behavior_tarinsecurepath_events_total", - "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", - "go_godebug_non_default_behavior_x509sha1_events_total", - "go_godebug_non_default_behavior_x509usefallbackroots_events_total", - "go_godebug_non_default_behavior_zipinsecurepath_events_total", - } -} diff --git a/prometheus/collectors/go_collector_go122_test.go b/prometheus/collectors/go_collector_go122_test.go index 0b3c37adf..4e578b84f 100644 --- a/prometheus/collectors/go_collector_go122_test.go +++ b/prometheus/collectors/go_collector_go122_test.go @@ -164,33 +164,3 @@ func withSchedulerMetrics() []string { "go_threads", } } - -func withDebugMetrics() []string { - return []string{ - "go_godebug_non_default_behavior_execerrdot_events_total", - "go_godebug_non_default_behavior_gocachehash_events_total", - "go_godebug_non_default_behavior_gocachetest_events_total", - "go_godebug_non_default_behavior_gocacheverify_events_total", - "go_godebug_non_default_behavior_gotypesalias_events_total", - "go_godebug_non_default_behavior_http2client_events_total", - "go_godebug_non_default_behavior_http2server_events_total", - "go_godebug_non_default_behavior_httplaxcontentlength_events_total", - "go_godebug_non_default_behavior_httpmuxgo121_events_total", - "go_godebug_non_default_behavior_installgoroot_events_total", - "go_godebug_non_default_behavior_jstmpllitinterp_events_total", - "go_godebug_non_default_behavior_multipartmaxheaders_events_total", - "go_godebug_non_default_behavior_multipartmaxparts_events_total", - "go_godebug_non_default_behavior_multipathtcp_events_total", - "go_godebug_non_default_behavior_panicnil_events_total", - "go_godebug_non_default_behavior_randautoseed_events_total", - "go_godebug_non_default_behavior_tarinsecurepath_events_total", - "go_godebug_non_default_behavior_tls10server_events_total", - "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", - "go_godebug_non_default_behavior_tlsrsakex_events_total", - "go_godebug_non_default_behavior_tlsunsafeekm_events_total", - "go_godebug_non_default_behavior_x509sha1_events_total", - "go_godebug_non_default_behavior_x509usefallbackroots_events_total", - "go_godebug_non_default_behavior_x509usepolicies_events_total", - "go_godebug_non_default_behavior_zipinsecurepath_events_total", - } -} From 7752d37a0480687c16a7bf882540a93ee3acd405 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 15 Mar 2024 14:18:50 +0100 Subject: [PATCH 18/27] Upgrade to Go 1.21 in Makefile and workflows for tests Signed-off-by: Arianna Vespri --- .github/workflows/go.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8af9be65a..02321966f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -42,5 +42,5 @@ jobs: CI: true - name: Run style and unused - if: ${{ matrix.go_version == '1.20' }} + if: ${{ matrix.go_version == '1.21' }} run: make style unused diff --git a/Makefile b/Makefile index 1c5eb709d..ed3a0d90f 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test: deps common-test test-short: deps common-test-short .PHONY: generate-go-collector-test-files -VERSIONS := 1.20 1.21 1.22 +VERSIONS := 1.21 1.22 generate-go-collector-test-files: for GO_VERSION in $(VERSIONS); do \ docker run \ From 47c8cf1b0c99e8e2979659f6d69411d76df8a44c Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 15 Mar 2024 14:31:59 +0100 Subject: [PATCH 19/27] Upgrade Go version to 1.21 in tutorial Signed-off-by: Arianna Vespri --- tutorial/whatsup/go.mod | 2 +- tutorial/whatsup/go.sum | 16 ++++++++++++++++ tutorial/whatsup/reference/main.go | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tutorial/whatsup/go.mod b/tutorial/whatsup/go.mod index 830ecec05..1f30e5cc0 100644 --- a/tutorial/whatsup/go.mod +++ b/tutorial/whatsup/go.mod @@ -1,6 +1,6 @@ module github.com/prometheus/client_golang/tutorial -go 1.20 +go 1.21 require ( github.com/bwplotka/tracing-go v0.0.0-20230421061608-abdf862ceccd diff --git a/tutorial/whatsup/go.sum b/tutorial/whatsup/go.sum index c826a76a6..7ff70af79 100644 --- a/tutorial/whatsup/go.sum +++ b/tutorial/whatsup/go.sum @@ -61,6 +61,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/efficientgo/core v1.0.0-rc.2 h1:7j62qHLnrZqO3V3UA0AqOGd5d5aXV3AX6m/NZBHp78I= github.com/efficientgo/core v1.0.0-rc.2/go.mod h1:FfGdkzWarkuzOlY04VY+bGfb1lWrjaL6x/GLcQ4vJps= github.com/efficientgo/e2e v0.14.1-0.20230421070206-d72d43f3b937 h1:id4ofFoEdjDgOvGhRi24PozN2kzsIriHDKc+HP6ipHo= @@ -88,6 +89,7 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= +github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -143,6 +145,7 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= @@ -159,15 +162,21 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= +github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0= +github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= +github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/minio-go/v7 v7.0.45 h1:g4IeM9M9pW/Lo8AGGNOjBZYlvmtlE1N5TQEYWXRWzIs= +github.com/minio/minio-go/v7 v7.0.45/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw= github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= +github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -193,8 +202,11 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -218,6 +230,7 @@ go.opentelemetry.io/otel v1.6.3/go.mod h1:7BgNga5fNlF/iZjG06hM3yofffp0ofKCDwSXx1 go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= go.opentelemetry.io/otel/exporters/jaeger v1.6.3 h1:7tvBU1Ydbzq080efuepYYqC1Pv3/vOFBgCSrxLb24d0= +go.opentelemetry.io/otel/exporters/jaeger v1.6.3/go.mod h1:YgX3eZWbJzgrNyNHCK0otGreAMBTIAcObtZS2VRi6sU= go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.6.3 h1:nAmg1WgsUXoXf46dJG9eS/AzOcvkCTK4xJSUYpWyHYg= go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.6.3/go.mod h1:NEu79Xo32iVb+0gVNV8PMd7GoWqnyDXRlj04yFjqz40= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.6.3 h1:4/UjHWMVVc5VwX/KAtqJOHErKigMCH8NexChMuanb/o= @@ -245,6 +258,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -506,8 +520,10 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI= +gopkg.in/ini.v1 v1.66.6/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/tutorial/whatsup/reference/main.go b/tutorial/whatsup/reference/main.go index 3c4115149..e8ae5ef65 100644 --- a/tutorial/whatsup/reference/main.go +++ b/tutorial/whatsup/reference/main.go @@ -93,7 +93,7 @@ func runMain(opts internal.Config) (err error) { Help: "Build information.", ConstLabels: map[string]string{ "version": "vYOLO", - "language": "Go 1.20", + "language": "Go 1.21", "owner": "@me", }, }, func() float64 { From 3644321998f84b0ff3b2eef3d2a9ac04d9cfbe0b Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Mon, 22 Apr 2024 13:47:12 +0200 Subject: [PATCH 20/27] Adapt to forthcoming new handlers options, reinstate support for old Go Signed-off-by: Arianna Vespri --- examples/exemplars/main.go | 6 ++++-- examples/gocollector/main.go | 4 +++- go.sum | 1 - prometheus/promhttp/http.go | 17 ++++++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/examples/exemplars/main.go b/examples/exemplars/main.go index 8a841ee13..69670af71 100644 --- a/examples/exemplars/main.go +++ b/examples/exemplars/main.go @@ -62,8 +62,10 @@ func main() { "/metrics", promhttp.HandlerFor( registry, promhttp.HandlerOpts{ - EnableOpenMetrics: true, - WithUnit: true, + OpenMetricsOptions: promhttp.OpenMetricsOptions{ + Enable: true, + EnableUnit: true, + }, }), ) // To test: curl -H 'Accept: application/openmetrics-text' localhost:8080/metrics diff --git a/examples/gocollector/main.go b/examples/gocollector/main.go index 9116314a5..9fef3b48c 100644 --- a/examples/gocollector/main.go +++ b/examples/gocollector/main.go @@ -48,7 +48,9 @@ func main() { reg, promhttp.HandlerOpts{ // Opt into OpenMetrics to support exemplars. - EnableOpenMetrics: true, + OpenMetricsOptions: promhttp.OpenMetricsOptions{ + Enable: true, + }, }, )) fmt.Println("Hello world from new Go Collector!") diff --git a/go.sum b/go.sum index 957f09433..2c696c73a 100644 --- a/go.sum +++ b/go.sum @@ -65,6 +65,5 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 678a0e2db..67e26cd4f 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -161,9 +161,9 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO var contentType expfmt.Format var encoderOpts []expfmt.EncoderOption - if opts.EnableOpenMetrics { + if opts.EnableOpenMetrics || opts.OpenMetricsOptions.Enable { contentType = expfmt.NegotiateIncludingOpenMetrics(req.Header) - if opts.WithUnit { + if opts.OpenMetricsOptions.Enable { encoderOpts = append(encoderOpts, expfmt.WithUnit()) } } else { @@ -375,6 +375,8 @@ type HandlerOpts struct { // (which changes the identity of the resulting series on the Prometheus // server). EnableOpenMetrics bool + + OpenMetricsOptions OpenMetricsOptions // ProcessStartTime allows setting process start timevalue that will be exposed // with "Process-Start-Time-Unix" response header along with the metrics // payload. This allow callers to have efficient transformations to cumulative @@ -383,9 +385,14 @@ type HandlerOpts struct { // NOTE: This feature is experimental and not covered by OpenMetrics or Prometheus // exposition format. ProcessStartTime time.Time - // If true, WithUnit adds the unit to the encoder options, ultimately allowing the - // unit into the final output, provided that EnableOpenMetrics is also true. - WithUnit bool +} + +type OpenMetricsOptions struct { + Enable bool + // If true, EnableUnit adds the unit to the encoder options, ultimately allowing the + // unit into the final output, provided that either EnableOpenMetrics or + // OpenMetricsOptions.Enable is also true. + EnableUnit bool } // gzipAccepted returns whether the client will accept gzip-encoded content. From 717d3d342b00e491bad0160f8cade6d42b536883 Mon Sep 17 00:00:00 2001 From: Arianna Vespri <36129782+vesari@users.noreply.github.com> Date: Thu, 9 May 2024 15:14:02 +0200 Subject: [PATCH 21/27] Update prometheus/promhttp/http.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Arianna Vespri <36129782+vesari@users.noreply.github.com> --- prometheus/promhttp/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 67e26cd4f..781f8bc63 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -389,7 +389,7 @@ type HandlerOpts struct { type OpenMetricsOptions struct { Enable bool - // If true, EnableUnit adds the unit to the encoder options, ultimately allowing the + // EnableUnit adds the unit to the encoder options, ultimately allowing the // unit into the final output, provided that either EnableOpenMetrics or // OpenMetricsOptions.Enable is also true. EnableUnit bool From a635a5abb77692793d17de57339b6e84cb8fbec2 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 17 Oct 2025 14:00:31 +0200 Subject: [PATCH 22/27] small cleanup Signed-off-by: Arianna Vespri --- examples/exemplars/main.go | 5 +---- examples/gocollector/main.go | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/exemplars/main.go b/examples/exemplars/main.go index e0d14eb03..f7b7ac0e6 100644 --- a/examples/exemplars/main.go +++ b/examples/exemplars/main.go @@ -62,10 +62,7 @@ func main() { "/metrics", promhttp.HandlerFor( registry, promhttp.HandlerOpts{ - OpenMetricsOptions: promhttp.OpenMetricsOptions{ - Enable: true, - EnableUnit: true, - }, + EnableOpenMetrics: true, }), ) // To test: curl -H 'Accept: application/openmetrics-text' localhost:8080/metrics diff --git a/examples/gocollector/main.go b/examples/gocollector/main.go index 3106ce296..daca1a365 100644 --- a/examples/gocollector/main.go +++ b/examples/gocollector/main.go @@ -55,9 +55,7 @@ func main() { reg, promhttp.HandlerOpts{ // Opt into OpenMetrics to support exemplars. - OpenMetricsOptions: promhttp.OpenMetricsOptions{ - Enable: true, - }, + EnableOpenMetrics: true, }, )) fmt.Println("Hello world from new Go Collector!") From 9eac68e37b1dbedb68d7f7997ca58b371ead4592 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sun, 16 Nov 2025 11:44:37 +0100 Subject: [PATCH 23/27] Make desc funcs variadic Signed-off-by: Arianna Vespri --- prometheus/build_info_collector.go | 1 - prometheus/collectors/dbstats_collector.go | 9 -------- prometheus/counter.go | 6 ++--- prometheus/desc.go | 17 ++++++++++---- prometheus/desc_test.go | 18 ++++++++++++--- prometheus/example_clustermanager_test.go | 2 -- prometheus/example_metricvec_test.go | 9 +++++--- prometheus/examples_test.go | 10 ++++---- prometheus/expvar_collector_test.go | 3 --- prometheus/gauge.go | 6 ++--- prometheus/go_collector.go | 27 +--------------------- prometheus/go_collector_latest.go | 11 +++++---- prometheus/histogram.go | 4 ++-- prometheus/metric_test.go | 4 ++-- prometheus/process_collector.go | 7 ------ prometheus/promhttp/http.go | 6 +---- prometheus/promhttp/http_test.go | 6 ++--- prometheus/registry.go | 3 +++ prometheus/registry_test.go | 2 +- prometheus/summary.go | 4 ++-- prometheus/testutil/testutil_test.go | 4 ++-- prometheus/untyped.go | 2 +- prometheus/value_test.go | 2 -- prometheus/wrap.go | 2 +- 24 files changed, 70 insertions(+), 95 deletions(-) diff --git a/prometheus/build_info_collector.go b/prometheus/build_info_collector.go index 3f1fe169a..450189f35 100644 --- a/prometheus/build_info_collector.go +++ b/prometheus/build_info_collector.go @@ -30,7 +30,6 @@ func NewBuildInfoCollector() Collector { NewDesc( "go_build_info", "Build information about the main Go module.", - "", nil, Labels{"path": path, "version": version, "checksum": sum}, ), GaugeValue, 1)} diff --git a/prometheus/collectors/dbstats_collector.go b/prometheus/collectors/dbstats_collector.go index 22ab51139..d5a7279fb 100644 --- a/prometheus/collectors/dbstats_collector.go +++ b/prometheus/collectors/dbstats_collector.go @@ -46,55 +46,46 @@ func NewDBStatsCollector(db *sql.DB, dbName string) prometheus.Collector { maxOpenConnections: prometheus.NewDesc( fqName("max_open_connections"), "Maximum number of open connections to the database.", - "", nil, prometheus.Labels{"db_name": dbName}, ), openConnections: prometheus.NewDesc( fqName("open_connections"), "The number of established connections both in use and idle.", - "", nil, prometheus.Labels{"db_name": dbName}, ), inUseConnections: prometheus.NewDesc( fqName("in_use_connections"), "The number of connections currently in use.", - "", nil, prometheus.Labels{"db_name": dbName}, ), idleConnections: prometheus.NewDesc( fqName("idle_connections"), "The number of idle connections.", - "", nil, prometheus.Labels{"db_name": dbName}, ), waitCount: prometheus.NewDesc( fqName("wait_count_total"), "The total number of connections waited for.", - "", nil, prometheus.Labels{"db_name": dbName}, ), waitDuration: prometheus.NewDesc( fqName("wait_duration_seconds_total"), "The total time blocked waiting for a new connection.", - "seconds", nil, prometheus.Labels{"db_name": dbName}, ), maxIdleClosed: prometheus.NewDesc( fqName("max_idle_closed_total"), "The total number of connections closed due to SetMaxIdleConns.", - "", nil, prometheus.Labels{"db_name": dbName}, ), maxIdleTimeClosed: prometheus.NewDesc( fqName("max_idle_time_closed_total"), "The total number of connections closed due to SetConnMaxIdleTime.", - "", nil, prometheus.Labels{"db_name": dbName}, ), maxLifetimeClosed: prometheus.NewDesc( fqName("max_lifetime_closed_total"), "The total number of connections closed due to SetConnMaxLifetime.", - "", nil, prometheus.Labels{"db_name": dbName}, ), } diff --git a/prometheus/counter.go b/prometheus/counter.go index eef38bc30..094be07a6 100644 --- a/prometheus/counter.go +++ b/prometheus/counter.go @@ -88,9 +88,9 @@ func NewCounter(opts CounterOpts) Counter { desc := NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ) if opts.now == nil { opts.now = time.Now @@ -204,7 +204,7 @@ func (v2) NewCounterVec(opts CounterVecOpts) *CounterVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, + // opts.Unit, // QUESTION: shall I put this for last? opts.VariableLabels, opts.ConstLabels, ) @@ -354,8 +354,8 @@ func NewCounterFunc(opts CounterOpts, function func() float64) CounterFunc { return newValueFunc(NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ), CounterValue, function) } diff --git a/prometheus/desc.go b/prometheus/desc.go index b6f4f36e8..9d9dd0012 100644 --- a/prometheus/desc.go +++ b/prometheus/desc.go @@ -68,6 +68,13 @@ type Desc struct { err error } +func optionalUnitValue(unit ...string) string { + if len(unit) > 0 { + return unit[0] + } + return "" +} + // NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc // and will be reported on registration time. variableLabels and constLabels can // be nil if no such labels should be set. fqName must not be empty. @@ -77,8 +84,8 @@ type Desc struct { // // For constLabels, the label values are constant. Therefore, they are fully // specified in the Desc. See the Collector example for a usage pattern. -func NewDesc(fqName, help, unit string, variableLabels []string, constLabels Labels) *Desc { - return V2.NewDesc(fqName, help, unit, UnconstrainedLabels(variableLabels), constLabels) +func NewDesc(fqName, help string, variableLabels []string, constLabels Labels, unit ...string) *Desc { + return V2.NewDesc(fqName, help, UnconstrainedLabels(variableLabels), constLabels, optionalUnitValue(unit...)) } // NewDesc allocates and initializes a new Desc. Errors are recorded in the Desc @@ -91,12 +98,12 @@ func NewDesc(fqName, help, unit string, variableLabels []string, constLabels Lab // // For constLabels, the label values are constant. Therefore, they are fully // specified in the Desc. See the Collector example for a usage pattern. -func (v2) NewDesc(fqName, help, unit string, variableLabels ConstrainableLabels, constLabels Labels) *Desc { +func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, constLabels Labels, unit ...string) *Desc { d := &Desc{ fqName: fqName, help: help, - unit: unit, variableLabels: variableLabels.compile(), + unit: optionalUnitValue(unit...), } //nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme. if !model.NameValidationScheme.IsValidMetricName(fqName) { @@ -157,7 +164,7 @@ func (v2) NewDesc(fqName, help, unit string, variableLabels ConstrainableLabels, // label names. xxh.Reset() xxh.WriteString(help) - xxh.WriteString(unit) + xxh.WriteString(optionalUnitValue(unit...)) xxh.Write(separatorByteSlice) for _, labelName := range labelNames { xxh.WriteString(labelName) diff --git a/prometheus/desc_test.go b/prometheus/desc_test.go index 567c396d3..c1288844f 100644 --- a/prometheus/desc_test.go +++ b/prometheus/desc_test.go @@ -21,7 +21,6 @@ func TestNewDescInvalidLabelValues(t *testing.T) { desc := NewDesc( "sample_label", "sample label", - "", nil, Labels{"a": "\xFF"}, ) @@ -49,7 +48,7 @@ func TestNewDescWithNilLabelValues_String(t *testing.T) { nil, nil, ) - if desc.String() != `Desc{fqName: "sample_label", help: "sample label", constLabels: {}, variableLabels: {}}` { + if desc.String() != `Desc{fqName: "sample_label", help: "sample label", unit: "", constLabels: {}, variableLabels: {}}` { t.Errorf("String: unexpected output: %s", desc.String()) } } @@ -58,7 +57,20 @@ func TestNewInvalidDesc_String(t *testing.T) { desc := NewInvalidDesc( nil, ) - if desc.String() != `Desc{fqName: "", help: "", constLabels: {}, variableLabels: {}}` { + if desc.String() != `Desc{fqName: "", help: "", unit: "", constLabels: {}, variableLabels: {}}` { t.Errorf("String: unexpected output: %s", desc.String()) } } + +func TestNewDescWithUnit_String(t *testing.T) { + desc := NewDesc( + "sample_metric_bytes", + "sample metric with unit", + nil, + nil, + "bytes", + ) + if desc.String() != `Desc{fqName: "sample_metric_bytes", help: "sample metric with unit", unit: "bytes", constLabels: {}, variableLabels: {}}` { + t.Errorf("String: unexpected output:\ngot: %s\nwant: %s", desc.String(), desc.String()) + } +} diff --git a/prometheus/example_clustermanager_test.go b/prometheus/example_clustermanager_test.go index b995677fa..92b61ca85 100644 --- a/prometheus/example_clustermanager_test.go +++ b/prometheus/example_clustermanager_test.go @@ -66,13 +66,11 @@ var ( oomCountDesc = prometheus.NewDesc( "clustermanager_oom_crashes_total", "Number of OOM crashes.", - "", []string{"host"}, nil, ) ramUsageDesc = prometheus.NewDesc( "clustermanager_ram_usage_bytes", "RAM usage as reported to the cluster manager.", - "bytes", []string{"host"}, nil, ) ) diff --git a/prometheus/example_metricvec_test.go b/prometheus/example_metricvec_test.go index 8bf8e9739..0a6234364 100644 --- a/prometheus/example_metricvec_test.go +++ b/prometheus/example_metricvec_test.go @@ -52,8 +52,12 @@ type InfoVec struct { *prometheus.MetricVec } -func NewInfoVec(name, help, unit string, labelNames []string) *InfoVec { - desc := prometheus.NewDesc(name, help, unit, labelNames, nil) +func NewInfoVec(name, help string, labelNames []string, unit ...string) *InfoVec { + var u string + if len(unit) > 0 { + u = unit[0] + } + desc := prometheus.NewDesc(name, help, labelNames, nil, u) return &InfoVec{ MetricVec: prometheus.NewMetricVec(desc, func(lvs ...string) prometheus.Metric { if len(lvs) != len(labelNames) { @@ -110,7 +114,6 @@ func ExampleMetricVec() { infoVec := NewInfoVec( "library_version_info", "Versions of the libraries used in this binary.", - "", []string{"library", "version"}, ) diff --git a/prometheus/examples_test.go b/prometheus/examples_test.go index 8ba773937..7c137dbe2 100644 --- a/prometheus/examples_test.go +++ b/prometheus/examples_test.go @@ -384,9 +384,9 @@ func ExampleNewConstSummary() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A summary of the HTTP request durations.", - "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, + "seconds", ) // Create a constant summary from values we got from a 3rd party telemetry system. @@ -466,9 +466,9 @@ func ExampleNewConstHistogram() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", - "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, + "seconds", ) // Create a constant histogram from values we got from a 3rd party telemetry system. @@ -522,9 +522,9 @@ func ExampleNewConstHistogram_withExemplar() { desc := prometheus.NewDesc( "http_request_duration_seconds", "A histogram of the HTTP request durations.", - "seconds", []string{"code", "method"}, prometheus.Labels{"owner": "example"}, + "seconds", ) // Create a constant histogram from values we got from a 3rd party telemetry system. @@ -693,8 +693,8 @@ func ExampleNewMetricWithTimestamp() { desc := prometheus.NewDesc( "temperature_kelvin", "Current temperature in Kelvin.", - "kelvin", nil, nil, + "kelvin", ) // Create a constant gauge from values we got from an external @@ -727,8 +727,8 @@ func ExampleNewConstMetricWithCreatedTimestamp() { desc := prometheus.NewDesc( "time_since_epoch_seconds", "Current epoch time in seconds.", - "seconds", nil, nil, + "seconds", ) timeSinceEpochReportedByExternalSystem := time.Date(2009, time.November, 10, 23, 0, 0, 12345678, time.UTC) diff --git a/prometheus/expvar_collector_test.go b/prometheus/expvar_collector_test.go index 88d25019a..a8d0ed294 100644 --- a/prometheus/expvar_collector_test.go +++ b/prometheus/expvar_collector_test.go @@ -29,19 +29,16 @@ func ExampleNewExpvarCollector() { "memstats": prometheus.NewDesc( "expvar_memstats", "All numeric memstats as one metric family. Not a good role-model, actually... ;-)", - "", []string{"type"}, nil, ), "lone-int": prometheus.NewDesc( "expvar_lone_int", "Just an expvar int as an example.", - "", nil, nil, ), "http-request-map": prometheus.NewDesc( "expvar_http_request_total", "How many http requests processed, partitioned by status code and http method.", - "", []string{"code", "method"}, nil, ), }) diff --git a/prometheus/gauge.go b/prometheus/gauge.go index f643509bc..969359679 100644 --- a/prometheus/gauge.go +++ b/prometheus/gauge.go @@ -79,9 +79,9 @@ func NewGauge(opts GaugeOpts) Gauge { desc := NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ) result := &gauge{desc: desc, labelPairs: desc.constLabelPairs} result.init(result) // Init self-collection. @@ -162,9 +162,9 @@ func (v2) NewGaugeVec(opts GaugeVecOpts) *GaugeVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, opts.VariableLabels, opts.ConstLabels, + opts.Unit, ) return &GaugeVec{ MetricVec: NewMetricVec(desc, func(lvs ...string) Metric { @@ -307,8 +307,8 @@ func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc { return newValueFunc(NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ), GaugeValue, function) } diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index d6d31a8d1..520cbd7d4 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -29,7 +29,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("alloc_bytes"), "Number of bytes allocated in heap and currently in use. Equals to /memory/classes/heap/objects:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Alloc) }, @@ -38,7 +37,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("alloc_bytes_total"), "Total number of bytes allocated in heap until now, even if released already. Equals to /gc/heap/allocs:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.TotalAlloc) }, @@ -47,16 +45,15 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("sys_bytes"), "Number of bytes obtained from system. Equals to /memory/classes/total:byte.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Sys) }, valType: GaugeValue, }, { desc: NewDesc( - "", memstatNamespace("mallocs_total"), // TODO(bwplotka): We could add go_memstats_heap_objects, probably useful for discovery. Let's gather more feedback, kind of a waste of bytes for everybody for compatibility reasons to keep both, and we can't really rename/remove useful metric. + "Total number of heap objects allocated, both live and gc-ed. Semantically a counter version for go_memstats_heap_objects gauge. Equals to /gc/heap/allocs:objects + /gc/heap/tiny/allocs:objects.", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Mallocs) }, @@ -65,7 +62,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("frees_total"), "Total number of heap objects frees. Equals to /gc/heap/frees:objects + /gc/heap/tiny/allocs:objects.", -"" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.Frees) }, @@ -74,7 +70,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_alloc_bytes"), "Number of heap bytes allocated and currently in use, same as go_memstats_alloc_bytes. Equals to /memory/classes/heap/objects:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapAlloc) }, @@ -83,7 +78,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_sys_bytes"), "Number of heap bytes obtained from system. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes + /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapSys) }, @@ -92,7 +86,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_idle_bytes"), "Number of heap bytes waiting to be used. Equals to /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapIdle) }, @@ -101,7 +94,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_inuse_bytes"), "Number of heap bytes that are in use. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes", - "bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapInuse) }, @@ -110,7 +102,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_released_bytes"), "Number of heap bytes released to OS. Equals to /memory/classes/heap/released:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapReleased) }, @@ -119,7 +110,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("heap_objects"), "Number of currently allocated objects. Equals to /gc/heap/objects:objects.", -"", nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapObjects) }, @@ -128,7 +118,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("stack_inuse_bytes"), "Number of bytes obtained from system for stack allocator in non-CGO environments. Equals to /memory/classes/heap/stacks:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackInuse) }, @@ -137,7 +126,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("stack_sys_bytes"), "Number of bytes obtained from system for stack allocator. Equals to /memory/classes/heap/stacks:bytes + /memory/classes/os-stacks:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.StackSys) }, @@ -146,7 +134,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mspan_inuse_bytes"), "Number of bytes in use by mspan structures. Equals to /memory/classes/metadata/mspan/inuse:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanInuse) }, @@ -155,7 +142,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mspan_sys_bytes"), "Number of bytes used for mspan structures obtained from system. Equals to /memory/classes/metadata/mspan/inuse:bytes + /memory/classes/metadata/mspan/free:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MSpanSys) }, @@ -164,7 +150,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mcache_inuse_bytes"), "Number of bytes in use by mcache structures. Equals to /memory/classes/metadata/mcache/inuse:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheInuse) }, @@ -173,7 +158,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("mcache_sys_bytes"), "Number of bytes used for mcache structures obtained from system. Equals to /memory/classes/metadata/mcache/inuse:bytes + /memory/classes/metadata/mcache/free:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.MCacheSys) }, @@ -182,7 +166,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("buck_hash_sys_bytes"), "Number of bytes used by the profiling bucket hash table. Equals to /memory/classes/profiling/buckets:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.BuckHashSys) }, @@ -191,7 +174,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("gc_sys_bytes"), "Number of bytes used for garbage collection system metadata. Equals to /memory/classes/metadata/other:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.GCSys) }, @@ -200,7 +182,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("other_sys_bytes"), "Number of bytes used for other system allocations. Equals to /memory/classes/other:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.OtherSys) }, @@ -209,7 +190,6 @@ func goRuntimeMemStats() memStatsMetrics { desc: NewDesc( memstatNamespace("next_gc_bytes"), "Number of heap bytes when next garbage collection will take place. Equals to /gc/heap/goal:bytes.", -"bytes" nil, nil, ), eval: func(ms *runtime.MemStats) float64 { return float64(ms.NextGC) }, @@ -231,27 +211,22 @@ func newBaseGoCollector() baseGoCollector { goroutinesDesc: NewDesc( "go_goroutines", "Number of goroutines that currently exist.", - "", nil, nil), threadsDesc: NewDesc( "go_threads", "Number of OS threads created.", - "", nil, nil), gcDesc: NewDesc( "go_gc_duration_seconds", "A summary of the wall-time pause (stop-the-world) duration in garbage collection cycles.", -"seconds" nil, nil), gcLastTimeDesc: NewDesc( "go_memstats_last_gc_time_seconds", "Number of seconds since 1970 of last garbage collection.", - "seconds", nil, nil), goInfoDesc: NewDesc( "go_info", "Information about the Go environment.", - "", nil, Labels{"version": runtime.Version()}), } } diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 8f5da90d2..bdbbf7f55 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -98,7 +98,7 @@ type goCollector struct { // snapshot is always produced by Collect. mu sync.Mutex - // Contains all samples that has to retrieved from runtime/metrics (not all of them will be exposed). + // Contains all samples that have to be retrieved from runtime/metrics (not all of them will be exposed). sampleBuf []metrics.Sample // sampleMap allows lookup for MemStats metrics and runtime/metrics histograms for exact sums. sampleMap map[string]*metrics.Sample @@ -210,18 +210,19 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { sampleBuf = append(sampleBuf, metrics.Sample{Name: d.Name}) sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1] + // Extract unit from the runtime/metrics name (e.g., "/gc/heap/allocs:bytes" -> "bytes") + unit := d.Name[strings.IndexRune(d.Name, ':')+1:] + var m collectorMetric if d.Kind == metrics.KindFloat64Histogram { _, hasSum := opt.RuntimeMetricSumForHist[d.Name] - unit := d.Name[strings.IndexRune(d.Name, ':')+1:] m = newBatchHistogram( NewDesc( BuildFQName(namespace, subsystem, name), help, -// Can we assume that this is a suitable unit? -unit, nil, nil, + unit, ), internal.RuntimeMetricsBucketsForUnit(bucketsMap[d.Name], unit), hasSum, @@ -232,6 +233,7 @@ unit, Subsystem: subsystem, Name: name, Help: help, + Unit: unit, }, ) } else { @@ -240,6 +242,7 @@ unit, Subsystem: subsystem, Name: name, Help: help, + Unit: unit, }) } metricSet = append(metricSet, m) diff --git a/prometheus/histogram.go b/prometheus/histogram.go index c6eb1e24a..1f0f92892 100644 --- a/prometheus/histogram.go +++ b/prometheus/histogram.go @@ -528,9 +528,9 @@ func NewHistogram(opts HistogramOpts) Histogram { NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ), opts, ) @@ -1192,9 +1192,9 @@ func (v2) NewHistogramVec(opts HistogramVecOpts) *HistogramVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, opts.VariableLabels, opts.ConstLabels, + opts.Unit, ) return &HistogramVec{ MetricVec: NewMetricVec(desc, func(lvs ...string) Metric { diff --git a/prometheus/metric_test.go b/prometheus/metric_test.go index 353523fc0..96960fee7 100644 --- a/prometheus/metric_test.go +++ b/prometheus/metric_test.go @@ -49,7 +49,7 @@ func TestWithExemplarsMetric(t *testing.T) { t.Run("histogram", func(t *testing.T) { // Create a constant histogram from values we got from a 3rd party telemetry system. h := MustNewConstHistogram( - NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", "seconds", nil, nil), + NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", nil, nil, "seconds"), 4711, 403.34, // Four buckets, but we expect five as the +Inf bucket will be created if we see value outside of those buckets. map[float64]uint64{25: 121, 50: 2403, 100: 3221, 200: 4233}, @@ -99,7 +99,7 @@ func TestWithExemplarsNativeHistogramMetric(t *testing.T) { t.Run("native histogram single exemplar", func(t *testing.T) { // Create a constant histogram from values we got from a 3rd party telemetry system. h := MustNewConstNativeHistogram( - NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", nil, nil), + NewDesc("http_request_duration_seconds", "A histogram of the HTTP request durations.", nil, nil, "seconds"), 10, 12.1, map[int]int64{1: 7, 2: 1, 3: 2}, map[int]int64{}, 0, 2, 0.2, time.Date( 2009, 11, 17, 20, 34, 58, 651387237, time.UTC)) m := &withExemplarsMetric{Metric: h, exemplars: []*dto.Exemplar{ diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index 1227a0145..e7bce8b58 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -70,43 +70,36 @@ func NewProcessCollector(opts ProcessCollectorOpts) Collector { cpuTotal: NewDesc( ns+"process_cpu_seconds_total", "Total user and system CPU time spent in seconds.", - "seconds", nil, nil, ), openFDs: NewDesc( ns+"process_open_fds", "Number of open file descriptors.", - "", nil, nil, ), maxFDs: NewDesc( ns+"process_max_fds", "Maximum number of open file descriptors.", - "", nil, nil, ), vsize: NewDesc( ns+"process_virtual_memory_bytes", "Virtual memory size in bytes.", - "bytes", nil, nil, ), maxVsize: NewDesc( ns+"process_virtual_memory_max_bytes", "Maximum amount of virtual memory available in bytes.", - "bytes", nil, nil, ), rss: NewDesc( ns+"process_resident_memory_bytes", "Resident memory size in bytes.", - "bytes", nil, nil, ), startTime: NewDesc( ns+"process_start_time_seconds", "Start time of the process since unix epoch in seconds.", - "seconds", nil, nil, ), inBytes: NewDesc( diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 42b4437d6..fd3c76342 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -191,12 +191,8 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO } var contentType expfmt.Format - var encoderOpts []expfmt.EncoderOption - if opts.EnableOpenMetrics || opts.OpenMetricsOptions.Enable { + if opts.EnableOpenMetrics { contentType = expfmt.NegotiateIncludingOpenMetrics(req.Header) - if opts.OpenMetricsOptions.Enable { - encoderOpts = append(encoderOpts, expfmt.WithUnit()) - } } else { contentType = expfmt.Negotiate(req.Header) } diff --git a/prometheus/promhttp/http_test.go b/prometheus/promhttp/http_test.go index b9f50de57..5f1b767e8 100644 --- a/prometheus/promhttp/http_test.go +++ b/prometheus/promhttp/http_test.go @@ -41,12 +41,12 @@ const ( ) func (e errorCollector) Describe(ch chan<- *prometheus.Desc) { - ch <- prometheus.NewDesc("invalid_metric", "not helpful", "", nil, nil) + ch <- prometheus.NewDesc("invalid_metric", "not helpful", nil, nil) } func (e errorCollector) Collect(ch chan<- prometheus.Metric) { ch <- prometheus.NewInvalidMetric( - prometheus.NewDesc("invalid_metric", "not helpful", "", nil, nil), + prometheus.NewDesc("invalid_metric", "not helpful", nil, nil), errors.New("collect error"), ) } @@ -56,7 +56,7 @@ type blockingCollector struct { } func (b blockingCollector) Describe(ch chan<- *prometheus.Desc) { - ch <- prometheus.NewDesc("dummy_desc", "not helpful", "", nil, nil) + ch <- prometheus.NewDesc("dummy_desc", "not helpful", nil, nil) } func (b blockingCollector) Collect(ch chan<- prometheus.Metric) { diff --git a/prometheus/registry.go b/prometheus/registry.go index c6fd2f58b..2cdcdff6a 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -685,6 +685,9 @@ func processMetric( metricFamily = &dto.MetricFamily{} metricFamily.Name = proto.String(desc.fqName) metricFamily.Help = proto.String(desc.help) + if desc.unit != "" { + metricFamily.Unit = proto.String(desc.unit) + } // TODO(beorn7): Simplify switch once Desc has type. switch { case dtoMetric.Gauge != nil: diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index 3be6f6f72..12b09d623 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -1311,7 +1311,7 @@ func TestCheckMetricConsistency(t *testing.T) { reg := prometheus.NewRegistry() timestamp := time.Now() - desc := prometheus.NewDesc("metric_a", "", "", nil, nil) + desc := prometheus.NewDesc("metric_a", "", nil, nil) metric := prometheus.MustNewConstMetric(desc, prometheus.CounterValue, 1) validCollector := &customCollector{ diff --git a/prometheus/summary.go b/prometheus/summary.go index 49d162099..b8becf120 100644 --- a/prometheus/summary.go +++ b/prometheus/summary.go @@ -187,9 +187,9 @@ func NewSummary(opts SummaryOpts) Summary { NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ), opts, ) @@ -580,9 +580,9 @@ func (v2) NewSummaryVec(opts SummaryVecOpts) *SummaryVec { desc := V2.NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, opts.VariableLabels, opts.ConstLabels, + opts.Unit, ) return &SummaryVec{ MetricVec: NewMetricVec(desc, func(lvs ...string) Metric { diff --git a/prometheus/testutil/testutil_test.go b/prometheus/testutil/testutil_test.go index 813d29da7..06e367744 100644 --- a/prometheus/testutil/testutil_test.go +++ b/prometheus/testutil/testutil_test.go @@ -28,12 +28,12 @@ import ( type untypedCollector struct{} func (u untypedCollector) Describe(c chan<- *prometheus.Desc) { - c <- prometheus.NewDesc("name", "help", "", nil, nil) + c <- prometheus.NewDesc("name", "help", nil, nil) } func (u untypedCollector) Collect(c chan<- prometheus.Metric) { c <- prometheus.MustNewConstMetric( - prometheus.NewDesc("name", "help", "", nil, nil), + prometheus.NewDesc("name", "help", nil, nil), prometheus.UntypedValue, 2001, ) diff --git a/prometheus/untyped.go b/prometheus/untyped.go index c9ea7d4bb..d43db964d 100644 --- a/prometheus/untyped.go +++ b/prometheus/untyped.go @@ -36,8 +36,8 @@ func NewUntypedFunc(opts UntypedOpts, function func() float64) UntypedFunc { return newValueFunc(NewDesc( BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), opts.Help, - opts.Unit, nil, opts.ConstLabels, + opts.Unit, ), UntypedValue, function) } diff --git a/prometheus/value_test.go b/prometheus/value_test.go index 0214d567e..23da6b217 100644 --- a/prometheus/value_test.go +++ b/prometheus/value_test.go @@ -44,7 +44,6 @@ func TestNewConstMetricInvalidLabelValues(t *testing.T) { metricDesc := NewDesc( "sample_value", "sample value", - "", []string{"a"}, Labels{}, ) @@ -88,7 +87,6 @@ func TestNewConstMetricWithCreatedTimestamp(t *testing.T) { metricDesc := NewDesc( "sample_value", "sample value", - "", nil, nil, ) diff --git a/prometheus/wrap.go b/prometheus/wrap.go index 2a0ab438d..6ce58aea3 100644 --- a/prometheus/wrap.go +++ b/prometheus/wrap.go @@ -239,7 +239,7 @@ func wrapDesc(desc *Desc, prefix string, labels Labels) *Desc { constLabels[ln] = lv } // NewDesc will do remaining validations. - newDesc := V2.NewDesc(prefix+desc.fqName, desc.help, desc.unit, desc.variableLabels, constLabels) + newDesc := V2.NewDesc(prefix+desc.fqName, desc.help, desc.variableLabels, constLabels, desc.unit) // Propagate errors if there was any. This will override any errer // created by NewDesc above, i.e. earlier errors get precedence. if desc.err != nil { From 3441cb00225c3a65d7b45d5f934bc7e9078c9ba6 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Wed, 19 Nov 2025 16:34:30 +0100 Subject: [PATCH 24/27] Adjust http to have unit and test accordingly Signed-off-by: Arianna Vespri --- prometheus/promhttp/http.go | 12 ++++++++--- prometheus/promhttp/http_test.go | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index fd3c76342..a11d6c380 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -215,11 +215,14 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO } var enc expfmt.Encoder + var encOpts []expfmt.EncoderOption if opts.EnableOpenMetricsTextCreatedSamples { - enc = expfmt.NewEncoder(w, contentType, expfmt.WithCreatedLines()) - } else { - enc = expfmt.NewEncoder(w, contentType) + encOpts = append(encOpts, expfmt.WithCreatedLines()) + } + if opts.EnableOpenMetricsUnit { + encOpts = append(encOpts, expfmt.WithUnit()) } + enc = expfmt.NewEncoder(w, contentType, encOpts...) // handleError handles the error according to opts.ErrorHandling // and returns true if we have to abort after the handling. @@ -435,6 +438,9 @@ type HandlerOpts struct { // Prometheus introduced the feature flag 'created-timestamp-zero-ingestion' // in version 2.50.0 to handle this situation. EnableOpenMetricsTextCreatedSamples bool + // EnableOpenMetricsUnit enables unit metadata in the OpenMetrics output format. + // This is only applicable when OpenMetrics format is negotiated. + EnableOpenMetricsUnit bool // ProcessStartTime allows setting process start timevalue that will be exposed // with "Process-Start-Time-Unix" response header along with the metrics // payload. This allow callers to have efficient transformations to cumulative diff --git a/prometheus/promhttp/http_test.go b/prometheus/promhttp/http_test.go index 5f1b767e8..9f4cbd5f5 100644 --- a/prometheus/promhttp/http_test.go +++ b/prometheus/promhttp/http_test.go @@ -549,6 +549,40 @@ func TestNegotiateEncodingWriter(t *testing.T) { } } +func TestHandlerWithUnit(t *testing.T) { + reg := prometheus.NewRegistry() + + counter := prometheus.NewCounter(prometheus.CounterOpts{ + Name: "http_request_duration_seconds_total", + Help: "Total time spent handling HTTP requests.", + Unit: "seconds", + }) + reg.MustRegister(counter) + counter.Add(42) + + expectedOpenMetricsOutput := `# HELP http_request_duration_seconds Total time spent handling HTTP requests. +# TYPE http_request_duration_seconds counter +# UNIT http_request_duration_seconds seconds +http_request_duration_seconds_total 42.0 +# EOF +` + + handler := HandlerFor(reg, HandlerOpts{EnableOpenMetrics: true, EnableOpenMetricsUnit: true}) + writer := httptest.NewRecorder() + request, _ := http.NewRequest(http.MethodGet, "/", nil) + request.Header.Add(acceptHeader, "application/openmetrics-text") + + handler.ServeHTTP(writer, request) + + if got, want := writer.Header().Get(contentTypeHeader), "application/openmetrics-text; version=0.0.1; charset=utf-8; escaping=underscores"; got != want { + t.Errorf("expected Content-Type %q, got %q", want, got) + } + + if got := writer.Body.String(); got != expectedOpenMetricsOutput { + t.Errorf("expected body:\n%s\ngot:\n%s", expectedOpenMetricsOutput, got) + } +} + func BenchmarkCompression(b *testing.B) { benchmarks := []struct { name string From 99ae579f5b8e37dbfbc42595bdb305a04d4b0c1b Mon Sep 17 00:00:00 2001 From: Arianna Vespri <36129782+vesari@users.noreply.github.com> Date: Sun, 14 Dec 2025 09:53:30 +0100 Subject: [PATCH 25/27] Update prometheus/metric.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Arianna Vespri <36129782+vesari@users.noreply.github.com> --- prometheus/metric.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus/metric.go b/prometheus/metric.go index 4073a943c..c5cb90adf 100644 --- a/prometheus/metric.go +++ b/prometheus/metric.go @@ -81,7 +81,7 @@ type Opts struct { // string. Help string - // Unit provides the unit of this metric. + // Unit provides the unit of this metric as per https://prometheus.io/docs/specs/om Unit string // ConstLabels are used to attach fixed labels to this metric. Metrics From 1d93cb8c2057fcbfe8680abc45113e19a740f3c6 Mon Sep 17 00:00:00 2001 From: Arianna Vespri <36129782+vesari@users.noreply.github.com> Date: Sun, 14 Dec 2025 09:55:33 +0100 Subject: [PATCH 26/27] Update prometheus/promhttp/http.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Arianna Vespri <36129782+vesari@users.noreply.github.com> --- prometheus/promhttp/http.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index a11d6c380..b71a371e7 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -214,8 +214,10 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO rsp.Header().Set(contentEncodingHeader, encodingHeader) } - var enc expfmt.Encoder - var encOpts []expfmt.EncoderOption +var ( +enc expfmt.Encoder +encOpts []expfmt.EncoderOption +) if opts.EnableOpenMetricsTextCreatedSamples { encOpts = append(encOpts, expfmt.WithCreatedLines()) } From 5a0791863e4899f5c373a94895f257c9c776d037 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sun, 14 Dec 2025 10:19:00 +0100 Subject: [PATCH 27/27] Fix formatting Signed-off-by: Arianna Vespri --- prometheus/promhttp/http.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 6c1c37a7b..18e9d5bf5 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -226,10 +226,10 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO rsp.Header().Set(contentEncodingHeader, encodingHeader) } -var ( -enc expfmt.Encoder -encOpts []expfmt.EncoderOption -) + var ( + enc expfmt.Encoder + encOpts []expfmt.EncoderOption + ) if opts.EnableOpenMetricsTextCreatedSamples { encOpts = append(encOpts, expfmt.WithCreatedLines()) }