diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bf0805439..8e63ab868 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,6 +15,7 @@ sort: 15 * `/select//vmui/` for `vmselect` at cluster version of VictoriaMetrics * FEATURE: support durations anywhere in [MetricsQL queries](https://docs.victoriametrics.com/MetricsQL.html). For example, `sum_over_time(m[1h]) / 1h` is a valid query, which is equivalent to `sum_over_time(m[1h]) / 3600`. * FEATURE: support durations without suffxies in [MetricsQL queries](https://docs.victoriametrics.com/MetricsQL.html). For example, `rate(m[3600])` is a valid query, which is equivalent to `rate(m[1h])`. +* FEATURE: add `is_set` label to `flag` metrics. This allows determining explicitly set command-line flags with the query `flag{is_set="true"}`. * BUGFIX: vmagent: remove `{ %space %}` typo in `/targets` output. The typo has been introduced in v1.62.0. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1408). * BUGFIX: vmagent: fix CSS styles on `/targets` page. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1422). diff --git a/lib/httpserver/metrics.go b/lib/httpserver/metrics.go index 0b822f5d5..ec8da34af 100644 --- a/lib/httpserver/metrics.go +++ b/lib/httpserver/metrics.go @@ -58,6 +58,10 @@ func writePrometheusMetrics(w io.Writer) { fmt.Fprintf(w, "vm_app_uptime_seconds %d\n", int(time.Since(startTime).Seconds())) // Export flags as metrics. + isSetMap := make(map[string]bool) + flag.Visit(func(f *flag.Flag) { + isSetMap[f.Name] = true + }) flag.VisitAll(func(f *flag.Flag) { lname := strings.ToLower(f.Name) value := f.Value.String() @@ -65,7 +69,11 @@ func writePrometheusMetrics(w io.Writer) { // Do not expose passwords and keys to prometheus. value = "secret" } - fmt.Fprintf(w, "flag{name=%q, value=%q} 1\n", f.Name, value) + isSet := "false" + if isSetMap[f.Name] { + isSet = "true" + } + fmt.Fprintf(w, "flag{name=%q, value=%q, is_set=%q} 1\n", f.Name, value, isSet) }) } diff --git a/lib/logger/flag.go b/lib/logger/flag.go index 5a9d09774..74a5963f9 100644 --- a/lib/logger/flag.go +++ b/lib/logger/flag.go @@ -11,12 +11,20 @@ import ( func logAllFlags() { Infof("build version: %s", buildinfo.Version) Infof("command line flags") + isSetMap := make(map[string]bool) + flag.Visit(func(f *flag.Flag) { + isSetMap[f.Name] = true + }) flag.VisitAll(func(f *flag.Flag) { lname := strings.ToLower(f.Name) value := f.Value.String() if flagutil.IsSecretFlag(lname) { value = "secret" } - Infof("flag %q = %q", f.Name, value) + isSet := "false" + if isSetMap[f.Name] { + isSet = "true" + } + Infof("flag %q=%q (is_set=%s)", f.Name, value, isSet) }) }