MCPcopy Index your code
hub / github.com/cortexproject/cortex / main

Function main

cmd/cortex/main.go:64–222  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62var testMode = false
63
64func main() {
65 var (
66 cfg cortex.Config
67 eventSampleRate int
68 mutexProfileFraction int
69 blockProfileRate int
70 printVersion bool
71 printModules bool
72 )
73
74 args := os.Args[1:]
75 configFile, expandENV := parseConfigFileParameter(args)
76
77 // This sets default values from flags to the config.
78 // It needs to be called before parsing the config file!
79 flagext.RegisterFlags(&cfg)
80
81 if configFile != "" {
82 if err := LoadConfig(configFile, expandENV, &cfg); err != nil {
83 fmt.Fprintf(os.Stderr, "error loading config from %s: %v\n", configFile, err)
84 if testMode {
85 return
86 }
87 os.Exit(1)
88 }
89 } else if len(args) == 0 {
90 fmt.Fprintf(os.Stderr, "please set configuration file. For example: -config.file=./docs/configuration/single-process-config-blocks-local.yaml\n")
91 if testMode {
92 return
93 }
94 os.Exit(1)
95 }
96
97 // Ignore -config.file and -config.expand-env here, since it was already parsed, but it's still present on command line.
98 flagext.IgnoredFlag(flag.CommandLine, configFileOption, "Configuration file to load.")
99 _ = flag.CommandLine.Bool(configExpandENV, false, "Expands ${var} or $var in config according to the values of the environment variables.")
100
101 flag.IntVar(&eventSampleRate, "event.sample-rate", 0, "How often to sample observability events (0 = never).")
102 flag.IntVar(&mutexProfileFraction, "debug.mutex-profile-fraction", 0, "Fraction of mutex contention events that are reported in the mutex profile. On average 1/rate events are reported. 0 to disable.")
103 flag.IntVar(&blockProfileRate, "debug.block-profile-rate", 0, "Fraction of goroutine blocking events that are reported in the blocking profile. 1 to include every blocking event in the profile, 0 to disable.")
104 flag.BoolVar(&printVersion, "version", false, "Print Cortex version and exit.")
105 flag.BoolVar(&printModules, "modules", false, "List available values that can be used as target.")
106
107 //lint:ignore faillint Need to pass the global logger like this for warning on deprecated methods
108 flagext.DeprecatedFlag(flag.CommandLine, "mem-ballast-size-bytes", "Deprecated: Setting this flag will not take any effect, for similar functionality use GOMEMLIMIT. Size of memory ballast to allocate", util_log.Logger)
109
110 usage := flag.CommandLine.Usage
111 flag.CommandLine.Usage = func() { /* don't do anything by default, we will print usage ourselves, but only when requested. */ }
112 flag.CommandLine.Init(flag.CommandLine.Name(), flag.ContinueOnError)
113
114 err := flag.CommandLine.Parse(os.Args[1:])
115 if err == flag.ErrHelp {
116 // Print available parameters to stdout, so that users can grep/less it easily.
117 flag.CommandLine.SetOutput(os.Stdout)
118 usage()
119 if !testMode {
120 os.Exit(2)
121 }

Callers 1

testSingleFunction · 0.70

Calls 15

RegisterFlagsFunction · 0.92
IgnoredFlagFunction · 0.92
DeprecatedFlagFunction · 0.92
InitEventsFunction · 0.92
SetupTracingFunction · 0.92
NewFunction · 0.92
parseConfigFileParameterFunction · 0.85
DumpYamlFunction · 0.85
ParseMethod · 0.80
DependenciesForModuleMethod · 0.80
LoadConfigFunction · 0.70

Tested by 1

testSingleFunction · 0.56