Skip to content

Commit

Permalink
Deprecate old flag format (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome authored Jul 20, 2023
1 parent 6395eb7 commit 18e8f98
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,21 @@ func main() {
kingpin.Flag("prometheus.const-label", "Label that will be used in every metric. Format is label=value. It can be repeated multiple times.").Envar("CONST_LABELS").StringMapVar(&constLabels)

promlogConfig := &promlog.Config{}
logger := promlog.New(promlogConfig)

// convert deprecated flags to new format
for i, arg := range os.Args {
if strings.HasPrefix(arg, "-") && len(arg) > 1 {
newArg := fmt.Sprintf("-%s", arg)
level.Warn(logger).Log("msg", "the flag format is deprecated and will be removed in a future release, please use the new format", "old", arg, "new", newArg)
os.Args[i] = newArg
}
}

flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print(exporterName))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(promlogConfig)

level.Info(logger).Log("msg", "Starting nginx-prometheus-exporter", "version", version.Info())
level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
Expand Down

0 comments on commit 18e8f98

Please sign in to comment.