mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-05 04:16:15 +02:00
test(cmd/prometheus): add TestFeatureFlagsDocumented and adjust --enable-feature description (#18487)
* test(cmd/prometheus): add TestFeatureFlagsDocumented and fix help text Add TestFeatureFlagsDocumented to ensure the --enable-feature help text in and docs/feature_flags.md list the same set of flags. The help text was out of sync with the documentation: - Flags present in docs but missing from help text: `auto-reload-config`, `metadata-wal-records`, `otlp-native-delta-ingestion`, `promql-delayed-name-removal`, `type-and-unit-labels`. Added them. - Flags present in help text but missing from docs: `auto-gomaxprocs`, `expand-external-labels`. Removed them. The help text is now sorted for better readability and kept in sync with the documentation. Also, the parsing of an empty `--enable-feature` was changed to print `msg="Unknown option for --enable-feature" option=""` instead of nothing. Signed-off-by: Ayoub Mrini <ayoubmrini424@gmail.com> * main.go remove default for --enable-feature to avoid unwanted Signed-off-by: Ayoub Mrini <ayoubmrini424@gmail.com> --------- Signed-off-by: Ayoub Mrini <ayoubmrini424@gmail.com>
This commit is contained in:
parent
57821524d5
commit
83962c35a4
@ -305,8 +305,6 @@ func (c *flagConfig) setFeatureListOptions(logger *slog.Logger) error {
|
||||
case "promql-binop-fill-modifiers":
|
||||
c.parserOpts.EnableBinopFillModifiers = true
|
||||
logger.Info("Experimental PromQL binary operator fill modifiers enabled.")
|
||||
case "":
|
||||
continue
|
||||
case "old-ui":
|
||||
c.web.UseOldUI = true
|
||||
logger.Info("Serving previous version of the Prometheus web UI.")
|
||||
@ -608,8 +606,8 @@ func main() {
|
||||
a.Flag("scrape.discovery-reload-interval", "Interval used by scrape manager to throttle target groups updates.").
|
||||
Hidden().Default("5s").SetValue(&cfg.scrape.DiscoveryReloadInterval)
|
||||
|
||||
a.Flag("enable-feature", "Comma separated feature names to enable. Valid options: exemplar-storage, expand-external-labels, memory-snapshot-on-shutdown, promql-per-step-stats, promql-experimental-functions, extra-scrape-metrics, auto-gomaxprocs, created-timestamp-zero-ingestion, st-storage, concurrent-rule-eval, delayed-compaction, old-ui, otlp-deltatocumulative, promql-duration-expr, use-uncached-io, promql-extended-range-selectors, promql-binop-fill-modifiers, xor2-encoding. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details.").
|
||||
Default("").StringsVar(&cfg.featureList)
|
||||
a.Flag("enable-feature", "Comma separated feature names to enable. Valid options: auto-reload-config, concurrent-rule-eval, created-timestamp-zero-ingestion, delayed-compaction, exemplar-storage, extra-scrape-metrics, memory-snapshot-on-shutdown, metadata-wal-records, old-ui, otlp-deltatocumulative, otlp-native-delta-ingestion, promql-binop-fill-modifiers, promql-delayed-name-removal, promql-duration-expr, promql-experimental-functions, promql-extended-range-selectors, promql-per-step-stats, st-storage, type-and-unit-labels, use-uncached-io, xor2-encoding. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details.").
|
||||
StringsVar(&cfg.featureList)
|
||||
|
||||
a.Flag("agent", "Run Prometheus in 'Agent mode'.").BoolVar(&agentMode)
|
||||
|
||||
|
||||
@ -26,6 +26,7 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -34,6 +35,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/grafana/regexp"
|
||||
remoteapi "github.com/prometheus/client_golang/exp/api/remote"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/expfmt"
|
||||
@ -1062,3 +1064,30 @@ remote_write:
|
||||
// 3*shardUpdateDuration to allow for the resharding logic to run.
|
||||
}, 30*time.Second, time.Second)
|
||||
}
|
||||
|
||||
// TestFeatureFlagsDocumented ensures the --enable-feature help text in main.go
|
||||
// and the documented flags in docs/feature_flags.md list the same set of flags.
|
||||
func TestFeatureFlagsDocumented(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.SkipNow()
|
||||
}
|
||||
h, err := os.ReadFile(filepath.Join("..", "..", "cmd", "prometheus", "main.go"))
|
||||
require.NoError(t, err)
|
||||
m := regexp.MustCompile(`a\.Flag\("enable-feature", "Comma separated feature names to enable. Valid options: (.+?)\.`).FindSubmatch(h)
|
||||
require.NotNil(t, m)
|
||||
var helpFlags []string
|
||||
for f := range strings.SplitSeq(string(m[1]), ",") {
|
||||
helpFlags = append(helpFlags, strings.TrimSpace(f))
|
||||
}
|
||||
require.NotEmpty(t, helpFlags)
|
||||
|
||||
d, err := os.ReadFile(filepath.Join("..", "..", "docs", "feature_flags.md"))
|
||||
require.NoError(t, err)
|
||||
var docFlags []string
|
||||
for _, dm := range regexp.MustCompile("(?m)^`--enable-feature=(.+)`$").FindAllSubmatch(d, -1) {
|
||||
docFlags = append(docFlags, string(dm[1]))
|
||||
}
|
||||
require.NotEmpty(t, docFlags)
|
||||
require.True(t, slices.IsSorted(helpFlags))
|
||||
require.ElementsMatch(t, helpFlags, docFlags)
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ The Prometheus monitoring server
|
||||
| <code class="text-nowrap">--query.timeout</code> | Maximum time a query may take before being aborted. Use with server mode only. | `2m` |
|
||||
| <code class="text-nowrap">--query.max-concurrency</code> | Maximum number of queries executed concurrently. Use with server mode only. | `20` |
|
||||
| <code class="text-nowrap">--query.max-samples</code> | Maximum number of samples a single query can load into memory. Note that queries will fail if they try to load more samples than this into memory, so this also limits the number of samples a query can return. Use with server mode only. | `50000000` |
|
||||
| <code class="text-nowrap">--enable-feature</code> <code class="text-nowrap">...<code class="text-nowrap"> | Comma separated feature names to enable. Valid options: exemplar-storage, expand-external-labels, memory-snapshot-on-shutdown, promql-per-step-stats, promql-experimental-functions, extra-scrape-metrics, auto-gomaxprocs, created-timestamp-zero-ingestion, st-storage, concurrent-rule-eval, delayed-compaction, old-ui, otlp-deltatocumulative, promql-duration-expr, use-uncached-io, promql-extended-range-selectors, promql-binop-fill-modifiers, xor2-encoding. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details. | |
|
||||
| <code class="text-nowrap">--enable-feature</code> <code class="text-nowrap">...<code class="text-nowrap"> | Comma separated feature names to enable. Valid options: auto-reload-config, concurrent-rule-eval, created-timestamp-zero-ingestion, delayed-compaction, exemplar-storage, extra-scrape-metrics, memory-snapshot-on-shutdown, metadata-wal-records, old-ui, otlp-deltatocumulative, otlp-native-delta-ingestion, promql-binop-fill-modifiers, promql-delayed-name-removal, promql-duration-expr, promql-experimental-functions, promql-extended-range-selectors, promql-per-step-stats, st-storage, type-and-unit-labels, use-uncached-io, xor2-encoding. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details. | |
|
||||
| <code class="text-nowrap">--agent</code> | Run Prometheus in 'Agent mode'. | |
|
||||
| <code class="text-nowrap">--log.level</code> | Only log messages with the given severity or above. One of: [debug, info, warn, error] | `info` |
|
||||
| <code class="text-nowrap">--log.format</code> | Output format of log messages. One of: [logfmt, json] | `logfmt` |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user