From 5fecb77f698b5e0001d9ffe450c37eac375fa58a Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Thu, 24 Oct 2024 15:57:58 +0300 Subject: [PATCH] app/vmctl: fix match expression for vm-native protocol with --vm-native-disable-per-metric-migration flag enabled (#7310) Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7309 ### Describe Your Changes Please provide a brief description of the changes you made. Be as specific as possible to help others understand the purpose and impact of your modifications. ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). --------- Signed-off-by: hagen1778 Co-authored-by: hagen1778 --- app/vmctl/vm_native.go | 31 ++++++++++++++++--------------- app/vmctl/vm_native_test.go | 6 ++++++ docs/changelog/CHANGELOG.md | 2 ++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/vmctl/vm_native.go b/app/vmctl/vm_native.go index 618e1fdec..121a8bfa1 100644 --- a/app/vmctl/vm_native.go +++ b/app/vmctl/vm_native.go @@ -120,7 +120,7 @@ func (p *vmNativeProcessor) runSingle(ctx context.Context, f native.Filter, srcU if p.disablePerMetricRequests { pr := bar.NewProxyReader(reader) if pr != nil { - reader = bar.NewProxyReader(reader) + reader = pr fmt.Printf("Continue import process with filter %s:\n", f.String()) } } @@ -193,7 +193,15 @@ func (p *vmNativeProcessor) runBackfilling(ctx context.Context, tenantID string, var metrics = map[string][][]time.Time{ "": ranges, } + + format := nativeSingleProcessTpl + barPrefix := "Requests to make" + if p.interCluster { + barPrefix = fmt.Sprintf("Requests to make for tenant %s", tenantID) + } + if !p.disablePerMetricRequests { + format = fmt.Sprintf(nativeWithBackoffTpl, barPrefix) metrics, err = p.explore(ctx, p.src, tenantID, ranges) if err != nil { return fmt.Errorf("failed to explore metric names: %s", err) @@ -223,15 +231,7 @@ func (p *vmNativeProcessor) runBackfilling(ctx context.Context, tenantID string, log.Print(foundSeriesMsg) } - barPrefix := "Requests to make" - if p.interCluster { - barPrefix = fmt.Sprintf("Requests to make for tenant %s", tenantID) - } - - bar := barpool.NewSingleProgress(fmt.Sprintf(nativeWithBackoffTpl, barPrefix), requestsToMake) - if p.disablePerMetricRequests { - bar = barpool.NewSingleProgress(nativeSingleProcessTpl, 0) - } + bar := barpool.NewSingleProgress(format, requestsToMake) bar.Start() defer bar.Finish() @@ -362,16 +362,17 @@ func byteCountSI(b int64) string { } func buildMatchWithFilter(filter string, metricName string) (string, error) { - if filter == metricName { - return filter, nil - } - nameFilter := fmt.Sprintf("__name__=%q", metricName) - tfss, err := searchutils.ParseMetricSelector(filter) if err != nil { return "", err } + if filter == metricName || metricName == "" { + return filter, nil + } + + nameFilter := fmt.Sprintf("__name__=%q", metricName) + var filters []string for _, tfs := range tfss { var a []string diff --git a/app/vmctl/vm_native_test.go b/app/vmctl/vm_native_test.go index 74f57e3bf..fa7bf4b68 100644 --- a/app/vmctl/vm_native_test.go +++ b/app/vmctl/vm_native_test.go @@ -293,6 +293,9 @@ func TestBuildMatchWithFilter_Success(t *testing.T) { // only label with regexp f(`{cluster=~".*"}`, "http_request_count_total", `{cluster=~".*",__name__="http_request_count_total"}`) + // only label with regexp, empty metric name + f(`{cluster=~".*"}`, "", `{cluster=~".*"}`) + // many labels in filter with regexp f(`{cluster=~".*",job!=""}`, "http_request_count_total", `{cluster=~".*",job!="",__name__="http_request_count_total"}`) @@ -307,4 +310,7 @@ func TestBuildMatchWithFilter_Success(t *testing.T) { // metric name has negative regexp f(`{__name__!~".*"}`, "http_request_count_total", `{__name__="http_request_count_total"}`) + + // metric name has negative regex and metric name is empty + f(`{__name__!~".*"}`, "", `{__name__!~".*"}`) } diff --git a/docs/changelog/CHANGELOG.md b/docs/changelog/CHANGELOG.md index b5e0fb0c1..3d84ad75d 100644 --- a/docs/changelog/CHANGELOG.md +++ b/docs/changelog/CHANGELOG.md @@ -17,9 +17,11 @@ The sandbox cluster installation runs under the constant load generated by See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). ## tip + * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert/): `-rule` cmd-line flag now supports multi-document YAML files. This could be useful when rules are retrieved via HTTP URL where multiple rule files were merged together in one response. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6753). Thanks to @Irene-123 for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6995). * BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert): properly set `group_name` and `file` fields for recording rules in `/api/v1/rules`. +* BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl/): fix issue with series matching for `vmctl vm-native` with `--vm-native-disable-per-metric-migration` flag enabled. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7309). ## [v1.105.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.105.0)