From e06d8556365dee571e0213cdc0f343ef7b202ab5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 12 Aug 2023 14:37:57 -0700 Subject: [PATCH 01/15] deployment/docker/Makefile: do not overwrite `latest` tag when pushing Docker images for LTS release The `latest` tag is reserved for the latest release --- deployment/docker/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/deployment/docker/Makefile b/deployment/docker/Makefile index b372cfc389..44e9cb4ecb 100644 --- a/deployment/docker/Makefile +++ b/deployment/docker/Makefile @@ -78,7 +78,6 @@ publish-via-docker: \ --build-arg root_image=$(ROOT_IMAGE) \ --build-arg APP_NAME=$(APP_NAME) \ --tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(RACE) \ - --tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(LATEST_TAG)$(RACE) \ -o type=image \ -f app/$(APP_NAME)/multiarch/Dockerfile \ --push \ From 7a19b2a14ca853e87873ee60d4fadad293f93d78 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 12 Aug 2023 15:30:13 -0700 Subject: [PATCH 02/15] docs/CHANGELOG.md: document that v1.93.x is a new line of LTS releases --- docs/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 750d9cde59..8a3f0dfb21 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -28,6 +28,9 @@ The following `tip` changes can be tested by building VictoriaMetrics components Released at 2023-08-12 +**v1.93.x is a line of LTS releases (e.g. long-time support). It contains important up-to-date bugfixes. +The v1.93.x line will be supported for at least 12 months since [v1.93.0](https://docs.victoriametrics.com/CHANGELOG.html#v1930) release** + **Update note**: starting from this release, [vmagent](https://docs.victoriametrics.com/vmagent.html) ignores timestamps provided by scrape targets by default - it associates scraped metrics with local timestamps instead. Set `honor_timestamps: true` in [scrape configs](https://docs.victoriametrics.com/sd_configs.html#scrape_configs) if timestamps provided by scrape targets must be used instead. This change helps removing gaps for metrics collected from [cadvisor](https://github.com/google/cadvisor) such as `container_memory_usage_bytes`. This also improves data compression and query performance over metrics collected from `cadvisor`. See more details [here](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4697). * SECURITY: upgrade Go builder from Go1.20.6 to Go1.21.0 in order to fix [this issue](https://github.com/golang/go/issues/61460). From a63fb21ab2db31b3c0fe11f4bc802650ac5ff3de Mon Sep 17 00:00:00 2001 From: Dmytro Kozlov Date: Wed, 16 Aug 2023 14:54:51 +0200 Subject: [PATCH 03/15] app/vmctl: fix migration process if tenant have no data (#4799) app/vmctl: don't interrupt migration process if tenant has no data Signed-off-by: hagen1778 Co-authored-by: Alexander Marshalov <_@marshalov.org> --- app/vmctl/vm_native.go | 7 ++++++- docs/CHANGELOG.md | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/vmctl/vm_native.go b/app/vmctl/vm_native.go index 8d94d2bbe1..31bdb6b380 100644 --- a/app/vmctl/vm_native.go +++ b/app/vmctl/vm_native.go @@ -201,7 +201,12 @@ func (p *vmNativeProcessor) runBackfilling(ctx context.Context, tenantID string, } if len(metrics) == 0 { - return fmt.Errorf("no metrics found") + errMsg := "no metrics found" + if tenantID != "" { + errMsg = fmt.Sprintf("%s for tenant id: %s", errMsg, tenantID) + } + log.Println(errMsg) + return nil } foundSeriesMsg = fmt.Sprintf("Found %d metrics to import", len(metrics)) } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8a3f0dfb21..b14751bc64 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,8 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## tip +* BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): don't interrupt the migration process if no metrics were found for a specific tenant. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4796). + ## [v1.93.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.0) Released at 2023-08-12 From b4529df08d3118b493c8a5916aaec7ca7d66009d Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Wed, 16 Aug 2023 14:45:35 +0200 Subject: [PATCH 04/15] vmbackup: correctly check if specified `-dst` belongs to specified `-storageDataPath` (#4841) See this issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837 Signed-off-by: hagen1778 --- app/vmbackup/main.go | 15 ++++++++++++++- app/vmbackup/main_test.go | 5 +++++ docs/CHANGELOG.md | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/vmbackup/main.go b/app/vmbackup/main.go index 06c9e475de..f42dfa73fc 100644 --- a/app/vmbackup/main.go +++ b/app/vmbackup/main.go @@ -205,7 +205,20 @@ func hasFilepathPrefix(path, prefix string) bool { if err != nil { return false } - return strings.HasPrefix(pathAbs, prefixAbs) + if prefixAbs == pathAbs { + return true + } + rel, err := filepath.Rel(prefixAbs, pathAbs) + if err != nil { + // if paths can't be related - they don't match + return false + } + if i := strings.Index(rel, "."); i == 0 { + // if path can be related only with . as first char - they still don't match + return false + } + // if paths are related - it is a match + return true } func newOriginFS() (common.OriginFS, error) { diff --git a/app/vmbackup/main_test.go b/app/vmbackup/main_test.go index f3288fb499..c1a87e51d3 100644 --- a/app/vmbackup/main_test.go +++ b/app/vmbackup/main_test.go @@ -26,4 +26,9 @@ func TestHasFilepathPrefix(t *testing.T) { f("fs://"+pwd+"/foo", pwd+"/foo/bar", false) f("fs://"+pwd+"/foo/bar", pwd+"/foo", true) f("fs://"+pwd+"/foo", pwd+"/bar", false) + f("fs:///data1", "/data", false) + f("fs:///data", "/data1", false) + f("fs:///data", "/data/foo", false) + f("fs:///data/foo", "/data", true) + f("fs:///data/foo/", "/data/", true) } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b14751bc64..af043aebd7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## tip +* BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): correctly check if specified `-dst` belongs to specified `-storageDataPath`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837). * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): don't interrupt the migration process if no metrics were found for a specific tenant. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4796). ## [v1.93.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.0) From b4c79fc60678d77b0d341a0254a075d578f04937 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 14 Aug 2023 16:14:40 +0200 Subject: [PATCH 05/15] lib/promrelabel: properly replace `:` char with `_` in metric names when -usePromCompatibleNaming command-line flag is set This addresses https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071 comment from @johnseekins --- app/vmagent/remotewrite/relabel.go | 4 ++-- app/vmctl/opentsdb/parser.go | 4 ++-- app/vminsert/relabel/relabel.go | 4 ++-- docs/CHANGELOG.md | 1 + lib/promrelabel/relabel.go | 25 ++++++++++++++++++------ lib/promrelabel/relabel_test.go | 22 ++++++++++++++++++--- lib/promrelabel/relabel_timing_test.go | 27 ++++++++++++++++++++++---- 7 files changed, 68 insertions(+), 19 deletions(-) diff --git a/app/vmagent/remotewrite/relabel.go b/app/vmagent/remotewrite/relabel.go index b1cfc16e69..146930f8d3 100644 --- a/app/vmagent/remotewrite/relabel.go +++ b/app/vmagent/remotewrite/relabel.go @@ -114,9 +114,9 @@ func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, extraLab for j := range tmpLabels { label := &tmpLabels[j] if label.Name == "__name__" { - label.Value = promrelabel.SanitizeName(label.Value) + label.Value = promrelabel.SanitizeMetricName(label.Value) } else { - label.Name = promrelabel.SanitizeName(label.Name) + label.Name = promrelabel.SanitizeLabelName(label.Name) } } } diff --git a/app/vmctl/opentsdb/parser.go b/app/vmctl/opentsdb/parser.go index 6993e8d13d..6c2f209e7a 100644 --- a/app/vmctl/opentsdb/parser.go +++ b/app/vmctl/opentsdb/parser.go @@ -180,7 +180,7 @@ func modifyData(msg Metric, normalize bool) (Metric, error) { /* replace bad characters in metric name with _ per the data model */ - finalMsg.Metric = promrelabel.SanitizeName(name) + finalMsg.Metric = promrelabel.SanitizeMetricName(name) // replace bad characters in tag keys with _ per the data model for key, value := range msg.Tags { // if normalization requested, lowercase the key and value @@ -191,7 +191,7 @@ func modifyData(msg Metric, normalize bool) (Metric, error) { /* replace all explicitly bad characters with _ */ - key = promrelabel.SanitizeName(key) + key = promrelabel.SanitizeLabelName(key) // tags that start with __ are considered custom stats for internal prometheus stuff, we should drop them if !strings.HasPrefix(key, "__") { finalMsg.Tags[key] = value diff --git a/app/vminsert/relabel/relabel.go b/app/vminsert/relabel/relabel.go index fcb107c24e..3409fb4c02 100644 --- a/app/vminsert/relabel/relabel.go +++ b/app/vminsert/relabel/relabel.go @@ -134,9 +134,9 @@ func (ctx *Ctx) ApplyRelabeling(labels []prompb.Label) []prompb.Label { for i := range tmpLabels { label := &tmpLabels[i] if label.Name == "__name__" { - label.Value = promrelabel.SanitizeName(label.Value) + label.Value = promrelabel.SanitizeMetricName(label.Value) } else { - label.Name = promrelabel.SanitizeName(label.Name) + label.Name = promrelabel.SanitizeLabelName(label.Name) } } } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index af043aebd7..e2858098dc 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## tip +* BUGFIX: properly replace `:` chars in label names with `_` when `-usePromCompatibleNaming` command-line flag is passed to `vmagent`, `vminsert` or single-node VictoriaMetrics. This addresses [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): correctly check if specified `-dst` belongs to specified `-storageDataPath`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837). * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): don't interrupt the migration process if no metrics were found for a specific tenant. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4796). diff --git a/lib/promrelabel/relabel.go b/lib/promrelabel/relabel.go index c6c17b4c96..e2d5d68da1 100644 --- a/lib/promrelabel/relabel.go +++ b/lib/promrelabel/relabel.go @@ -619,15 +619,28 @@ func fillLabelReferences(dst []byte, replacement string, labels []prompbmarshal. return dst } -// SanitizeName replaces unsupported by Prometheus chars in metric names and label names with _. +// SanitizeLabelName replaces unsupported by Prometheus chars in label names with _. // // See https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels -func SanitizeName(name string) string { - return promSanitizer.Transform(name) +func SanitizeLabelName(name string) string { + return labelNameSanitizer.Transform(name) } -var promSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { - return unsupportedPromChars.ReplaceAllString(s, "_") +var labelNameSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { + return unsupportedLabelNameChars.ReplaceAllString(s, "_") }) -var unsupportedPromChars = regexp.MustCompile(`[^a-zA-Z0-9_:]`) +var unsupportedLabelNameChars = regexp.MustCompile(`[^a-zA-Z0-9_]`) + +// SanitizeMetricName replaces unsupported by Prometheus chars in metric names with _. +// +// See https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels +func SanitizeMetricName(value string) string { + return metricNameSanitizer.Transform(value) +} + +var metricNameSanitizer = bytesutil.NewFastStringTransformer(func(s string) string { + return unsupportedMetricNameChars.ReplaceAllString(s, "_") +}) + +var unsupportedMetricNameChars = regexp.MustCompile(`[^a-zA-Z0-9_:]`) diff --git a/lib/promrelabel/relabel_test.go b/lib/promrelabel/relabel_test.go index 987374252c..df8080af48 100644 --- a/lib/promrelabel/relabel_test.go +++ b/lib/promrelabel/relabel_test.go @@ -9,13 +9,13 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" ) -func TestSanitizeName(t *testing.T) { +func TestSanitizeMetricName(t *testing.T) { f := func(s, resultExpected string) { t.Helper() for i := 0; i < 5; i++ { - result := SanitizeName(s) + result := SanitizeMetricName(s) if result != resultExpected { - t.Fatalf("unexpected result for SanitizeName(%q) at iteration %d; got %q; want %q", s, i, result, resultExpected) + t.Fatalf("unexpected result for SanitizeMetricName(%q) at iteration %d; got %q; want %q", s, i, result, resultExpected) } } } @@ -25,6 +25,22 @@ func TestSanitizeName(t *testing.T) { f("foo...bar", "foo___bar") } +func TestSanitizeLabelName(t *testing.T) { + f := func(s, resultExpected string) { + t.Helper() + for i := 0; i < 5; i++ { + result := SanitizeLabelName(s) + if result != resultExpected { + t.Fatalf("unexpected result for SanitizeLabelName(%q) at iteration %d; got %q; want %q", s, i, result, resultExpected) + } + } + } + f("", "") + f("a", "a") + f("foo.bar/baz:a", "foo_bar_baz_a") + f("foo...bar", "foo___bar") +} + func TestLabelsToString(t *testing.T) { f := func(labels []prompbmarshal.Label, sExpected string) { t.Helper() diff --git a/lib/promrelabel/relabel_timing_test.go b/lib/promrelabel/relabel_timing_test.go index 31682e787d..485002020c 100644 --- a/lib/promrelabel/relabel_timing_test.go +++ b/lib/promrelabel/relabel_timing_test.go @@ -8,20 +8,39 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal" ) -func BenchmarkSanitizeName(b *testing.B) { +func BenchmarkSanitizeMetricName(b *testing.B) { for _, name := range []string{"", "foo", "foo-bar-baz", "http_requests_total"} { b.Run(name, func(b *testing.B) { - benchmarkSanitizeName(b, name) + benchmarkSanitizeMetricName(b, name) }) } } -func benchmarkSanitizeName(b *testing.B, name string) { +func benchmarkSanitizeMetricName(b *testing.B, name string) { b.ReportAllocs() b.SetBytes(1) b.RunParallel(func(pb *testing.PB) { for pb.Next() { - sanitizedName := SanitizeName(name) + sanitizedName := SanitizeMetricName(name) + GlobalSink += len(sanitizedName) + } + }) +} + +func BenchmarkSanitizeLabelName(b *testing.B) { + for _, name := range []string{"", "foo", "foo-bar-baz", "http_requests_total"} { + b.Run(name, func(b *testing.B) { + benchmarkSanitizeLabelName(b, name) + }) + } +} + +func benchmarkSanitizeLabelName(b *testing.B, name string) { + b.ReportAllocs() + b.SetBytes(1) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + sanitizedName := SanitizeLabelName(name) GlobalSink += len(sanitizedName) } }) From c6154f8f52a48021b88dd4c0eb7a1f646ca0e6e1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 14 Aug 2023 15:10:00 +0200 Subject: [PATCH 06/15] lib/promrelabel: stop emitting DEBUG log lines when parsing `if` expressions These lines were accidentally left in the commit 62651570bb6142f94025266e9e65353f3d6c37e2 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4635 --- docs/CHANGELOG.md | 1 + lib/promrelabel/if_expression.go | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e2858098dc..473a0fb879 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## tip +* BUGFIX: remove `DEBUG` logging when parsing `if` filters inside [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements) and when parsing `match` filters inside [stream aggregation rules](https://docs.victoriametrics.com/stream-aggregation.html). * BUGFIX: properly replace `:` chars in label names with `_` when `-usePromCompatibleNaming` command-line flag is passed to `vmagent`, `vminsert` or single-node VictoriaMetrics. This addresses [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): correctly check if specified `-dst` belongs to specified `-storageDataPath`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837). * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl.html): don't interrupt the migration process if no metrics were found for a specific tenant. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4796). diff --git a/lib/promrelabel/if_expression.go b/lib/promrelabel/if_expression.go index 78519d3e8a..1f3506dfbb 100644 --- a/lib/promrelabel/if_expression.go +++ b/lib/promrelabel/if_expression.go @@ -80,7 +80,6 @@ func (ie *IfExpression) UnmarshalYAML(f func(interface{}) error) error { } func (ie *IfExpression) unmarshalFromInterface(v interface{}) error { - logger.Infof("DEBUG: unmarshaling ifExpr from %#v", v) ies := ie.ies[:0] switch t := v.(type) { case string: @@ -89,7 +88,6 @@ func (ie *IfExpression) unmarshalFromInterface(v interface{}) error { return fmt.Errorf("unexpected `match` option: %w", err) } ies = append(ies, ieLocal) - logger.Infof("DEBUG: unmarshaled ifExpr from %#v to %s", t, ieLocal) case []interface{}: for _, x := range t { s, ok := x.(string) @@ -102,7 +100,6 @@ func (ie *IfExpression) unmarshalFromInterface(v interface{}) error { } ies = append(ies, ieLocal) } - logger.Infof("DEBUG: unmarshaled ifExpr from %#v to %s", t, ies) default: return fmt.Errorf("unexpected `match` type; got %#v; want string or an array of strings", t) } From 4b86a181059d2d900c644ff02ad7de877b530435 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 17 Aug 2023 13:57:29 +0200 Subject: [PATCH 07/15] docs/CHANGELOG.md: mention that this is v1.93.x LTS release line --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 473a0fb879..3542d278e5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -22,7 +22,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components * [How to build vmctl](https://docs.victoriametrics.com/vmctl.html#how-to-build) -## tip +## v1.93.x long-time support release (LTS) * BUGFIX: remove `DEBUG` logging when parsing `if` filters inside [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements) and when parsing `match` filters inside [stream aggregation rules](https://docs.victoriametrics.com/stream-aggregation.html). * BUGFIX: properly replace `:` chars in label names with `_` when `-usePromCompatibleNaming` command-line flag is passed to `vmagent`, `vminsert` or single-node VictoriaMetrics. This addresses [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071). From d4123e135f070659463fff437dca75f2bd70d2d3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 17 Aug 2023 13:26:10 +0200 Subject: [PATCH 08/15] lib/envflag: do not allow unsupported form for boolean command-line flags in the form `-boolFlag value` Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4845 --- docs/CHANGELOG.md | 1 + lib/envflag/envflag.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3542d278e5..55dc470d3b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## v1.93.x long-time support release (LTS) +* BUGFIX: do not allow starting VictoriaMetrics components with improperly set boolean command-line flags in the form `-boolFlagName value`, since this leads to silent incomplete flags' parsing. This form should be replaced with `-boolFlagName=value`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4845). * BUGFIX: remove `DEBUG` logging when parsing `if` filters inside [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements) and when parsing `match` filters inside [stream aggregation rules](https://docs.victoriametrics.com/stream-aggregation.html). * BUGFIX: properly replace `:` chars in label names with `_` when `-usePromCompatibleNaming` command-line flag is passed to `vmagent`, `vminsert` or single-node VictoriaMetrics. This addresses [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): correctly check if specified `-dst` belongs to specified `-storageDataPath`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837). diff --git a/lib/envflag/envflag.go b/lib/envflag/envflag.go index ab2b3fd9ae..6603a127d6 100644 --- a/lib/envflag/envflag.go +++ b/lib/envflag/envflag.go @@ -32,6 +32,11 @@ func ParseFlagSet(fs *flag.FlagSet, args []string) { // Do not use lib/logger here, since it is uninitialized yet. log.Fatalf("cannot parse flags %q: %s", args, err) } + if fs.NArg() > 0 { + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4845 + log.Fatalf("unprocessed command-line args left: %s; the most likely reason is missing `=` between boolean flag name and value; "+ + "see https://pkg.go.dev/flag#hdr-Command_line_flag_syntax", fs.Args()) + } if !*enable { return } From 927ded6c3b82ba470c35fd4eada2f01383708b92 Mon Sep 17 00:00:00 2001 From: Alexander Marshalov <_@marshalov.org> Date: Tue, 15 Aug 2023 13:47:48 +0200 Subject: [PATCH 09/15] fixed applying `remoteWrite.label` for pushed metrics (#4247) (#4824) vmagent: properly add extra labels before sending data to remote storage labels from `remoteWrite.label` are now added to sent metrics just before they are pushed to `remoteWrite.url` after all relabelings, including stream aggregation relabelings (#4247) https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247 Signed-off-by: Alexander Marshalov <_@marshalov.org> Co-authored-by: Roman Khavronenko --- app/vmagent/remotewrite/relabel.go | 46 ++++++++++++++++++------- app/vmagent/remotewrite/relabel_test.go | 33 ++++++++++++++---- app/vmagent/remotewrite/remotewrite.go | 9 +++-- docs/CHANGELOG.md | 1 + docs/stream-aggregation.md | 14 ++++++-- 5 files changed, 80 insertions(+), 23 deletions(-) diff --git a/app/vmagent/remotewrite/relabel.go b/app/vmagent/remotewrite/relabel.go index 146930f8d3..b79021c64f 100644 --- a/app/vmagent/remotewrite/relabel.go +++ b/app/vmagent/remotewrite/relabel.go @@ -87,8 +87,8 @@ func initLabelsGlobal() { } } -func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, extraLabels []prompbmarshal.Label, pcs *promrelabel.ParsedConfigs) []prompbmarshal.TimeSeries { - if len(extraLabels) == 0 && pcs.Len() == 0 && !*usePromCompatibleNaming { +func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, pcs *promrelabel.ParsedConfigs) []prompbmarshal.TimeSeries { + if pcs.Len() == 0 && !*usePromCompatibleNaming { // Nothing to change. return tss } @@ -98,16 +98,6 @@ func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, extraLab ts := &tss[i] labelsLen := len(labels) labels = append(labels, ts.Labels...) - // extraLabels must be added before applying relabeling according to https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write - for j := range extraLabels { - extraLabel := &extraLabels[j] - tmp := promrelabel.GetLabelByName(labels[labelsLen:], extraLabel.Name) - if tmp != nil { - tmp.Value = extraLabel.Value - } else { - labels = append(labels, *extraLabel) - } - } if *usePromCompatibleNaming { // Replace unsupported Prometheus chars in label names and metric names with underscores. tmpLabels := labels[labelsLen:] @@ -135,6 +125,38 @@ func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, extraLab return tssDst } +func (rctx *relabelCtx) appendExtraLabels(tss []prompbmarshal.TimeSeries, extraLabels []prompbmarshal.Label) []prompbmarshal.TimeSeries { + if len(extraLabels) == 0 { + return tss + } + tssDst := tss[:0] + labels := rctx.labels[:0] + for i := range tss { + ts := &tss[i] + labelsLen := len(labels) + labels = append(labels, ts.Labels...) + for j := range extraLabels { + extraLabel := extraLabels[j] + if *usePromCompatibleNaming { + extraLabel.Name = promrelabel.SanitizeLabelName(extraLabel.Name) + } + tmp := promrelabel.GetLabelByName(labels[labelsLen:], extraLabel.Name) + if tmp != nil { + tmp.Value = extraLabel.Value + } else { + labels = append(labels, extraLabel) + } + } + labels = promrelabel.FinalizeLabels(labels[:labelsLen], labels[labelsLen:]) + tssDst = append(tssDst, prompbmarshal.TimeSeries{ + Labels: labels[labelsLen:], + Samples: ts.Samples, + }) + } + rctx.labels = labels + return tssDst +} + type relabelCtx struct { // pool for labels, which are used during the relabeling. labels []prompbmarshal.Label diff --git a/app/vmagent/remotewrite/relabel_test.go b/app/vmagent/remotewrite/relabel_test.go index eb35400021..441283f23b 100644 --- a/app/vmagent/remotewrite/relabel_test.go +++ b/app/vmagent/remotewrite/relabel_test.go @@ -10,18 +10,16 @@ import ( ) func TestApplyRelabeling(t *testing.T) { - f := func(extraLabels []prompbmarshal.Label, pcs *promrelabel.ParsedConfigs, sTss, sExpTss string) { + f := func(pcs *promrelabel.ParsedConfigs, sTss, sExpTss string) { rctx := &relabelCtx{} tss, expTss := parseSeries(sTss), parseSeries(sExpTss) - gotTss := rctx.applyRelabeling(tss, extraLabels, pcs) + gotTss := rctx.applyRelabeling(tss, pcs) if !reflect.DeepEqual(gotTss, expTss) { t.Fatalf("expected to have: \n%v;\ngot: \n%v", expTss, gotTss) } } - f(nil, nil, "up", "up") - f([]prompbmarshal.Label{{Name: "foo", Value: "bar"}}, nil, "up", `up{foo="bar"}`) - f([]prompbmarshal.Label{{Name: "foo", Value: "bar"}}, nil, `up{foo="baz"}`, `up{foo="bar"}`) + f(nil, "up", "up") pcs, err := promrelabel.ParseRelabelConfigsData([]byte(` - target_label: "foo" @@ -32,11 +30,32 @@ func TestApplyRelabeling(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %s", err) } - f(nil, pcs, `up{foo="baz", env="prod"}`, `up{foo="aaa"}`) + f(pcs, `up{foo="baz", env="prod"}`, `up{foo="aaa"}`) oldVal := *usePromCompatibleNaming *usePromCompatibleNaming = true - f(nil, nil, `foo.bar`, `foo_bar`) + f(nil, `foo.bar`, `foo_bar`) + *usePromCompatibleNaming = oldVal +} + +func TestAppendExtraLabels(t *testing.T) { + f := func(extraLabels []prompbmarshal.Label, sTss, sExpTss string) { + rctx := &relabelCtx{} + tss, expTss := parseSeries(sTss), parseSeries(sExpTss) + gotTss := rctx.appendExtraLabels(tss, extraLabels) + if !reflect.DeepEqual(gotTss, expTss) { + t.Fatalf("expected to have: \n%v;\ngot: \n%v", expTss, gotTss) + } + } + + f(nil, "up", "up") + f([]prompbmarshal.Label{{Name: "foo", Value: "bar"}}, "up", `up{foo="bar"}`) + f([]prompbmarshal.Label{{Name: "foo", Value: "bar"}}, `up{foo="baz"}`, `up{foo="bar"}`) + f([]prompbmarshal.Label{{Name: "baz", Value: "qux"}}, `up{foo="baz"}`, `up{foo="baz",baz="qux"}`) + + oldVal := *usePromCompatibleNaming + *usePromCompatibleNaming = true + f([]prompbmarshal.Label{{Name: "foo.bar", Value: "baz"}}, "up", `up{foo_bar="baz"}`) *usePromCompatibleNaming = oldVal } diff --git a/app/vmagent/remotewrite/remotewrite.go b/app/vmagent/remotewrite/remotewrite.go index 29099e1144..ac5681aa48 100644 --- a/app/vmagent/remotewrite/remotewrite.go +++ b/app/vmagent/remotewrite/remotewrite.go @@ -386,7 +386,7 @@ func Push(at *auth.Token, wr *prompbmarshal.WriteRequest) { } if rctx != nil { rowsCountBeforeRelabel := getRowsCount(tssBlock) - tssBlock = rctx.applyRelabeling(tssBlock, labelsGlobal, pcsGlobal) + tssBlock = rctx.applyRelabeling(tssBlock, pcsGlobal) rowsCountAfterRelabel := getRowsCount(tssBlock) rowsDroppedByGlobalRelabel.Add(rowsCountBeforeRelabel - rowsCountAfterRelabel) } @@ -668,7 +668,7 @@ func (rwctx *remoteWriteCtx) Push(tss []prompbmarshal.TimeSeries) { v = tssPool.Get().(*[]prompbmarshal.TimeSeries) tss = append(*v, tss...) rowsCountBeforeRelabel := getRowsCount(tss) - tss = rctx.applyRelabeling(tss, nil, pcs) + tss = rctx.applyRelabeling(tss, pcs) rowsCountAfterRelabel := getRowsCount(tss) rwctx.rowsDroppedByRelabel.Add(rowsCountBeforeRelabel - rowsCountAfterRelabel) } @@ -719,6 +719,11 @@ func dropAggregatedSeries(src []prompbmarshal.TimeSeries, matchIdxs []byte, drop } func (rwctx *remoteWriteCtx) pushInternal(tss []prompbmarshal.TimeSeries) { + if len(labelsGlobal) > 0 { + rctx := getRelabelCtx() + tss = rctx.appendExtraLabels(tss, labelsGlobal) + putRelabelCtx(rctx) + } pss := rwctx.pss idx := atomic.AddUint64(&rwctx.pssNextIdx, 1) % uint64(len(pss)) pss[idx].Push(tss) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 55dc470d3b..ae0934ab61 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,6 +25,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## v1.93.x long-time support release (LTS) * BUGFIX: do not allow starting VictoriaMetrics components with improperly set boolean command-line flags in the form `-boolFlagName value`, since this leads to silent incomplete flags' parsing. This form should be replaced with `-boolFlagName=value`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4845). +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): according to [the docs](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics) labels from `-remoteWrite.label` cmd-line flag are now added to the sent metrics just before they are pushed to the `-remoteWrite.url` (after all relabeling, including stream aggregation relabeling). In addition, it allows adding labels for identifying vmagent instances when using streaming aggregation in vmagents [cluster mode](https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247) and [these docs](https://docs.victoriametrics.com/stream-aggregation.html#cluster-mode) for more details. * BUGFIX: remove `DEBUG` logging when parsing `if` filters inside [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements) and when parsing `match` filters inside [stream aggregation rules](https://docs.victoriametrics.com/stream-aggregation.html). * BUGFIX: properly replace `:` chars in label names with `_` when `-usePromCompatibleNaming` command-line flag is passed to `vmagent`, `vminsert` or single-node VictoriaMetrics. This addresses [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): correctly check if specified `-dst` belongs to specified `-storageDataPath`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837). diff --git a/docs/stream-aggregation.md b/docs/stream-aggregation.md index 9be338bac3..eb01c9f64a 100644 --- a/docs/stream-aggregation.md +++ b/docs/stream-aggregation.md @@ -1,7 +1,7 @@ --- sort: 98 weight: 98 -title: streaming aggregation +title: Streaming aggregation menu: docs: parent: "victoriametrics" @@ -10,7 +10,7 @@ aliases: - /stream-aggregation.html --- -# streaming aggregation +# Streaming aggregation [vmagent](https://docs.victoriametrics.com/vmagent.html) and [single-node VictoriaMetrics](https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html) can aggregate incoming [samples](https://docs.victoriametrics.com/keyConcepts.html#raw-samples) in streaming mode by time and by labels before data is written to remote storage. @@ -673,3 +673,13 @@ support the following approaches for hot reloading stream aggregation configs fr ``` * By sending HTTP request to `/-/reload` endpoint (e.g. `http://vmagent:8429/-/reload` or `http://victoria-metrics:8428/-/reload). + +## Cluster mode + +If you use [vmagent in cluster mode](https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets) for streaming aggregation +(with `-promscrape.cluster.*` parameters or with `VMAgent.spec.shardCount > 1` for [vmoperator](https://docs.victoriametrics.com/operator)) +then be careful when aggregating metrics via `by`, `without` or modifying via`*_relabel_configs` parameters, as incorrect usage may result in duplicates and data collision. For example, if more than one vmagent calculates `increase` for metric `http_requests_total` with `by: [path]` directive, then the resulting time series written to the remote database will be indistinguishable, as there is no way to tell to which `instance` the aggregation belongs. The proper fix would be to add a unique aggregation dimension: `by: [instance, path]`. With this change, aggregates between `instances` won't collide. + +If adding a new aggregation dimension isn't feasible (due to cardinality reduction purposes), then it is worth at least differentiating by which vmagent the aggregation was performed. You can do it with `remoteWrite.label` [parameter in vmagent](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics). +For example, for running in docker or k8s you can use `remoteWrite.label` with `POD_NAME` or `HOSTNAME` environment variable: `remoteWrite.label='vmagent=%{HOSTNAME}'`. +See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247#issue-1692894073) for details. From c060c6d839e4812443af716f44c9b6bd22f8d4c9 Mon Sep 17 00:00:00 2001 From: Alexander Marshalov <_@marshalov.org> Date: Thu, 17 Aug 2023 12:15:03 +0200 Subject: [PATCH 10/15] vmagent: fixed premature release of the context (after #4247 / #4824) (#4849) Follow-up after https://github.com/VictoriaMetrics/VictoriaMetrics/commit/a27c2f37731986f4bf6738404bb6388b1f42ffde https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247 Signed-off-by: Alexander Marshalov <_@marshalov.org> --- app/vmagent/remotewrite/remotewrite.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/vmagent/remotewrite/remotewrite.go b/app/vmagent/remotewrite/remotewrite.go index ac5681aa48..b4f16ad3ef 100644 --- a/app/vmagent/remotewrite/remotewrite.go +++ b/app/vmagent/remotewrite/remotewrite.go @@ -721,9 +721,10 @@ func dropAggregatedSeries(src []prompbmarshal.TimeSeries, matchIdxs []byte, drop func (rwctx *remoteWriteCtx) pushInternal(tss []prompbmarshal.TimeSeries) { if len(labelsGlobal) > 0 { rctx := getRelabelCtx() + defer putRelabelCtx(rctx) tss = rctx.appendExtraLabels(tss, labelsGlobal) - putRelabelCtx(rctx) } + pss := rwctx.pss idx := atomic.AddUint64(&rwctx.pssNextIdx, 1) % uint64(len(pss)) pss[idx].Push(tss) From d688f9a744c58600a890abf42aaa64d84170f59d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 17 Aug 2023 14:35:26 +0200 Subject: [PATCH 11/15] app/vmagent/remotewrite: follow-up after a27c2f37731986f4bf6738404bb6388b1f42ffde - Fix Prometheus-compatible naming after applying the relabeling if -usePromCompatibleNaming command-line flag is set. This should prevent from possible Prometheus-incompatible metric names and label names generated by the relabeling. - Do not return anything from relabelCtx.appendExtraLabels() function, since it cannot change the number of time series passed to it. Append labels for the passed time series in-place. - Remove promrelabel.FinalizeLabels() call after adding extra labels to time series, since this call has been already made at relabelCtx.applyRelabeling(). It is user's responsibility if he passes labels with double underscore prefixes to -remoteWrite.label. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247 --- app/vmagent/remotewrite/relabel.go | 39 ++++++++++++------------- app/vmagent/remotewrite/relabel_test.go | 6 ++-- app/vmagent/remotewrite/remotewrite.go | 4 +-- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/vmagent/remotewrite/relabel.go b/app/vmagent/remotewrite/relabel.go index b79021c64f..93b4caee75 100644 --- a/app/vmagent/remotewrite/relabel.go +++ b/app/vmagent/remotewrite/relabel.go @@ -98,24 +98,15 @@ func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, pcs *pro ts := &tss[i] labelsLen := len(labels) labels = append(labels, ts.Labels...) - if *usePromCompatibleNaming { - // Replace unsupported Prometheus chars in label names and metric names with underscores. - tmpLabels := labels[labelsLen:] - for j := range tmpLabels { - label := &tmpLabels[j] - if label.Name == "__name__" { - label.Value = promrelabel.SanitizeMetricName(label.Value) - } else { - label.Name = promrelabel.SanitizeLabelName(label.Name) - } - } - } labels = pcs.Apply(labels, labelsLen) labels = promrelabel.FinalizeLabels(labels[:labelsLen], labels[labelsLen:]) if len(labels) == labelsLen { // Drop the current time series, since relabeling removed all the labels. continue } + if *usePromCompatibleNaming { + fixPromCompatibleNaming(labels[labelsLen:]) + } tssDst = append(tssDst, prompbmarshal.TimeSeries{ Labels: labels[labelsLen:], Samples: ts.Samples, @@ -125,11 +116,10 @@ func (rctx *relabelCtx) applyRelabeling(tss []prompbmarshal.TimeSeries, pcs *pro return tssDst } -func (rctx *relabelCtx) appendExtraLabels(tss []prompbmarshal.TimeSeries, extraLabels []prompbmarshal.Label) []prompbmarshal.TimeSeries { +func (rctx *relabelCtx) appendExtraLabels(tss []prompbmarshal.TimeSeries, extraLabels []prompbmarshal.Label) { if len(extraLabels) == 0 { - return tss + return } - tssDst := tss[:0] labels := rctx.labels[:0] for i := range tss { ts := &tss[i] @@ -147,14 +137,9 @@ func (rctx *relabelCtx) appendExtraLabels(tss []prompbmarshal.TimeSeries, extraL labels = append(labels, extraLabel) } } - labels = promrelabel.FinalizeLabels(labels[:labelsLen], labels[labelsLen:]) - tssDst = append(tssDst, prompbmarshal.TimeSeries{ - Labels: labels[labelsLen:], - Samples: ts.Samples, - }) + ts.Labels = labels[labelsLen:] } rctx.labels = labels - return tssDst } type relabelCtx struct { @@ -181,3 +166,15 @@ func putRelabelCtx(rctx *relabelCtx) { rctx.labels = rctx.labels[:0] relabelCtxPool.Put(rctx) } + +func fixPromCompatibleNaming(labels []prompbmarshal.Label) { + // Replace unsupported Prometheus chars in label names and metric names with underscores. + for i := range labels { + label := &labels[i] + if label.Name == "__name__" { + label.Value = promrelabel.SanitizeMetricName(label.Value) + } else { + label.Name = promrelabel.SanitizeLabelName(label.Name) + } + } +} diff --git a/app/vmagent/remotewrite/relabel_test.go b/app/vmagent/remotewrite/relabel_test.go index 441283f23b..c84a316101 100644 --- a/app/vmagent/remotewrite/relabel_test.go +++ b/app/vmagent/remotewrite/relabel_test.go @@ -42,9 +42,9 @@ func TestAppendExtraLabels(t *testing.T) { f := func(extraLabels []prompbmarshal.Label, sTss, sExpTss string) { rctx := &relabelCtx{} tss, expTss := parseSeries(sTss), parseSeries(sExpTss) - gotTss := rctx.appendExtraLabels(tss, extraLabels) - if !reflect.DeepEqual(gotTss, expTss) { - t.Fatalf("expected to have: \n%v;\ngot: \n%v", expTss, gotTss) + rctx.appendExtraLabels(tss, extraLabels) + if !reflect.DeepEqual(tss, expTss) { + t.Fatalf("expected to have: \n%v;\ngot: \n%v", expTss, tss) } } diff --git a/app/vmagent/remotewrite/remotewrite.go b/app/vmagent/remotewrite/remotewrite.go index b4f16ad3ef..62dd1a9089 100644 --- a/app/vmagent/remotewrite/remotewrite.go +++ b/app/vmagent/remotewrite/remotewrite.go @@ -355,7 +355,7 @@ func Push(at *auth.Token, wr *prompbmarshal.WriteRequest) { var rctx *relabelCtx rcs := allRelabelConfigs.Load() pcsGlobal := rcs.global - if pcsGlobal.Len() > 0 || len(labelsGlobal) > 0 { + if pcsGlobal.Len() > 0 { rctx = getRelabelCtx() } tss := wr.Timeseries @@ -722,7 +722,7 @@ func (rwctx *remoteWriteCtx) pushInternal(tss []prompbmarshal.TimeSeries) { if len(labelsGlobal) > 0 { rctx := getRelabelCtx() defer putRelabelCtx(rctx) - tss = rctx.appendExtraLabels(tss, labelsGlobal) + rctx.appendExtraLabels(tss, labelsGlobal) } pss := rwctx.pss From 382721a3accc0a6098ae5d261684d5d80a6364e3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 17 Aug 2023 15:18:22 +0200 Subject: [PATCH 12/15] docs/stream-aggregation.md: clarify the usage of `-remoteWrite.label` after the fix at a27c2f37731986f4bf6738404bb6388b1f42ffde Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247 --- README.md | 3 ++- docs/CHANGELOG.md | 2 +- docs/README.md | 3 ++- docs/Single-server-VictoriaMetrics.md | 3 ++- docs/stream-aggregation.md | 12 ++++++++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f792d14739..aebd03b8ff 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,8 @@ VictoriaMetrics is developed at a fast pace, so it is recommended periodically c ### Environment variables -All the VictoriaMetrics components allow referring environment variables in command-line flags via `%{ENV_VAR}` syntax. +All the VictoriaMetrics components allow referring environment variables in `yaml` configuration files (such as `-promscrape.config`) +and in command-line flags via `%{ENV_VAR}` syntax. For example, `-metricsAuthKey=%{METRICS_AUTH_KEY}` is automatically expanded to `-metricsAuthKey=top-secret` if `METRICS_AUTH_KEY=top-secret` environment variable exists at VictoriaMetrics startup. This expansion is performed by VictoriaMetrics itself. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ae0934ab61..74b5456167 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,7 +25,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## v1.93.x long-time support release (LTS) * BUGFIX: do not allow starting VictoriaMetrics components with improperly set boolean command-line flags in the form `-boolFlagName value`, since this leads to silent incomplete flags' parsing. This form should be replaced with `-boolFlagName=value`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4845). -* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): according to [the docs](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics) labels from `-remoteWrite.label` cmd-line flag are now added to the sent metrics just before they are pushed to the `-remoteWrite.url` (after all relabeling, including stream aggregation relabeling). In addition, it allows adding labels for identifying vmagent instances when using streaming aggregation in vmagents [cluster mode](https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247) and [these docs](https://docs.victoriametrics.com/stream-aggregation.html#cluster-mode) for more details. +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly set labels from `-remoteWrite.label` command-line flag just before sending samples to the configured `-remoteWrite.url` according to [these docs](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics). Previously these labels were incorrectly set before [the relabeling](https://docs.victoriametrics.com/vmagent.html#relabeling) configured via `-remoteWrite.urlRelabelConfigs` and [the stream aggregation](https://docs.victoriametrics.com/stream-aggregation.html) configured via `-remoteWrite.streamAggr.config`, so these labels could be lost or incorrectly transformed before sending the samples to remote storage. The fix allows using `-remoteWrite.label` for identifying `vmagent` instances in [cluster mode](https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247) and [these docs](https://docs.victoriametrics.com/stream-aggregation.html#cluster-mode) for more details. * BUGFIX: remove `DEBUG` logging when parsing `if` filters inside [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements) and when parsing `match` filters inside [stream aggregation rules](https://docs.victoriametrics.com/stream-aggregation.html). * BUGFIX: properly replace `:` chars in label names with `_` when `-usePromCompatibleNaming` command-line flag is passed to `vmagent`, `vminsert` or single-node VictoriaMetrics. This addresses [this comment](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3113#issuecomment-1275077071). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): correctly check if specified `-dst` belongs to specified `-storageDataPath`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4837). diff --git a/docs/README.md b/docs/README.md index 448d59f560..34412c3432 100644 --- a/docs/README.md +++ b/docs/README.md @@ -176,7 +176,8 @@ VictoriaMetrics is developed at a fast pace, so it is recommended periodically c ### Environment variables -All the VictoriaMetrics components allow referring environment variables in command-line flags via `%{ENV_VAR}` syntax. +All the VictoriaMetrics components allow referring environment variables in `yaml` configuration files (such as `-promscrape.config`) +and in command-line flags via `%{ENV_VAR}` syntax. For example, `-metricsAuthKey=%{METRICS_AUTH_KEY}` is automatically expanded to `-metricsAuthKey=top-secret` if `METRICS_AUTH_KEY=top-secret` environment variable exists at VictoriaMetrics startup. This expansion is performed by VictoriaMetrics itself. diff --git a/docs/Single-server-VictoriaMetrics.md b/docs/Single-server-VictoriaMetrics.md index b3e54edf71..d26ed865d3 100644 --- a/docs/Single-server-VictoriaMetrics.md +++ b/docs/Single-server-VictoriaMetrics.md @@ -184,7 +184,8 @@ VictoriaMetrics is developed at a fast pace, so it is recommended periodically c ### Environment variables -All the VictoriaMetrics components allow referring environment variables in command-line flags via `%{ENV_VAR}` syntax. +All the VictoriaMetrics components allow referring environment variables in `yaml` configuration files (such as `-promscrape.config`) +and in command-line flags via `%{ENV_VAR}` syntax. For example, `-metricsAuthKey=%{METRICS_AUTH_KEY}` is automatically expanded to `-metricsAuthKey=top-secret` if `METRICS_AUTH_KEY=top-secret` environment variable exists at VictoriaMetrics startup. This expansion is performed by VictoriaMetrics itself. diff --git a/docs/stream-aggregation.md b/docs/stream-aggregation.md index eb01c9f64a..161d6011fc 100644 --- a/docs/stream-aggregation.md +++ b/docs/stream-aggregation.md @@ -678,8 +678,12 @@ support the following approaches for hot reloading stream aggregation configs fr If you use [vmagent in cluster mode](https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets) for streaming aggregation (with `-promscrape.cluster.*` parameters or with `VMAgent.spec.shardCount > 1` for [vmoperator](https://docs.victoriametrics.com/operator)) -then be careful when aggregating metrics via `by`, `without` or modifying via`*_relabel_configs` parameters, as incorrect usage may result in duplicates and data collision. For example, if more than one vmagent calculates `increase` for metric `http_requests_total` with `by: [path]` directive, then the resulting time series written to the remote database will be indistinguishable, as there is no way to tell to which `instance` the aggregation belongs. The proper fix would be to add a unique aggregation dimension: `by: [instance, path]`. With this change, aggregates between `instances` won't collide. +then be careful when aggregating metrics via `by`, `without` or modifying via `*_relabel_configs` parameters, since incorrect usage +may result in duplicates and data collision. For example, if more than one `vmagent` instance calculates `increase` for metric `http_requests_total` +with `by: [path]` directive, then all the `vmagent` instances will aggregate samples to the same set of time series with different `path` labels. +The proper fix would be to add an unique [`-remoteWrite.label`]https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics() per each `vmagent`, +so every `vmagent` aggregates data into distinct set of time series. These time series then can be aggregated later as needed during querying. -If adding a new aggregation dimension isn't feasible (due to cardinality reduction purposes), then it is worth at least differentiating by which vmagent the aggregation was performed. You can do it with `remoteWrite.label` [parameter in vmagent](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics). -For example, for running in docker or k8s you can use `remoteWrite.label` with `POD_NAME` or `HOSTNAME` environment variable: `remoteWrite.label='vmagent=%{HOSTNAME}'`. -See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247#issue-1692894073) for details. +For example, if `vmagent` instances run in Docker or Kubernetes, then you can refer `POD_NAME` or `HOSTNAME` environment variables +as an unique label value per each `vmagent`: `-remoteWrite.label='vmagent=%{HOSTNAME}` . See [these docs](https://docs.victoriametrics.com/#environment-variables) +on how to refer environment variables in VictoriaMetrics components. From a2c901423b451001d1a502e4a068bc01ef5033b8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 17 Aug 2023 15:24:44 +0200 Subject: [PATCH 13/15] docs/stream-aggregation.md: typo fix after 54f522ac257ea82db2ca18d0e458921f8ec5a510 --- docs/stream-aggregation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/stream-aggregation.md b/docs/stream-aggregation.md index 161d6011fc..80756a3f02 100644 --- a/docs/stream-aggregation.md +++ b/docs/stream-aggregation.md @@ -681,7 +681,7 @@ If you use [vmagent in cluster mode](https://docs.victoriametrics.com/vmagent.ht then be careful when aggregating metrics via `by`, `without` or modifying via `*_relabel_configs` parameters, since incorrect usage may result in duplicates and data collision. For example, if more than one `vmagent` instance calculates `increase` for metric `http_requests_total` with `by: [path]` directive, then all the `vmagent` instances will aggregate samples to the same set of time series with different `path` labels. -The proper fix would be to add an unique [`-remoteWrite.label`]https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics() per each `vmagent`, +The proper fix would be to add an unique [`-remoteWrite.label`](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics) per each `vmagent`, so every `vmagent` aggregates data into distinct set of time series. These time series then can be aggregated later as needed during querying. For example, if `vmagent` instances run in Docker or Kubernetes, then you can refer `POD_NAME` or `HOSTNAME` environment variables From 35263983a6d080c76761c64d645ce299ec3b1daa Mon Sep 17 00:00:00 2001 From: Nikolay Date: Wed, 23 Aug 2023 13:22:53 +0200 Subject: [PATCH 14/15] lib/storage: properly caclucate nextRotationTimestamp (#4874) cause of typo unix millis was used instead of unix for current timestamp calculation https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4873 (cherry picked from commit c5aac34b68f6c55cb465feb712c575b681e2a6bc) --- docs/CHANGELOG.md | 1 + lib/storage/storage.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 74b5456167..c2dab4c583 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -57,6 +57,7 @@ The v1.93.x line will be supported for at least 12 months since [v1.93.0](https: * FEATURE: [Official Grafana dashboards for VictoriaMetrics](https://grafana.com/orgs/victoriametrics): correctly calculate `Bytes per point` value for single-server and cluster VM dashboards. Before, the calculation mistakenly accounted for the number of entries in indexdb in denominator, which could have shown lower values than expected. * FEATURE: [Alerting rules for VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#alerts): `ConcurrentFlushesHitTheLimit` alerting rule was moved from [single-server](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts.yml) and [cluster](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-cluster.yml) alerts to the [list of "health" alerts](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-health.yml) as it could be related to many VictoriaMetrics components. +* BUGFIX: [storage](https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html): properly set next retention time for indexDB. Previously it may enter into endless retention loop. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4873) for details. * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): return human readable error if opentelemetry has json encoding. Follow-up after [PR](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2570). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly validate scheme for `proxy_url` field at the scrape config. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4811) for details. * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly apply `if` filters during [relabeling](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements). Previously the `if` filter could improperly work. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4806) and [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4816). diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 5ef0a82909..e61c0f0c07 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -757,7 +757,7 @@ func (s *Storage) mustRotateIndexDB(currentTime time.Time) { idbNew := mustOpenIndexDB(idbNewPath, s, &s.isReadOnly) // Update nextRotationTimestamp - nextRotationTimestamp := currentTime.UnixMilli() + s.retentionMsecs/1000 + nextRotationTimestamp := currentTime.Unix() + s.retentionMsecs/1000 atomic.StoreInt64(&s.nextRotationTimestamp, nextRotationTimestamp) // Set idbNext to idbNew From c8c20b7f7aa8f383dbc826af820e950a9b96806d Mon Sep 17 00:00:00 2001 From: Dmytro Kozlov Date: Fri, 18 Aug 2023 08:55:42 +0200 Subject: [PATCH 15/15] docs: cut 1.93.1-lts in changelog Signed-off-by: hagen1778 --- docs/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c2dab4c583..89d1d76d3c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,9 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## v1.93.x long-time support release (LTS) +## v1.93.1 long-time support release (LTS) + +* BUGFIX: [storage](https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html): properly set next retention time for indexDB. Previously it may enter into endless retention loop. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4873) for details. * BUGFIX: do not allow starting VictoriaMetrics components with improperly set boolean command-line flags in the form `-boolFlagName value`, since this leads to silent incomplete flags' parsing. This form should be replaced with `-boolFlagName=value`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4845). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly set labels from `-remoteWrite.label` command-line flag just before sending samples to the configured `-remoteWrite.url` according to [these docs](https://docs.victoriametrics.com/vmagent.html#adding-labels-to-metrics). Previously these labels were incorrectly set before [the relabeling](https://docs.victoriametrics.com/vmagent.html#relabeling) configured via `-remoteWrite.urlRelabelConfigs` and [the stream aggregation](https://docs.victoriametrics.com/stream-aggregation.html) configured via `-remoteWrite.streamAggr.config`, so these labels could be lost or incorrectly transformed before sending the samples to remote storage. The fix allows using `-remoteWrite.label` for identifying `vmagent` instances in [cluster mode](https://docs.victoriametrics.com/vmagent.html#scraping-big-number-of-targets). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4247) and [these docs](https://docs.victoriametrics.com/stream-aggregation.html#cluster-mode) for more details. * BUGFIX: remove `DEBUG` logging when parsing `if` filters inside [relabeling rules](https://docs.victoriametrics.com/vmagent.html#relabeling-enhancements) and when parsing `match` filters inside [stream aggregation rules](https://docs.victoriametrics.com/stream-aggregation.html).