diff --git a/CHANGELOG.md b/CHANGELOG.md index ab4095f799d..ab7870c4d22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * [ENHANCEMENT] Ingester: added new metric `cortex_ingester_active_series` to track active series more accurately. Also added options to control whether active series tracking is enabled (`-ingester.active-series-enabled`, defaults to false), and how often this metric is updated (`-ingester.active-series-update-period`) and max idle time for series to be considered inactive (`-ingester.active-series-idle-timeout`). #3153 * [ENHANCEMENT] Blocksconvert – Builder: download plan file locally before processing it. #3209 * [ENHANCEMENT] Store-gateway: added zone-aware replication support to blocks replication in the store-gateway. #3200 +* [ENHANCEMENT] Added `-version` flag to Cortex. #3233 * [BUGFIX] No-longer-needed ingester operations for queries triggered by queriers and rulers are now canceled. #3178 * [BUGFIX] Ruler: directories in the configured `rules-path` will be removed on startup and shutdown in order to ensure they don't persist between runs. #3195 * [BUGFIX] Handle hash-collisions in the query path. #3192 diff --git a/cmd/cortex/main.go b/cmd/cortex/main.go index 8340e833112..ec72a041207 100644 --- a/cmd/cortex/main.go +++ b/cmd/cortex/main.go @@ -61,6 +61,8 @@ func main() { eventSampleRate int ballastBytes int mutexProfileFraction int + printVersion bool + printModules bool ) configFile, expandENV := parseConfigFileParameter(os.Args[1:]) @@ -86,6 +88,8 @@ func main() { flag.IntVar(&eventSampleRate, "event.sample-rate", 0, "How often to sample observability events (0 = never).") flag.IntVar(&ballastBytes, "mem-ballast-size-bytes", 0, "Size of memory ballast to allocate.") flag.IntVar(&mutexProfileFraction, "debug.mutex-profile-fraction", 0, "Fraction at which mutex profile vents will be reported, 0 to disable") + flag.BoolVar(&printVersion, "version", false, "Print Cortex version and exit.") + flag.BoolVar(&printModules, "modules", false, "List available values that can be used as target.") usage := flag.CommandLine.Usage flag.CommandLine.Usage = func() { /* don't do anything by default, we will print usage ourselves, but only when requested. */ } @@ -106,6 +110,11 @@ func main() { } } + if printVersion { + fmt.Fprintln(os.Stdout, version.Print("Cortex")) + return + } + // Validate the config once both the config file has been loaded // and CLI flags parsed. err = cfg.Validate(util.Logger) @@ -118,7 +127,7 @@ func main() { // Continue on if -modules flag is given. Code handling the // -modules flag will not start cortex. - if testMode && !cfg.ListModules { + if testMode && !printModules { DumpYaml(&cfg) return } @@ -151,7 +160,7 @@ func main() { t, err := cortex.New(cfg) util.CheckFatal("initializing cortex", err) - if t.Cfg.ListModules { + if printModules { allDeps := t.ModuleManager.DependenciesForModule(cortex.All) for _, m := range t.ModuleManager.UserVisibleModuleNames() { @@ -167,12 +176,7 @@ func main() { fmt.Fprintln(os.Stdout) fmt.Fprintln(os.Stdout, "Modules marked with * are included in target All.") - - // in test mode we cannot call os.Exit, it will stop to whole test process. - if testMode { - return - } - os.Exit(2) + return } level.Info(util.Logger).Log("msg", "Starting Cortex", "version", version.Info()) diff --git a/cmd/cortex/main_test.go b/cmd/cortex/main_test.go index e053f834e2d..d5c5a14a1af 100644 --- a/cmd/cortex/main_test.go +++ b/cmd/cortex/main_test.go @@ -80,6 +80,11 @@ func TestFlagParsing(t *testing.T) { stderrMessage: "the Querier configuration in YAML has been specified as an empty YAML node", }, + "version": { + arguments: []string{"-version"}, + stdoutMessage: "Cortex, version", + }, + // we cannot test the happy path, as cortex would then fully start } { t.Run(name, func(t *testing.T) { diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index 43783f8189b..5575a76520e 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -75,7 +75,6 @@ type Config struct { AuthEnabled bool `yaml:"auth_enabled"` PrintConfig bool `yaml:"-"` HTTPPrefix string `yaml:"http_prefix"` - ListModules bool `yaml:"-"` // No yaml for this, it only works with flags. API api.Config `yaml:"api"` Server server.Config `yaml:"server"` @@ -111,7 +110,6 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { c.Server.MetricsNamespace = "cortex" c.Server.ExcludeRequestInLog = true f.StringVar(&c.Target, "target", All, "The Cortex module to run. Use \"-modules\" command line flag to get a list of available modules, and to see which modules are included in \"All\".") - f.BoolVar(&c.ListModules, "modules", false, "List available values to be use as target. Cannot be used in YAML config.") f.BoolVar(&c.AuthEnabled, "auth.enabled", true, "Set to false to disable auth.") f.BoolVar(&c.PrintConfig, "print.config", false, "Print the config and exit.") f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.")