@@ -46,58 +46,62 @@ type Config struct {
46
46
StartupOnly bool
47
47
}
48
48
49
- var flagAliases = map [string ][]string {
50
- "auth.tls-cert-file" : {"tls-cert-file" },
51
- "auth.tls-key-file" : {"tls-key-file" },
52
- "cache.memory-target" : {"memory-target" },
53
- "db.app" : {"app" },
54
- "db.connection-timeout" : {"db-connection-timeout" },
55
- "db.connections-max" : {"db-connections-max" },
56
- "db.host" : {"db-host" },
57
- "db.name" : {"db-name" },
58
- "db.num-writer-connections" : {"db-writer-connection-concurrency" },
59
- "db.password" : {"db-password" },
60
- "db.port" : {"db-port" },
61
- "db.read-only" : {"read-only" },
62
- "db.ssl-mode" : {"db-ssl-mode" },
63
- "db.statements-cache" : {"db-statements-cache" },
64
- "db.uri" : {"db-uri" },
65
- "db.user" : {"db-user" },
66
- "metrics.async-acks" : {"async-acks" },
67
- "metrics.cache.exemplar.size" : {"exemplar-cache-size" },
68
- "metrics.cache.labels.size" : {"labels-cache-size" },
69
- "metrics.cache.metrics.size" : {"metrics-cache-size" },
70
- "metrics.cache.series.initial-size" : {"series-cache-initial-size" },
71
- "metrics.cache.series.max-bytes" : {"series-cache-max-bytes" },
72
- "metrics.high-availability" : {"high-availability" },
73
- "metrics.ignore-samples-written-to-compressed-chunks" : {"ignore-samples-written-to-compressed-chunks" },
74
- "metrics.multi-tenancy" : {"multi-tenancy" },
75
- "metrics.multi-tenancy.allow-non-tenants" : {"multi-tenancy-allow-non-tenants" },
76
- "metrics.multi-tenancy.valid-tenants" : {"multi-tenancy-valid-tenants" },
77
- "metrics.promql.default-subquery-step-interval" : {"promql-default-subquery-step-interval" },
78
- "metrics.promql.lookback-delta" : {"promql-lookback-delta" },
79
- "metrics.promql.max-points-per-ts" : {"promql-max-points-per-ts" },
80
- "metrics.promql.max-samples" : {"promql-max-samples" },
81
- "metrics.promql.query-timeout" : {"promql-query-timeout" },
82
- "startup.install-extensions" : {"install-extensions" },
83
- "startup.upgrade-extensions" : {"upgrade-extensions" },
84
- "startup.upgrade-prerelease-extensions" : {"upgrade-prerelease-extensions" },
85
- "startup.use-schema-version-lease" : {"use-schema-version-lease" },
86
- "telemetry.log.format" : {"log-format" },
87
- "telemetry.log.level" : {"log-level" },
88
- "telemetry.log.throughput-report-interval" : {"tput-report" },
89
- "thanos.store-api.server-address" : {"thanos-store-api-listen-address" },
90
- "tracing.otlp.server-address" : {"otlp-grpc-server-listen-address" },
91
- "web.auth.bearer-token" : {"bearer-token" },
92
- "web.auth.bearer-token-file" : {"bearer-token-file" },
93
- "web.auth.password" : {"auth-password" },
94
- "web.auth.password-file" : {"auth-password-file" },
95
- "web.auth.username" : {"auth-username" },
96
- "web.cors-origin" : {"web-cors-origin" },
97
- "web.enable-admin-api" : {"web-enable-admin-api" },
98
- "web.listen-address" : {"web-listen-address" },
99
- "web.telemetry-path" : {"web-telemetry-path" },
100
- }
49
+ var (
50
+ aliasDescTemplate = "Alias for -%s flag. "
51
+ deprecatedFlagSuffix = "(DEPRECATED) Will be removed in version 0.11.0"
52
+ flagAliases = map [string ][]string {
53
+ "auth.tls-cert-file" : {"tls-cert-file" },
54
+ "auth.tls-key-file" : {"tls-key-file" },
55
+ "cache.memory-target" : {"memory-target" },
56
+ "db.app" : {"app" },
57
+ "db.connection-timeout" : {"db-connection-timeout" },
58
+ "db.connections-max" : {"db-connections-max" },
59
+ "db.host" : {"db-host" },
60
+ "db.name" : {"db-name" },
61
+ "db.num-writer-connections" : {"db-writer-connection-concurrency" },
62
+ "db.password" : {"db-password" },
63
+ "db.port" : {"db-port" },
64
+ "db.read-only" : {"read-only" },
65
+ "db.ssl-mode" : {"db-ssl-mode" },
66
+ "db.statements-cache" : {"db-statements-cache" },
67
+ "db.uri" : {"db-uri" },
68
+ "db.user" : {"db-user" },
69
+ "metrics.async-acks" : {"async-acks" },
70
+ "metrics.cache.exemplar.size" : {"exemplar-cache-size" },
71
+ "metrics.cache.labels.size" : {"labels-cache-size" },
72
+ "metrics.cache.metrics.size" : {"metrics-cache-size" },
73
+ "metrics.cache.series.initial-size" : {"series-cache-initial-size" },
74
+ "metrics.cache.series.max-bytes" : {"series-cache-max-bytes" },
75
+ "metrics.high-availability" : {"high-availability" },
76
+ "metrics.ignore-samples-written-to-compressed-chunks" : {"ignore-samples-written-to-compressed-chunks" },
77
+ "metrics.multi-tenancy" : {"multi-tenancy" },
78
+ "metrics.multi-tenancy.allow-non-tenants" : {"multi-tenancy-allow-non-tenants" },
79
+ "metrics.multi-tenancy.valid-tenants" : {"multi-tenancy-valid-tenants" },
80
+ "metrics.promql.default-subquery-step-interval" : {"promql-default-subquery-step-interval" },
81
+ "metrics.promql.lookback-delta" : {"promql-lookback-delta" },
82
+ "metrics.promql.max-points-per-ts" : {"promql-max-points-per-ts" },
83
+ "metrics.promql.max-samples" : {"promql-max-samples" },
84
+ "metrics.promql.query-timeout" : {"promql-query-timeout" },
85
+ "startup.install-extensions" : {"install-extensions" },
86
+ "startup.upgrade-extensions" : {"upgrade-extensions" },
87
+ "startup.upgrade-prerelease-extensions" : {"upgrade-prerelease-extensions" },
88
+ "startup.use-schema-version-lease" : {"use-schema-version-lease" },
89
+ "telemetry.log.format" : {"log-format" },
90
+ "telemetry.log.level" : {"log-level" },
91
+ "telemetry.log.throughput-report-interval" : {"tput-report" },
92
+ "thanos.store-api.server-address" : {"thanos-store-api-listen-address" },
93
+ "tracing.otlp.server-address" : {"otlp-grpc-server-listen-address" },
94
+ "web.auth.bearer-token" : {"bearer-token" },
95
+ "web.auth.bearer-token-file" : {"bearer-token-file" },
96
+ "web.auth.password" : {"auth-password" },
97
+ "web.auth.password-file" : {"auth-password-file" },
98
+ "web.auth.username" : {"auth-username" },
99
+ "web.cors-origin" : {"web-cors-origin" },
100
+ "web.enable-admin-api" : {"web-enable-admin-api" },
101
+ "web.listen-address" : {"web-listen-address" },
102
+ "web.telemetry-path" : {"web-telemetry-path" },
103
+ }
104
+ )
101
105
102
106
func ParseFlags (cfg * Config , args []string ) (* Config , error ) {
103
107
var (
@@ -121,7 +125,7 @@ func ParseFlags(cfg *Config, args []string) (*Config, error) {
121
125
fs .StringVar (& cfg .OTLPGRPCListenAddr , "tracing.otlp.server-address" , "" , "Address to listen on for OTLP GRPC server." )
122
126
fs .StringVar (& corsOriginFlag , "web.cors-origin" , ".*" , `Regex for CORS origin. It is fully anchored. Example: 'https?://(domain1|domain2)\.com'` )
123
127
fs .DurationVar (& cfg .ThroughputInterval , "telemetry.log.throughput-report-interval" , time .Second , "Duration interval at which throughput should be reported. Setting duration to `0` will disable reporting throughput, otherwise, an interval with unit must be provided, e.g. `10s` or `3m`." )
124
- fs .StringVar (& migrateOption , "migrate" , "true" , "Update the Prometheus SQL schema to the latest version. Valid options are: [true, false, only]. (DEPRECATED) Will be removed in version 0.11.0" )
128
+ fs .StringVar (& migrateOption , "migrate" , "true" , fmt . Sprintf ( "Update the Prometheus SQL schema to the latest version. Valid options are: [true, false, only]. %s" , deprecatedFlagSuffix ) )
125
129
fs .StringVar (& cfg .DatasetConfig , "startup.dataset.config" , "" , "Dataset configuration in YAML format for Promscale. It is used for setting various dataset configuration like default metric chunk interval" )
126
130
fs .BoolVar (& cfg .StartupOnly , "startup.only" , false , "Only run startup configuration with Promscale (i.e. migrate) and exit. Can be used to run promscale as an init container for HA setups." )
127
131
fs .BoolVar (& skipMigrate , "startup.skip-migrate" , false , "Skip migrating Promscale SQL schema to latest version on startup." )
@@ -133,7 +137,7 @@ func ParseFlags(cfg *Config, args []string) (*Config, error) {
133
137
fs .StringVar (& cfg .TLSCertFile , "auth.tls-cert-file" , "" , "TLS Certificate file used for server authentication, leave blank to disable TLS. NOTE: this option is used for all servers that Promscale runs (web and GRPC)." )
134
138
fs .StringVar (& cfg .TLSKeyFile , "auth.tls-key-file" , "" , "TLS Key file for server authentication, leave blank to disable TLS. NOTE: this option is used for all servers that Promscale runs (web and GRPC)." )
135
139
136
- util . AddAliases (fs , flagAliases , "(DEPRECATED) Will be removed in version 0.11.0" )
140
+ addAliases (fs , flagAliases , deprecatedFlagSuffix )
137
141
138
142
if err := util .ParseEnv ("PROMSCALE" , fs ); err != nil {
139
143
return nil , fmt .Errorf ("error parsing env variables: %w" , err )
@@ -147,6 +151,23 @@ func ParseFlags(cfg *Config, args []string) (*Config, error) {
147
151
return nil , fmt .Errorf ("configuration error: %w" , err )
148
152
}
149
153
154
+ // Warn about deprecated flags.
155
+ if flagsForUpdate := deprecatedFlagsUsed (fs ); len (flagsForUpdate ) > 0 {
156
+ log .Warn ("msg" , "Using deprecated flags that will be dropped in a future version. Please update to new flag names." )
157
+ for oldFlag , newFlag := range flagsForUpdate {
158
+ log .Warn ("msg" , fmt .Sprintf ("Update deprecated flag %s to new flag %s" , oldFlag , newFlag ))
159
+ }
160
+ }
161
+ // Migrate flag is a special case that needs to be logged separately.
162
+ switch migrateOption {
163
+ case "false" :
164
+ log .Warn ("msg" , "Using deprecated flag `migrate` set to `false` which will be dropped in a future version. " +
165
+ "Please update you configuration by using `startup.skip-migrate` flag." )
166
+ case "only" :
167
+ log .Warn ("msg" , "Using deprecated flag `migrate` set to `only` which will be dropped in a future version. " +
168
+ "Please update you configuration by using `startup.only` flag." )
169
+ }
170
+
150
171
// Checking if TLS files are not both set or both empty.
151
172
if (cfg .TLSCertFile != "" ) != (cfg .TLSKeyFile != "" ) {
152
173
return nil , fmt .Errorf ("both TLS Ceriticate File and TLS Key File need to be provided for a valid TLS configuration" )
@@ -225,3 +246,52 @@ func validate(cfg *Config) error {
225
246
}
226
247
return nil
227
248
}
249
+
250
+ func addAliases (fs * flag.FlagSet , aliases map [string ][]string , descSuffix string ) {
251
+ aliasDescFormat := aliasDescTemplate + descSuffix
252
+ set := false
253
+ fs .VisitAll (func (f * flag.Flag ) {
254
+ if flagAliases , ok := aliases [f .Name ]; ok {
255
+ set = false
256
+ for _ , alias := range flagAliases {
257
+ set = true
258
+ fs .Var (f .Value , alias , fmt .Sprintf (aliasDescFormat , f .Name ))
259
+ }
260
+
261
+ if ! set {
262
+ panic (fmt .Sprintf ("trying to set an flag alias for a flag that is missing: %s" , f .Name ))
263
+ }
264
+ }
265
+ })
266
+ }
267
+
268
+ func deprecatedFlagsUsed (fs * flag.FlagSet ) map [string ]string {
269
+ var (
270
+ result = make (map [string ]string )
271
+ newFlagName string
272
+ count int
273
+ )
274
+
275
+ fs .Visit (func (f * flag.Flag ) {
276
+ if strings .Contains (f .Usage , deprecatedFlagSuffix ) {
277
+ i , err := fmt .Sscanf (f .Usage , aliasDescTemplate , & newFlagName )
278
+
279
+ switch {
280
+ case f .Name == "migrate" :
281
+ // Migrate flag is a special case since it's not just a rename
282
+ // of an old flag. We handle it separately when logging
283
+ // use of deprecated flags.
284
+ return
285
+ case err != nil :
286
+ fallthrough
287
+ case i != 1 :
288
+ panic ("deprecated flag usage not set in the correct format" )
289
+ }
290
+
291
+ result [f .Name ] = newFlagName
292
+ count ++
293
+ }
294
+ })
295
+
296
+ return result
297
+ }
0 commit comments