From 5be2f2c4e415ca7bc846c89bf536f9bc73337e9c Mon Sep 17 00:00:00 2001 From: Hui Wang <haley@victoriametrics.com> Date: Tue, 18 Jun 2024 14:14:30 +0200 Subject: [PATCH] =?UTF-8?q?vmalert-tool:=20support=20file=20path=20with=20?= =?UTF-8?q?hierarchical=20patterns=20and=20regexp=E2=80=A6=20(#6501)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …es, and http url in unittest cmd-line flag `-files` (cherry picked from commit 3b8970802eca9d7df8a08ccbaf88ae368894ca40) Signed-off-by: hagen1778 <roman@victoriametrics.com> --- app/vmalert/config/config.go | 4 ++-- app/vmalert/config/fs.go | 8 ++++---- docs/CHANGELOG.md | 1 + docs/vmalert-tool.md | 5 +++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/vmalert/config/config.go b/app/vmalert/config/config.go index 4d8232d061..d2c07469c3 100644 --- a/app/vmalert/config/config.go +++ b/app/vmalert/config/config.go @@ -234,7 +234,7 @@ func ParseSilent(pathPatterns []string, validateTplFn ValidateTplFn, validateExp cLogger.Suppress(true) defer cLogger.Suppress(false) - files, err := readFromFS(pathPatterns) + files, err := ReadFromFS(pathPatterns) if err != nil { return nil, fmt.Errorf("failed to read from the config: %w", err) } @@ -243,7 +243,7 @@ func ParseSilent(pathPatterns []string, validateTplFn ValidateTplFn, validateExp // Parse parses rule configs from given file patterns func Parse(pathPatterns []string, validateTplFn ValidateTplFn, validateExpressions bool) ([]Group, error) { - files, err := readFromFS(pathPatterns) + files, err := ReadFromFS(pathPatterns) if err != nil { return nil, fmt.Errorf("failed to read from the config: %w", err) } diff --git a/app/vmalert/config/fs.go b/app/vmalert/config/fs.go index 2fc068370d..5f9854c75c 100644 --- a/app/vmalert/config/fs.go +++ b/app/vmalert/config/fs.go @@ -32,14 +32,14 @@ var ( fsRegistry = make(map[string]FS) ) -// readFromFS parses the given path list and inits FS for each item. -// Once initialed, readFromFS will try to read and return files from each FS. -// readFromFS returns an error if at least one FS failed to init. +// ReadFromFS parses the given path list and inits FS for each item. +// Once initialed, ReadFromFS will try to read and return files from each FS. +// ReadFromFS returns an error if at least one FS failed to init. // The function can be called multiple times but each unique path // will be initialed only once. // // It is allowed to mix different FS types in path list. -func readFromFS(paths []string) (map[string][]byte, error) { +func ReadFromFS(paths []string) (map[string][]byte, error) { var err error result := make(map[string][]byte) for _, path := range paths { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e80d199fc8..3a6fd16444 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -39,6 +39,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent/): increase default value of `-promscrape.maxDroppedTargets` command-line flag to 10_000 from 1000. This makes it easier to track down large number of dropped targets. * FEATURE: [vmsingle](https://docs.victoriametrics.com/single-server-victoriametrics/): check for ranged vector arguments in non-rollup expressions when `-search.disableImplicitConversion` or `-search.logImplicitConversion` are enabled. For example, `sum(up[5m])` or `absent(up[5m])` will fail to execute if these flags are set. * FEATURE: [vmsingle](https://docs.victoriametrics.com/single-server-victoriametrics/): validate that rollup expressions has ranged vector arguments passed when `-search.disableImplicitConversion` or `-search.logImplicitConversion` are enabled. For example, `rate(metric)` or `count_over_time(metric)` will fail to execute if these flags are set. +* FEATURE: [vmalert-tool](https://docs.victoriametrics.com/vmalert-tool/): support file path with hierarchical patterns and regexpes, and http url in unittest cmd-line flag `-files`, e.g. `-files="http://<some-server-addr>/path/to/rules"` or `-files="dir/**/*.yaml"`. * BUGFIX: all VictoriaMetrics components: prioritize `-configAuthKey` and `-reloadAuthKey` over `-httpAuth.*` settings. This change aligns behavior of mentioned flags with other auth flags like `-metricsAuthKey`, `-flagsAuthKey`, `-pprofAuthKey`. Check [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6329). * BUGFIX: [vmctl](https://docs.victoriametrics.com/vmctl/): add `--disable-progress-bar` global command-line flag. It can be used for disabling dynamic progress bar for all migration modes. `--vm-disable-progress-bar` command-line flag is deprecated and will be removed in the future releases. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6367). diff --git a/docs/vmalert-tool.md b/docs/vmalert-tool.md index 07551e61a2..5290844942 100644 --- a/docs/vmalert-tool.md +++ b/docs/vmalert-tool.md @@ -26,8 +26,9 @@ It will perform the following actions: See how to run vmalert-tool for unit test below: ``` -# Run vmalert-tool with one or multiple test files via --files cmd-line flag -./vmalert-tool unittest --files test1.yaml --files test2.yaml +# Run vmalert-tool with one or multiple test files via `--files` cmd-line flag +# Supports file path with hierarchical patterns and regexpes, and http url. +./vmalert-tool unittest --files /path/to/file --files http://<some-server-addr>/path/to/test.yaml ``` vmalert-tool unittest is compatible with [Prometheus config format for tests](https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/#test-file-format)