From 5bf3341b6684a18bfdc019c9b2c154ab6a42c0a1 Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Mon, 19 Aug 2024 15:27:04 -0300 Subject: [PATCH 1/6] Use NewPedanticRegistry in Process' Collector tests Signed-off-by: Arthur Silva Sens --- prometheus/process_collector_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus/process_collector_test.go b/prometheus/process_collector_test.go index 11e0540..0d62d41 100644 --- a/prometheus/process_collector_test.go +++ b/prometheus/process_collector_test.go @@ -37,7 +37,7 @@ func TestProcessCollector(t *testing.T) { t.Skipf("skipping TestProcessCollector, procfs not available: %s", err) } - registry := NewRegistry() + registry := NewPedanticRegistry() if err := registry.Register(NewProcessCollector(ProcessCollectorOpts{})); err != nil { t.Fatal(err) } From 261fe84cd4f670b8e51bf74f6f6bbb96aa1fce20 Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Mon, 19 Aug 2024 15:31:02 -0300 Subject: [PATCH 2/6] bugfix: Pass network metrics to processCollector's Describe() function Signed-off-by: Arthur Silva Sens --- prometheus/process_collector.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index efbc3ea..62a4e7a 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -140,6 +140,8 @@ func (c *processCollector) Describe(ch chan<- *Desc) { ch <- c.maxVsize ch <- c.rss ch <- c.startTime + ch <- c.inBytes + ch <- c.outBytes } // Collect returns the current state of all metrics of the collector. From f2dd7b35fd3f28b6a59b64953aab727b5c0c0404 Mon Sep 17 00:00:00 2001 From: bwplotka Date: Tue, 20 Aug 2024 11:42:48 +0100 Subject: [PATCH 3/6] Use pedantic registry in other places too, to double check. Signed-off-by: bwplotka --- prometheus/collectors/dbstats_collector_test.go | 2 +- prometheus/collectors/go_collector_latest_test.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/prometheus/collectors/dbstats_collector_test.go b/prometheus/collectors/dbstats_collector_test.go index 0698bb2..057e243 100644 --- a/prometheus/collectors/dbstats_collector_test.go +++ b/prometheus/collectors/dbstats_collector_test.go @@ -21,7 +21,7 @@ import ( ) func TestDBStatsCollector(t *testing.T) { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() { db := new(sql.DB) if err := reg.Register(NewDBStatsCollector(db, "db_A")); err != nil { diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index 98259f8..2f5440a 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -63,7 +63,7 @@ var memstatMetrics = []string{ } func TestGoCollectorMarshalling(t *testing.T) { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() reg.MustRegister(NewGoCollector( WithGoCollectorRuntimeMetrics(GoRuntimeMetricsRule{ Matcher: regexp.MustCompile("/.*"), @@ -80,7 +80,7 @@ func TestGoCollectorMarshalling(t *testing.T) { } func TestWithGoCollectorDefault(t *testing.T) { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() reg.MustRegister(NewGoCollector()) result, err := reg.Gather() if err != nil { @@ -100,7 +100,7 @@ func TestWithGoCollectorDefault(t *testing.T) { } func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() reg.MustRegister(NewGoCollector( WithGoCollectorMemStatsMetricsDisabled(), )) @@ -157,7 +157,7 @@ func TestGoCollectorAllowList(t *testing.T) { }, } { t.Run(test.name, func(t *testing.T) { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() reg.MustRegister(NewGoCollector( WithGoCollectorMemStatsMetricsDisabled(), WithGoCollectorRuntimeMetrics(test.rules...), @@ -219,7 +219,7 @@ func TestGoCollectorDenyList(t *testing.T) { }, } { t.Run(test.name, func(t *testing.T) { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() reg.MustRegister(NewGoCollector( WithGoCollectorMemStatsMetricsDisabled(), WithoutGoCollectorRuntimeMetrics(test.matchers...), @@ -242,7 +242,7 @@ func TestGoCollectorDenyList(t *testing.T) { } func ExampleGoCollector() { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() // Register the GoCollector with the default options. Only the base metrics, default runtime metrics and memstats are enabled. reg.MustRegister(NewGoCollector()) @@ -252,7 +252,7 @@ func ExampleGoCollector() { } func ExampleGoCollector_WithAdvancedGoMetrics() { - reg := prometheus.NewRegistry() + reg := prometheus.NewPedanticRegistry() // Enable Go metrics with pre-defined rules. Or your custom rules. reg.MustRegister( From 4a15d0584653a36547195042512218cad99888c6 Mon Sep 17 00:00:00 2001 From: bwplotka Date: Tue, 20 Aug 2024 11:46:16 +0100 Subject: [PATCH 4/6] Cut 1.20.1 Signed-off-by: bwplotka --- CHANGELOG.md | 6 +++++- VERSION | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f72cae5..37749eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +## 1.20.1 / 2024-08-20 + +* [BUGFIX] process-collector: Fixed unregistered descriptor error when using process collector with `PedanticRegistry` on linux machines. #1587 + ## 1.20.0 / 2024-08-14 * [CHANGE] :warning: go-collector: Remove `go_memstat_lookups_total` metric which was always 0; Go runtime stopped sharing pointer lookup statistics. #1577 @@ -10,7 +14,7 @@ * [FEATURE] promhttp: Add experimental support for `zstd` on scrape, controlled by the request `Accept-Encoding` header. #1496 * [FEATURE] api/v1: Add `WithLimit` parameter to all API methods that supports it. #1544 * [FEATURE] prometheus: Add support for created timestamps in constant histograms and constant summaries. #1537 -* [FEATURE] process-collectors: Add network usage metrics: `process_network_receive_bytes_total` and `process_network_transmit_bytes_total`. #1555 +* [FEATURE] process-collector: Add network usage metrics: `process_network_receive_bytes_total` and `process_network_transmit_bytes_total`. #1555 * [FEATURE] promlint: Add duplicated metric lint rule. #1472 * [BUGFIX] promlint: Relax metric type in name linter rule. #1455 * [BUGFIX] promhttp: Make sure server instrumentation wrapping supports new and future extra responseWriter methods. #1480 diff --git a/VERSION b/VERSION index 3989355..0044d6c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.20.0 +1.20.1 From f7f8f3a1e2c09da4b88b78b7e04a9252187cf71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 23 Aug 2024 15:04:34 +0200 Subject: [PATCH 5/6] fix: Unset Content-Encoding header when uncompressed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #1595 Signed-off-by: Manuel Rüger --- prometheus/promhttp/http.go | 6 ++++-- prometheus/promhttp/http_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 2e0b9a8..e598e66 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -203,8 +203,10 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO defer closeWriter() - rsp.Header().Set(contentEncodingHeader, encodingHeader) - + // Set Content-Encoding only when data is compressed + if encodingHeader != string(Identity) { + rsp.Header().Set(contentEncodingHeader, encodingHeader) + } enc := expfmt.NewEncoder(w, contentType) // handleError handles the error according to opts.ErrorHandling diff --git a/prometheus/promhttp/http_test.go b/prometheus/promhttp/http_test.go index 0ed8fe3..3ad2d1d 100644 --- a/prometheus/promhttp/http_test.go +++ b/prometheus/promhttp/http_test.go @@ -267,7 +267,7 @@ func TestInstrumentMetricHandler(t *testing.T) { t.Errorf("got HTTP status code %d, want %d", got, want) } - if got, want := writer.Header().Get(contentEncodingHeader), string(Identity); got != want { + if got, want := writer.Header().Get(contentEncodingHeader), ""; got != want { t.Errorf("got HTTP content encoding header %s, want %s", got, want) } From 187acd4ca1a05e3207990e427cae7057a1e58961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 23 Aug 2024 18:55:43 +0200 Subject: [PATCH 6/6] Cut 1.20.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Rüger --- CHANGELOG.md | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37749eb..f83a027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +## 1.20.2 / 2024-08-23 + +* [BUGFIX] promhttp: Unset Content-Encoding header when data is uncompressed. #1596 + ## 1.20.1 / 2024-08-20 * [BUGFIX] process-collector: Fixed unregistered descriptor error when using process collector with `PedanticRegistry` on linux machines. #1587 diff --git a/VERSION b/VERSION index 0044d6c..769e37e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.20.1 +1.20.2