From 5198eac6f425ce094115638cfaace0560782c66b Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 9 Dec 2022 11:04:13 +0100 Subject: [PATCH 1/4] Release 2.40.6 with security fixes Signed-off-by: Julien Pivotto --- CHANGELOG.md | 5 +++++ VERSION | 2 +- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- web/ui/module/codemirror-promql/package.json | 4 ++-- web/ui/module/lezer-promql/package.json | 2 +- web/ui/package-lock.json | 14 +++++++------- web/ui/react-app/package.json | 4 ++-- 8 files changed, 33 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dba2e19dc..0710227099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.40.6 / 2022-12-09 + +* [SECURITY] Security upgrade from go and upstream dependencies that include + security fixes to the net/http and os packages. #11691 + ## 2.40.5 / 2022-12-01 * [BUGFIX] TSDB: Fix queries involving native histograms due to improper reset of iterators. #11643 diff --git a/VERSION b/VERSION index 0644c8fe66..ad572faeb4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.40.5 +2.40.6 diff --git a/go.mod b/go.mod index e1ee2751a0..5fccf86fed 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/prometheus/alertmanager v0.24.0 github.com/prometheus/client_golang v1.13.1 github.com/prometheus/client_model v0.3.0 - github.com/prometheus/common v0.37.0 + github.com/prometheus/common v0.37.1 github.com/prometheus/common/assets v0.2.0 github.com/prometheus/common/sigv4 v0.1.0 github.com/prometheus/exporter-toolkit v0.8.2 @@ -61,10 +61,10 @@ require ( go.uber.org/atomic v1.10.0 go.uber.org/automaxprocs v1.5.1 go.uber.org/goleak v1.2.0 - golang.org/x/net v0.1.0 + golang.org/x/net v0.4.0 golang.org/x/oauth2 v0.1.0 golang.org/x/sync v0.1.0 - golang.org/x/sys v0.1.0 + golang.org/x/sys v0.3.0 golang.org/x/time v0.1.0 golang.org/x/tools v0.2.0 google.golang.org/api v0.102.0 @@ -175,8 +175,8 @@ require ( golang.org/x/crypto v0.1.0 // indirect golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 golang.org/x/mod v0.6.0 // indirect - golang.org/x/term v0.1.0 // indirect - golang.org/x/text v0.4.0 // indirect + golang.org/x/term v0.3.0 // indirect + golang.org/x/text v0.5.0 // indirect google.golang.org/appengine v1.6.7 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 8cac275fb8..8fefa97cf4 100644 --- a/go.sum +++ b/go.sum @@ -697,8 +697,8 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8 github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= -github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE= -github.com/prometheus/common v0.37.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA= +github.com/prometheus/common v0.37.1 h1:pYY6b5sGXqEB0WwcRGAoVGKbxVthy9qF17R4gbHZVe0= +github.com/prometheus/common v0.37.1/go.mod h1:jEuMeTn4pKGSAxwr7rXtOD70GeY0ERpt0d9FkKf9sK4= github.com/prometheus/common/assets v0.2.0 h1:0P5OrzoHrYBOSM1OigWL3mY8ZvV2N4zIE/5AahrSrfM= github.com/prometheus/common/assets v0.2.0/go.mod h1:D17UVUE12bHbim7HzwUvtqm6gwBEaDQ0F+hIGbFbccI= github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4= @@ -977,8 +977,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220907135653-1e95f45603a7/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU= +golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1084,13 +1084,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908150016-7ac13a9a928d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.1.0 h1:g6Z6vPFA9dYBAF7DWcH6sCcOntplXsDKcliusYijMlw= -golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= +golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1100,8 +1100,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= +golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/web/ui/module/codemirror-promql/package.json b/web/ui/module/codemirror-promql/package.json index 7eab09449d..1b86f596fe 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.40.5", + "version": "0.40.6", "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.40.5", + "@prometheus-io/lezer-promql": "^0.40.6", "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 0ffb9e5f76..b429732a76 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.40.5", + "version": "0.40.6", "description": "lezer-based PromQL grammar", "main": "index.cjs", "type": "module", diff --git a/web/ui/package-lock.json b/web/ui/package-lock.json index bc5b81c6ec..3b3eedd5c9 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.40.5", + "version": "0.40.6", "license": "Apache-2.0", "dependencies": { - "@prometheus-io/lezer-promql": "^0.40.5", + "@prometheus-io/lezer-promql": "^0.40.6", "lru-cache": "^6.0.0" }, "devDependencies": { @@ -61,7 +61,7 @@ }, "module/lezer-promql": { "name": "@prometheus-io/lezer-promql", - "version": "0.40.5", + "version": "0.40.6", "license": "Apache-2.0", "devDependencies": { "@lezer/generator": "^1.1.1", @@ -17625,7 +17625,7 @@ }, "react-app": { "name": "@prometheus-io/app", - "version": "0.40.5", + "version": "0.40.6", "dependencies": { "@codemirror/autocomplete": "^6.2.0", "@codemirror/commands": "^6.1.0", @@ -17643,7 +17643,7 @@ "@lezer/lr": "^1.2.3", "@nexucis/fuzzy": "^0.4.1", "@nexucis/kvsearch": "^0.8.1", - "@prometheus-io/codemirror-promql": "^0.40.5", + "@prometheus-io/codemirror-promql": "^0.40.6", "bootstrap": "^4.6.2", "css.escape": "^1.5.1", "downshift": "^6.1.11", @@ -19883,7 +19883,7 @@ "@lezer/lr": "^1.2.3", "@nexucis/fuzzy": "^0.4.1", "@nexucis/kvsearch": "^0.8.1", - "@prometheus-io/codemirror-promql": "^0.40.5", + "@prometheus-io/codemirror-promql": "^0.40.6", "@testing-library/react-hooks": "^7.0.2", "@types/enzyme": "^3.10.12", "@types/flot": "0.0.32", @@ -19935,7 +19935,7 @@ "@lezer/common": "^1.0.1", "@lezer/highlight": "^1.1.0", "@lezer/lr": "^1.2.3", - "@prometheus-io/lezer-promql": "^0.40.5", + "@prometheus-io/lezer-promql": "^0.40.6", "@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 f1b5edca67..0f2437a099 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.40.5", + "version": "0.40.6", "private": true, "dependencies": { "@codemirror/autocomplete": "^6.2.0", @@ -19,7 +19,7 @@ "@lezer/common": "^1.0.1", "@nexucis/fuzzy": "^0.4.1", "@nexucis/kvsearch": "^0.8.1", - "@prometheus-io/codemirror-promql": "^0.40.5", + "@prometheus-io/codemirror-promql": "^0.40.6", "bootstrap": "^4.6.2", "css.escape": "^1.5.1", "downshift": "^6.1.11", From 5f366e9b62b81a8c289d3d4fc821a30ff839b47c Mon Sep 17 00:00:00 2001 From: beorn7 Date: Sun, 11 Dec 2022 23:39:53 +0100 Subject: [PATCH 2/4] histograms: Improve tests and fix exposed bugs This adds negative buckets and access of float histograms to TestHistogramChunkSameBuckets and TestHistogramChunkBucketChanges. It also exercises a specific pattern of reusing an iterator (one where no access has happened). This exposes two bugs (where entries for positive buckets where used where the corresponding entries for negative buckets should have been used). One was fixed in #11627 (not merged), which triggered the work in this commit. This commit fixes both issues, so #11627 can be closed. It also simplifies the code in the histogramIterator.Next method that aims to recycle existing slice capacity. Furthermore, this is on top of the release-2.40 branch because we should probably cut a bugfix release for this. Signed-off-by: beorn7 --- tsdb/chunkenc/histogram.go | 39 +++------- tsdb/chunkenc/histogram_test.go | 132 +++++++++++++++++++++----------- 2 files changed, 96 insertions(+), 75 deletions(-) diff --git a/tsdb/chunkenc/histogram.go b/tsdb/chunkenc/histogram.go index e57b96db90..5aad382b2b 100644 --- a/tsdb/chunkenc/histogram.go +++ b/tsdb/chunkenc/histogram.go @@ -176,7 +176,7 @@ func newHistogramIterator(b []byte) *histogramIterator { } func (c *HistogramChunk) iterator(it Iterator) *histogramIterator { - // This commet is copied from XORChunk.iterator: + // This comment is copied from XORChunk.iterator: // Should iterators guarantee to act on a copy of the data so it doesn't lock append? // When using striped locks to guard access to chunks, probably yes. // Could only copy data if the chunk is not completed yet. @@ -651,7 +651,7 @@ func (it *histogramIterator) Reset(b []byte) { } it.pBucketsDelta = it.pBucketsDelta[:0] - it.pBucketsDelta = it.pBucketsDelta[:0] + it.nBucketsDelta = it.nBucketsDelta[:0] it.sum = 0 it.leading = 0 @@ -677,36 +677,17 @@ func (it *histogramIterator) Next() ValueType { it.zThreshold = zeroThreshold it.pSpans, it.nSpans = posSpans, negSpans numPBuckets, numNBuckets := countSpans(posSpans), countSpans(negSpans) - // Allocate bucket slices as needed, recycling existing slices - // in case this iterator was reset and already has slices of a - // sufficient capacity. + // The code below recycles existing slices in case this iterator + // was reset and already has slices of a sufficient capacity. if numPBuckets > 0 { - if cap(it.pBuckets) < numPBuckets { - it.pBuckets = make([]int64, numPBuckets) - // If cap(it.pBuckets) isn't sufficient, neither is the cap of the others. - it.pBucketsDelta = make([]int64, numPBuckets) - it.pFloatBuckets = make([]float64, numPBuckets) - } else { - for i := 0; i < numPBuckets; i++ { - it.pBuckets = append(it.pBuckets, 0) - it.pBucketsDelta = append(it.pBucketsDelta, 0) - it.pFloatBuckets = append(it.pFloatBuckets, 0) - } - } + it.pBuckets = append(it.pBuckets, make([]int64, numPBuckets)...) + it.pBucketsDelta = append(it.pBucketsDelta, make([]int64, numPBuckets)...) + it.pFloatBuckets = append(it.pFloatBuckets, make([]float64, numPBuckets)...) } if numNBuckets > 0 { - if cap(it.nBuckets) < numNBuckets { - it.nBuckets = make([]int64, numNBuckets) - // If cap(it.nBuckets) isn't sufficient, neither is the cap of the others. - it.nBucketsDelta = make([]int64, numNBuckets) - it.nFloatBuckets = make([]float64, numNBuckets) - } else { - for i := 0; i < numNBuckets; i++ { - it.nBuckets = append(it.nBuckets, 0) - it.nBucketsDelta = append(it.nBucketsDelta, 0) - it.pFloatBuckets = append(it.pFloatBuckets, 0) - } - } + it.nBuckets = append(it.nBuckets, make([]int64, numNBuckets)...) + it.nBucketsDelta = append(it.nBucketsDelta, make([]int64, numNBuckets)...) + it.nFloatBuckets = append(it.nFloatBuckets, make([]float64, numNBuckets)...) } // Now read the actual data. diff --git a/tsdb/chunkenc/histogram_test.go b/tsdb/chunkenc/histogram_test.go index 09c08ae3c3..59483f86f3 100644 --- a/tsdb/chunkenc/histogram_test.go +++ b/tsdb/chunkenc/histogram_test.go @@ -21,9 +21,15 @@ import ( "github.com/prometheus/prometheus/model/histogram" ) +type result struct { + t int64 + h *histogram.Histogram + fh *histogram.FloatHistogram +} + func TestHistogramChunkSameBuckets(t *testing.T) { c := NewHistogramChunk() - var exp []res + var exp []result // Create fresh appender and add the first histogram. app, err := c.Appender() @@ -32,7 +38,7 @@ func TestHistogramChunkSameBuckets(t *testing.T) { ts := int64(1234567890) h := &histogram.Histogram{ - Count: 5, + Count: 15, ZeroCount: 2, Sum: 18.4, ZeroThreshold: 1e-100, @@ -42,20 +48,26 @@ func TestHistogramChunkSameBuckets(t *testing.T) { {Offset: 1, Length: 2}, }, PositiveBuckets: []int64{1, 1, -1, 0}, // counts: 1, 2, 1, 1 (total 5) + NegativeSpans: []histogram.Span{ + {Offset: 1, Length: 1}, + {Offset: 2, Length: 3}, + }, + NegativeBuckets: []int64{2, 1, -1, -1}, // counts: 2, 3, 2, 1 (total 8) } app.AppendHistogram(ts, h) - exp = append(exp, res{t: ts, h: h}) + exp = append(exp, result{t: ts, h: h, fh: h.ToFloat()}) require.Equal(t, 1, c.NumSamples()) // Add an updated histogram. ts += 16 h = h.Copy() - h.Count += 9 + h.Count = 32 h.ZeroCount++ h.Sum = 24.4 h.PositiveBuckets = []int64{5, -2, 1, -2} // counts: 5, 3, 4, 2 (total 14) + h.NegativeBuckets = []int64{4, -1, 1, -1} // counts: 4, 3, 4, 4 (total 15) app.AppendHistogram(ts, h) - exp = append(exp, res{t: ts, h: h}) + exp = append(exp, result{t: ts, h: h, fh: h.ToFloat()}) require.Equal(t, 2, c.NumSamples()) // Add update with new appender. @@ -64,59 +76,77 @@ func TestHistogramChunkSameBuckets(t *testing.T) { ts += 14 h = h.Copy() - h.Count += 13 + h.Count = 54 h.ZeroCount += 2 h.Sum = 24.4 h.PositiveBuckets = []int64{6, 1, -3, 6} // counts: 6, 7, 4, 10 (total 27) + h.NegativeBuckets = []int64{5, 1, -2, 3} // counts: 5, 6, 4, 7 (total 22) app.AppendHistogram(ts, h) - exp = append(exp, res{t: ts, h: h}) + exp = append(exp, result{t: ts, h: h, fh: h.ToFloat()}) require.Equal(t, 3, c.NumSamples()) // 1. Expand iterator in simple case. - it := c.iterator(nil) + it := c.Iterator(nil) require.NoError(t, it.Err()) - var act []res + var act []result for it.Next() == ValHistogram { ts, h := it.AtHistogram() - act = append(act, res{t: ts, h: h}) + fts, fh := it.AtFloatHistogram() + require.Equal(t, ts, fts) + act = append(act, result{t: ts, h: h, fh: fh}) } require.NoError(t, it.Err()) require.Equal(t, exp, act) // 2. Expand second iterator while reusing first one. it2 := c.Iterator(it) - var res2 []res + var act2 []result for it2.Next() == ValHistogram { ts, h := it2.AtHistogram() - res2 = append(res2, res{t: ts, h: h}) + fts, fh := it2.AtFloatHistogram() + require.Equal(t, ts, fts) + act2 = append(act2, result{t: ts, h: h, fh: fh}) } require.NoError(t, it2.Err()) - require.Equal(t, exp, res2) + require.Equal(t, exp, act2) - // 3. Test iterator Seek. - // mid := len(exp) / 2 - - // it3 := c.Iterator(nil) - // var res3 []pair - // require.Equal(t, true, it3.Seek(exp[mid].t)) + // 3. Now recycle an iterator that was never used to access anything. + itX := c.Iterator(nil) + for itX.Next() == ValHistogram { + // Just iterate through without accessing anything. + } + it3 := c.iterator(itX) + var act3 []result + for it3.Next() == ValHistogram { + ts, h := it3.AtHistogram() + fts, fh := it3.AtFloatHistogram() + require.Equal(t, ts, fts) + act3 = append(act3, result{t: ts, h: h, fh: fh}) + } + require.NoError(t, it3.Err()) + require.Equal(t, exp, act3) + + // 4. Test iterator Seek. + mid := len(exp) / 2 + it4 := c.Iterator(nil) + var act4 []result + require.Equal(t, ValHistogram, it4.Seek(exp[mid].t)) // Below ones should not matter. - // require.Equal(t, true, it3.Seek(exp[mid].t)) - // require.Equal(t, true, it3.Seek(exp[mid].t)) - // ts, v = it3.At() - // res3 = append(res3, pair{t: ts, v: v}) - - // for it3.Next() { - // ts, v := it3.At() - // res3 = append(res3, pair{t: ts, v: v}) - // } - // require.NoError(t, it3.Err()) - // require.Equal(t, exp[mid:], res3) - // require.Equal(t, false, it3.Seek(exp[len(exp)-1].t+1)) -} - -type res struct { - t int64 - h *histogram.Histogram + require.Equal(t, ValHistogram, it4.Seek(exp[mid].t)) + require.Equal(t, ValHistogram, it4.Seek(exp[mid].t)) + ts, h = it4.AtHistogram() + fts, fh := it4.AtFloatHistogram() + require.Equal(t, ts, fts) + act4 = append(act4, result{t: ts, h: h, fh: fh}) + for it4.Next() == ValHistogram { + ts, h := it4.AtHistogram() + fts, fh := it4.AtFloatHistogram() + require.Equal(t, ts, fts) + act4 = append(act4, result{t: ts, h: h, fh: fh}) + } + require.NoError(t, it4.Err()) + require.Equal(t, exp[mid:], act4) + require.Equal(t, ValNone, it4.Seek(exp[len(exp)-1].t+1)) } // Mimics the scenario described for compareSpans(). @@ -130,7 +160,7 @@ func TestHistogramChunkBucketChanges(t *testing.T) { ts1 := int64(1234567890) h1 := &histogram.Histogram{ - Count: 5, + Count: 27, ZeroCount: 2, Sum: 18.4, ZeroThreshold: 1e-125, @@ -143,6 +173,8 @@ func TestHistogramChunkBucketChanges(t *testing.T) { {Offset: 1, Length: 1}, }, PositiveBuckets: []int64{6, -3, 0, -1, 2, 1, -4}, // counts: 6, 3, 3, 2, 4, 5, 1 (total 24) + NegativeSpans: []histogram.Span{{Offset: 1, Length: 1}}, + NegativeBuckets: []int64{1}, } app.AppendHistogram(ts1, h1) @@ -157,19 +189,23 @@ func TestHistogramChunkBucketChanges(t *testing.T) { {Offset: 1, Length: 4}, {Offset: 3, Length: 3}, } - h2.Count += 9 + h2.NegativeSpans = []histogram.Span{{Offset: 0, Length: 2}} + h2.Count = 35 h2.ZeroCount++ h2.Sum = 30 // Existing histogram should get values converted from the above to: // 6 3 0 3 0 0 2 4 5 0 1 (previous values with some new empty buckets in between) // so the new histogram should have new counts >= these per-bucket counts, e.g.: h2.PositiveBuckets = []int64{7, -2, -4, 2, -2, -1, 2, 3, 0, -5, 1} // 7 5 1 3 1 0 2 5 5 0 1 (total 30) - + // Existing histogram should get values converted from the above to: + // 0 1 (previous values with some new empty buckets in between) + // so the new histogram should have new counts >= these per-bucket counts, e.g.: + h2.NegativeBuckets = []int64{2, -1} // 2 1 (total 3) // This is how span changes will be handled. hApp, _ := app.(*HistogramAppender) posInterjections, negInterjections, ok, cr := hApp.Appendable(h2) require.Greater(t, len(posInterjections), 0) - require.Equal(t, 0, len(negInterjections)) + require.Greater(t, len(negInterjections), 0) require.True(t, ok) // Only new buckets came in. require.False(t, cr) c, app = hApp.Recode(posInterjections, negInterjections, h2.PositiveSpans, h2.NegativeSpans) @@ -182,21 +218,25 @@ func TestHistogramChunkBucketChanges(t *testing.T) { // metadata as well as the expanded buckets. h1.PositiveSpans = h2.PositiveSpans h1.PositiveBuckets = []int64{6, -3, -3, 3, -3, 0, 2, 2, 1, -5, 1} - exp := []res{ - {t: ts1, h: h1}, - {t: ts2, h: h2}, + h1.NegativeSpans = h2.NegativeSpans + h1.NegativeBuckets = []int64{0, 1} + exp := []result{ + {t: ts1, h: h1, fh: h1.ToFloat()}, + {t: ts2, h: h2, fh: h2.ToFloat()}, } it := c.Iterator(nil) - var act []res + var act []result for it.Next() == ValHistogram { ts, h := it.AtHistogram() - act = append(act, res{t: ts, h: h}) + fts, fh := it.AtFloatHistogram() + require.Equal(t, ts, fts) + act = append(act, result{t: ts, h: h, fh: fh}) } require.NoError(t, it.Err()) require.Equal(t, exp, act) } -func TestHistoChunkAppendable(t *testing.T) { +func TestHistogramChunkAppendable(t *testing.T) { c := Chunk(NewHistogramChunk()) // Create fresh appender and add the first histogram. From f113d58a57a889ac36c298f3099a91f5e777f848 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 9 Dec 2022 19:02:05 +0100 Subject: [PATCH 3/4] Do not build with netgo on Windows Fix #11480 Signed-off-by: Julien Pivotto --- .promu.yml | 8 +++++++- Makefile.common | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.promu.yml b/.promu.yml index 50c0be2575..233295f852 100644 --- a/.promu.yml +++ b/.promu.yml @@ -10,7 +10,13 @@ build: path: ./cmd/prometheus - name: promtool path: ./cmd/promtool - flags: -a -tags netgo,builtinassets + tags: + all: + - netgo + - builtinassets + windows: + - builtinassets + flags: -a ldflags: | -X github.com/prometheus/common/version.Version={{.Version}} -X github.com/prometheus/common/version.Revision={{.Revision}} diff --git a/Makefile.common b/Makefile.common index 7642c4485c..e358db69c5 100644 --- a/Makefile.common +++ b/Makefile.common @@ -55,7 +55,7 @@ ifneq ($(shell which gotestsum),) endif endif -PROMU_VERSION ?= 0.13.0 +PROMU_VERSION ?= 0.14.0 PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz SKIP_GOLANGCI_LINT := From 106d06a032b040428964f16182239b7dfd3f11f2 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 13 Dec 2022 13:06:55 +0100 Subject: [PATCH 4/4] Release 2.40.7 We have 2 bugfixes, one which is important for Windows users and another one on native histograms. I think it is worth cutting another bugfix release before 2.41 comes out. Signed-off-by: Julien Pivotto --- CHANGELOG.md | 5 +++++ VERSION | 2 +- web/ui/module/codemirror-promql/package.json | 4 ++-- web/ui/module/lezer-promql/package.json | 2 +- web/ui/package-lock.json | 14 +++++++------- web/ui/react-app/package.json | 4 ++-- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0710227099..e0f08c51c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.40.7 / 2022-12-14 + +* [BUGFIX] Use Windows native DNS resolver. #11704 +* [BUGFIX] TSDB: Fix queries involving negative buckets of native histograms. #11699 + ## 2.40.6 / 2022-12-09 * [SECURITY] Security upgrade from go and upstream dependencies that include diff --git a/VERSION b/VERSION index ad572faeb4..5c4c670b52 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.40.6 +2.40.7 diff --git a/web/ui/module/codemirror-promql/package.json b/web/ui/module/codemirror-promql/package.json index 1b86f596fe..b12e50ac60 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.40.6", + "version": "0.40.7", "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.40.6", + "@prometheus-io/lezer-promql": "^0.40.7", "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 b429732a76..e29f2c8d86 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.40.6", + "version": "0.40.7", "description": "lezer-based PromQL grammar", "main": "index.cjs", "type": "module", diff --git a/web/ui/package-lock.json b/web/ui/package-lock.json index 3b3eedd5c9..692ee34779 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.40.6", + "version": "0.40.7", "license": "Apache-2.0", "dependencies": { - "@prometheus-io/lezer-promql": "^0.40.6", + "@prometheus-io/lezer-promql": "^0.40.7", "lru-cache": "^6.0.0" }, "devDependencies": { @@ -61,7 +61,7 @@ }, "module/lezer-promql": { "name": "@prometheus-io/lezer-promql", - "version": "0.40.6", + "version": "0.40.7", "license": "Apache-2.0", "devDependencies": { "@lezer/generator": "^1.1.1", @@ -17625,7 +17625,7 @@ }, "react-app": { "name": "@prometheus-io/app", - "version": "0.40.6", + "version": "0.40.7", "dependencies": { "@codemirror/autocomplete": "^6.2.0", "@codemirror/commands": "^6.1.0", @@ -17643,7 +17643,7 @@ "@lezer/lr": "^1.2.3", "@nexucis/fuzzy": "^0.4.1", "@nexucis/kvsearch": "^0.8.1", - "@prometheus-io/codemirror-promql": "^0.40.6", + "@prometheus-io/codemirror-promql": "^0.40.7", "bootstrap": "^4.6.2", "css.escape": "^1.5.1", "downshift": "^6.1.11", @@ -19883,7 +19883,7 @@ "@lezer/lr": "^1.2.3", "@nexucis/fuzzy": "^0.4.1", "@nexucis/kvsearch": "^0.8.1", - "@prometheus-io/codemirror-promql": "^0.40.6", + "@prometheus-io/codemirror-promql": "^0.40.7", "@testing-library/react-hooks": "^7.0.2", "@types/enzyme": "^3.10.12", "@types/flot": "0.0.32", @@ -19935,7 +19935,7 @@ "@lezer/common": "^1.0.1", "@lezer/highlight": "^1.1.0", "@lezer/lr": "^1.2.3", - "@prometheus-io/lezer-promql": "^0.40.6", + "@prometheus-io/lezer-promql": "^0.40.7", "@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 0f2437a099..5a17ac4167 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.40.6", + "version": "0.40.7", "private": true, "dependencies": { "@codemirror/autocomplete": "^6.2.0", @@ -19,7 +19,7 @@ "@lezer/common": "^1.0.1", "@nexucis/fuzzy": "^0.4.1", "@nexucis/kvsearch": "^0.8.1", - "@prometheus-io/codemirror-promql": "^0.40.6", + "@prometheus-io/codemirror-promql": "^0.40.7", "bootstrap": "^4.6.2", "css.escape": "^1.5.1", "downshift": "^6.1.11",