Skip to content

Commit

Permalink
Cherry-pick bugfix prometheus#12322 and create v2.43.1+stringlabels
Browse files Browse the repository at this point in the history
* labels: respect Set after Del in Builder (prometheus#12322)

The implementations are not symmetric between `Set()` and `Del()`, so
we must be careful. Add tests for this, both in labels and in relabel
where the issue was reported.

Also make the slice implementation consistent re `slices.Contains`.

* Create v2.43.1 with bugfix

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
  • Loading branch information
2 people authored and roidelapluie committed May 4, 2023
1 parent d8ec24a commit c4ced4a
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 21 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 2.43.1+stringlabels / 2023-05-04

Special release build that incorporates performance improvements using
the stringlabels Go tag. This release aims to provide a more efficient and
faster solution for users managing large-scale deployments or facing performance
issues with the default Prometheus binaries.

The new labels data structure replaces the existing label/value storage with a
single string, reducing heap size and improving performance in most cases. It
enables Prometheus to use fewer system resources, particularly in
memory-intensive environments.

## 2.43.1 / 2023-05-03

* [BUGFIX] Labels: `Set()` after `Del()` would be ignored, which broke some relabeling rules. #12322

## 2.43.0+stringlabels / 2023-03-21

Special release build that incorporates performance improvements using
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.43.0+stringlabels
2.43.1+stringlabels
9 changes: 4 additions & 5 deletions model/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,16 +531,15 @@ func (b *Builder) Set(n, v string) *Builder {
}

func (b *Builder) Get(n string) string {
for _, d := range b.del {
if d == n {
return ""
}
}
// Del() removes entries from .add but Set() does not remove from .del, so check .add first.
for _, a := range b.add {
if a.Name == n {
return a.Value
}
}
if slices.Contains(b.del, n) {
return ""
}
return b.base.Get(n)
}

Expand Down
7 changes: 4 additions & 3 deletions model/labels/labels_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,15 @@ func (b *Builder) Set(n, v string) *Builder {
}

func (b *Builder) Get(n string) string {
if slices.Contains(b.del, n) {
return ""
}
// Del() removes entries from .add but Set() does not remove from .del, so check .add first.
for _, a := range b.add {
if a.Name == n {
return a.Value
}
}
if slices.Contains(b.del, n) {
return ""
}
return b.base.Get(n)
}

Expand Down
7 changes: 7 additions & 0 deletions model/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,13 @@ func TestBuilder(t *testing.T) {
require.Equal(t, tcase.want.BytesWithoutLabels(nil, "aaa", "bbb"), b.Labels(tcase.base).Bytes(nil))
})
}
t.Run("set_after_del", func(t *testing.T) {
b := NewBuilder(FromStrings("aaa", "111"))
b.Del("bbb")
b.Set("bbb", "222")
require.Equal(t, FromStrings("aaa", "111", "bbb", "222"), b.Labels(EmptyLabels()))
require.Equal(t, "222", b.Get("bbb"))
})
}

func TestScratchBuilder(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions model/relabel/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,34 @@ func TestRelabel(t *testing.T) {
"foo": "bar",
}),
},
{ // From https://github.com/prometheus/prometheus/issues/12283
input: labels.FromMap(map[string]string{
"__meta_kubernetes_pod_container_port_name": "foo",
"__meta_kubernetes_pod_annotation_XXX_metrics_port": "9091",
}),
relabel: []*Config{
{
Regex: MustNewRegexp("^__meta_kubernetes_pod_container_port_name$"),
Action: LabelDrop,
},
{
SourceLabels: model.LabelNames{"__meta_kubernetes_pod_annotation_XXX_metrics_port"},
Regex: MustNewRegexp("(.+)"),
Action: Replace,
Replacement: "metrics",
TargetLabel: "__meta_kubernetes_pod_container_port_name",
},
{
SourceLabels: model.LabelNames{"__meta_kubernetes_pod_container_port_name"},
Regex: MustNewRegexp("^metrics$"),
Action: Keep,
},
},
output: labels.FromMap(map[string]string{
"__meta_kubernetes_pod_annotation_XXX_metrics_port": "9091",
"__meta_kubernetes_pod_container_port_name": "metrics",
}),
},
{
input: labels.FromMap(map[string]string{
"a": "foo",
Expand Down
4 changes: 2 additions & 2 deletions web/ui/module/codemirror-promql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prometheus-io/codemirror-promql",
"version": "0.43.0",
"version": "0.43.1",
"description": "a CodeMirror mode for the PromQL language",
"types": "dist/esm/index.d.ts",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -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.43.0",
"@prometheus-io/lezer-promql": "0.43.1",
"lru-cache": "^6.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion web/ui/module/lezer-promql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prometheus-io/lezer-promql",
"version": "0.43.0",
"version": "0.43.1",
"description": "lezer-based PromQL grammar",
"main": "dist/index.cjs",
"type": "module",
Expand Down
14 changes: 7 additions & 7 deletions web/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions web/ui/react-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prometheus-io/app",
"version": "0.43.0",
"version": "0.43.1",
"private": true,
"dependencies": {
"@codemirror/autocomplete": "^6.4.0",
Expand All @@ -19,7 +19,7 @@
"@lezer/common": "^1.0.2",
"@nexucis/fuzzy": "^0.4.1",
"@nexucis/kvsearch": "^0.8.1",
"@prometheus-io/codemirror-promql": "0.43.0",
"@prometheus-io/codemirror-promql": "0.43.1",
"bootstrap": "^4.6.2",
"css.escape": "^1.5.1",
"downshift": "^7.2.0",
Expand Down

0 comments on commit c4ced4a

Please sign in to comment.