Repository: prometheus/prometheus
Pull request #11916 (2023-01-31 17:13:23)

Merge 2.42 to main
**DO NOT SQUASH OR REBASE**

- Cut v2.42.0-rc.0 (#11902)
- Update changelog for 2.42 (#11909)
- Cut v2.42.0 (#11912)

<!--
    Don't forget!

    - Please sign CNCF's Developer Certificate of Origin and sign-off your commits by adding the -s / --sign-off flag to `git commit`. See https://github.com/apps/dco for more information.

    - If the PR adds or changes a behaviour or fixes a bug of an exported API it would need a unit/e2e test.

    - Where possible use only exported APIs for tests to simplify the review and make it as close as possible to an actual library usage.

    - No tests are needed for internal implementation changes.

    - Performance improvements would need a benchmark test to prove it.

    - All exposed objects should have a comment.

    - All comments should start with a capital letter and end with a full stop.
 -->

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index eb867d804..c8216eebc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,27 @@
 # Changelog
 
+## 2.42.0 / 2023-01-31
+
+This release comes with a bunch of feature coverage for native histograms and breaking changes.
+
+If you are trying native histograms already, we recommend you remove the `wal` directory when upgrading.
+Because the old WAL record for native histograms is not backward compatible in v2.42.0, this will lead to some data loss for the latest data.
+
+Additionally, if you scrape "float histograms" or use recording rules on native histograms in v2.42.0 (which writes float histograms),
+it is a one-way street since older versions do not support float histograms.
+
+* [CHANGE] **breaking** TSDB: Changed WAL record format for the experimental native histograms. #11783
+* [FEATURE] Add 'keep_firing_for' field to alerting rules. #11827
+* [FEATURE] Promtool: Add support of selecting timeseries for TSDB dump. #11872
+* [ENHANCEMENT] Agent: Native histogram support. #11842
+* [ENHANCEMENT] Rules: Support native histograms in recording rules. #11838
+* [ENHANCEMENT] SD: Add container ID as a meta label for pod targets for Kubernetes. #11844
+* [ENHANCEMENT] SD: Add VM size label to azure service discovery. #11650
+* [ENHANCEMENT] Support native histograms in federation. #11830
+* [ENHANCEMENT] TSDB: Add gauge histogram support. #11783 #11840 #11814
+* [ENHANCEMENT] TSDB/Scrape: Support FloatHistogram that represents buckets as float64 values. #11522 #11817 #11716
+* [ENHANCEMENT] UI: Show individual scrape pools on /targets page. #11142
+
 ## 2.41.0 / 2022-12-20
 
 * [FEATURE] Relabeling: Add `keepequal` and `dropequal` relabel actions. #11564
@@ -61,7 +83,7 @@ Your existing histograms won't switch to native histograms until `NativeHistogra
 * [ENHANCEMENT] Kubernetes SD: Use protobuf encoding. #11353
 * [ENHANCEMENT] TSDB: Use golang.org/x/exp/slices for improved sorting speed. #11054 #11318 #11380
 * [ENHANCEMENT] Consul SD: Add enterprise admin partitions. Adds `__meta_consul_partition` label. Adds `partition` config in `consul_sd_config`. #11482
-* [BUGFIX] API: Fix API error codes for `/api/v1/labels` and `/api/v1/series`. #11356 
+* [BUGFIX] API: Fix API error codes for `/api/v1/labels` and `/api/v1/series`. #11356
 
 ## 2.39.2 / 2022-11-09
 
diff --git a/VERSION b/VERSION
index 2d4c52ede..345a83ee2 100644
--- a/VERSION
+++ b/VERSION
@@ -1,1 +1,1 @@
-2.41.0
+2.42.0
diff --git a/docs/querying/api.md b/docs/querying/api.md
index f2182a205..53d12052c 100644
--- a/docs/querying/api.md
+++ b/docs/querying/api.md
@@ -449,7 +449,9 @@ raw numbers.
 
 The keys `"histogram"` and `"histograms"` only show up if the experimental
 native histograms are present in the response. Their placeholder `<histogram>`
-is explained in detail in its own section below. 
+is explained in detail in its own section below. Any one object will only have
+the `"value"`/`"values"` key or the `"histogram"`/`"histograms"` key, but not
+both.
 
 ### Range vectors
 
@@ -467,9 +469,6 @@ Range vectors are returned as result type `matrix`. The corresponding
 ]
 ```
 
-Each series could have the `"values"` key, or the `"histograms"` key, or both. 
-For a given timestamp, there will only be one sample of either float or histogram type.
-
 ### Instant vectors
 
 Instant vectors are returned as result type `vector`. The corresponding
@@ -486,8 +485,6 @@ Instant vectors are returned as result type `vector`. The corresponding
 ]
 ```
 
-Each series could have the `"value"` key, or the `"histogram"` key, but not both.
-
 ### Scalars
 
 Scalar results are returned as result type `scalar`. The corresponding
diff --git a/tsdb/head_wal.go b/tsdb/head_wal.go
index f2ef4c1e0..708541364 100644
--- a/tsdb/head_wal.go
+++ b/tsdb/head_wal.go
@@ -498,12 +498,6 @@ func (h *Head) resetSeriesWithMMappedChunks(mSeries *memSeries, mmc, oooMmc []*m
 	h.metrics.chunksCreated.Add(float64(len(mmc) + len(oooMmc)))
 	h.metrics.chunksRemoved.Add(float64(len(mSeries.mmappedChunks)))
 	h.metrics.chunks.Add(float64(len(mmc) + len(oooMmc) - len(mSeries.mmappedChunks)))
-
-	if mSeries.ooo != nil {
-		h.metrics.chunksRemoved.Add(float64(len(mSeries.ooo.oooMmappedChunks)))
-		h.metrics.chunks.Sub(float64(len(mSeries.ooo.oooMmappedChunks)))
-	}
-
 	mSeries.mmappedChunks = mmc
 	if len(oooMmc) == 0 {
 		mSeries.ooo = nil
diff --git a/web/api/v1/api.go b/web/api/v1/api.go
index 7c4ef1908..f560693d4 100644
--- a/web/api/v1/api.go
+++ b/web/api/v1/api.go
@@ -63,10 +63,6 @@ type status string
 const (
 	statusSuccess status = "success"
 	statusError   status = "error"
-
-	// Non-standard status code (originally introduced by nginx) for the case when a client closes
-	// the connection while the server is still processing the request.
-	statusClientClosedConnection = 499
 )
 
 type errorType string
@@ -597,10 +593,6 @@ func returnAPIError(err error) *apiError {
 		return &apiError{errorInternal, err}
 	}
 
-	if errors.Is(err, context.Canceled) {
-		return &apiError{errorCanceled, err}
-	}
-
 	return &apiError{errorExec, err}
 }
 
@@ -1607,9 +1599,7 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter
 		code = http.StatusBadRequest
 	case errorExec:
 		code = http.StatusUnprocessableEntity
-	case errorCanceled:
-		code = statusClientClosedConnection
-	case errorTimeout:
+	case errorCanceled, errorTimeout:
 		code = http.StatusServiceUnavailable
 	case errorInternal:
 		code = http.StatusInternalServerError
diff --git a/web/ui/module/codemirror-promql/package.json b/web/ui/module/codemirror-promql/package.json
index 59518c083..dc6047095 100644
--- a/web/ui/module/codemirror-promql/package.json
+++ b/web/ui/module/codemirror-promql/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@prometheus-io/codemirror-promql",
-  "version": "0.41.0",
+  "version": "0.42.0",
   "description": "a CodeMirror mode for the PromQL language",
   "types": "dist/esm/index.d.ts",
   "module": "dist/esm/index.js",
@@ -29,7 +29,7 @@
   },
   "homepage": "https://github.com/prometheus/prometheus/blob/main/web/ui/module/codemirror-promql/README.md",
   "dependencies": {
-    "@prometheus-io/lezer-promql": "^0.41.0",
+    "@prometheus-io/lezer-promql": "^0.42.0",
     "lru-cache": "^6.0.0"
   },
   "devDependencies": {
diff --git a/web/ui/module/lezer-promql/package.json b/web/ui/module/lezer-promql/package.json
index 3f4486a15..ea5681970 100644
--- a/web/ui/module/lezer-promql/package.json
+++ b/web/ui/module/lezer-promql/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@prometheus-io/lezer-promql",
-  "version": "0.41.0",
+  "version": "0.42.0",
   "description": "lezer-based PromQL grammar",
   "main": "dist/index.cjs",
   "type": "module",
diff --git a/web/ui/package-lock.json b/web/ui/package-lock.json
index f243ab5ed..f602a2bab 100644
--- a/web/ui/package-lock.json
+++ b/web/ui/package-lock.json
@@ -28,10 +28,10 @@
     },
     "module/codemirror-promql": {
       "name": "@prometheus-io/codemirror-promql",
-      "version": "0.41.0",
+      "version": "0.42.0",
       "license": "Apache-2.0",
       "dependencies": {
-        "@prometheus-io/lezer-promql": "^0.41.0",
+        "@prometheus-io/lezer-promql": "^0.42.0",
         "lru-cache": "^6.0.0"
       },
       "devDependencies": {
@@ -61,7 +61,7 @@
     },
     "module/lezer-promql": {
       "name": "@prometheus-io/lezer-promql",
-      "version": "0.41.0",
+      "version": "0.42.0",
       "license": "Apache-2.0",
       "devDependencies": {
         "@lezer/generator": "^1.2.2",
@@ -20763,7 +20763,7 @@
     },
     "react-app": {
       "name": "@prometheus-io/app",
-      "version": "0.41.0",
+      "version": "0.42.0",
       "dependencies": {
         "@codemirror/autocomplete": "^6.4.0",
         "@codemirror/commands": "^6.2.0",
@@ -20781,7 +20781,7 @@
         "@lezer/lr": "^1.3.1",
         "@nexucis/fuzzy": "^0.4.1",
         "@nexucis/kvsearch": "^0.8.1",
-        "@prometheus-io/codemirror-promql": "^0.41.0",
+        "@prometheus-io/codemirror-promql": "^0.42.0",
         "bootstrap": "^4.6.2",
         "css.escape": "^1.5.1",
         "downshift": "^7.2.0",
@@ -23417,7 +23417,7 @@
         "@lezer/lr": "^1.3.1",
         "@nexucis/fuzzy": "^0.4.1",
         "@nexucis/kvsearch": "^0.8.1",
-        "@prometheus-io/codemirror-promql": "^0.41.0",
+        "@prometheus-io/codemirror-promql": "^0.42.0",
         "@testing-library/react-hooks": "^7.0.2",
         "@types/enzyme": "^3.10.12",
         "@types/flot": "0.0.32",
@@ -23468,7 +23468,7 @@
         "@lezer/common": "^1.0.2",
         "@lezer/highlight": "^1.1.3",
         "@lezer/lr": "^1.3.1",
-        "@prometheus-io/lezer-promql": "^0.41.0",
+        "@prometheus-io/lezer-promql": "^0.42.0",
         "@types/lru-cache": "^5.1.1",
         "isomorphic-fetch": "^3.0.0",
         "lru-cache": "^6.0.0",
diff --git a/web/ui/react-app/package.json b/web/ui/react-app/package.json
index ab902592d..ed8612658 100644
--- a/web/ui/react-app/package.json
+++ b/web/ui/react-app/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@prometheus-io/app",
-  "version": "0.41.0",
+  "version": "0.42.0",
   "private": true,
   "dependencies": {
     "@codemirror/autocomplete": "^6.4.0",
@@ -19,7 +19,7 @@
     "@lezer/common": "^1.0.2",
     "@nexucis/fuzzy": "^0.4.1",
     "@nexucis/kvsearch": "^0.8.1",
-    "@prometheus-io/codemirror-promql": "^0.41.0",
+    "@prometheus-io/codemirror-promql": "^0.42.0",
     "bootstrap": "^4.6.2",
     "css.escape": "^1.5.1",
     "downshift": "^7.2.0",


Test patch:
diff --git a/web/api/v1/errors_test.go b/web/api/v1/errors_test.go
index da0d4b3f2..c86ceb1c9 100644
--- a/web/api/v1/errors_test.go
+++ b/web/api/v1/errors_test.go
@@ -58,7 +58,7 @@ func TestApiStatusCodes(t *testing.T) {
 		"promql.ErrQueryCanceled": {
 			err:            promql.ErrQueryCanceled("some error"),
 			expectedString: "query was canceled",
-			expectedCode:   statusClientClosedConnection,
+			expectedCode:   http.StatusServiceUnavailable,
 		},
 
 		"promql.ErrQueryTimeout": {
@@ -76,7 +76,7 @@ func TestApiStatusCodes(t *testing.T) {
 		"context.Canceled": {
 			err:            context.Canceled,
 			expectedString: "context canceled",
-			expectedCode:   statusClientClosedConnection,
+			expectedCode:   http.StatusUnprocessableEntity,
 		},
 	} {
 		for k, q := range map[string]storage.SampleAndChunkQueryable{