From 8aff32e5cdcfc1ec230f09c826fba7b0780d1679 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Sun, 6 Apr 2025 01:45:54 +0530 Subject: [PATCH 1/6] enable promql-experimental-functions Signed-off-by: Sujal Gupta --- cmd/thanos/query.go | 16 ++++++++++++---- pkg/api/query/engine.go | 6 ++++-- pkg/queryfrontend/config.go | 1 + test/e2e/e2ethanos/services.go | 6 ++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index afacef9252..3fc0d2d5d6 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -53,9 +53,10 @@ import ( ) const ( - promqlNegativeOffset = "promql-negative-offset" - promqlAtModifier = "promql-at-modifier" - queryPushdown = "query-pushdown" + promqlNegativeOffset = "promql-negative-offset" + promqlAtModifier = "promql-at-modifier" + queryPushdown = "query-pushdown" + promqlExperimentalFunctions = "promql-experimental-functions" ) // registerQuery registers a query command. @@ -133,9 +134,10 @@ func registerQuery(app *extkingpin.App) { enableMetricMetadataPartialResponse := cmd.Flag("metric-metadata.partial-response", "Enable partial response for metric metadata endpoint. --no-metric-metadata.partial-response for disabling."). Hidden().Default("true").Bool() + enableQueryExperimentalFunctions := cmd.Flag("--enable-feature=promql-experimental-functions", "Enable experimental functions for queries.") activeQueryDir := cmd.Flag("query.active-query-path", "Directory to log currently active queries in the queries.active file.").Default("").String() - featureList := cmd.Flag("enable-feature", "Comma separated experimental feature names to enable.The current list of features is empty.").Hidden().Default("").Strings() + featureList := cmd.Flag("enable-feature", "Comma separated experimental feature names to enable. The current list of features is: promql-experimental-functions (enables experimental PromQL functions).").Hidden().Default("").Strings() enableExemplarPartialResponse := cmd.Flag("exemplar.partial-response", "Enable partial response for exemplar endpoint. --no-exemplar.partial-response for disabling."). Hidden().Default("true").Bool() @@ -217,6 +219,9 @@ func registerQuery(app *extkingpin.App) { if feature == queryPushdown { level.Warn(logger).Log("msg", "This option for --enable-feature is now permanently deprecated and therefore ignored.", "option", queryPushdown) } + if feature == promqlExperimentalFunctions { + level.Warn(logger).Log("msg", "This option for --enable-feature is now permanently enabled and therefore a no-op.", "option", promqlExperimentalFunctions) + } } httpLogOpts, err := logging.ParseHTTPOptions(reqLogConfig) @@ -317,6 +322,7 @@ func registerQuery(app *extkingpin.App) { *enableTargetPartialResponse, *enableMetricMetadataPartialResponse, *enableExemplarPartialResponse, + *enableQueryExperimentalFunctions, *activeQueryDir, time.Duration(*instantDefaultMaxSourceResolution), *defaultMetadataTimeRange, @@ -379,6 +385,7 @@ func runQuery( enableTargetPartialResponse bool, enableMetricMetadataPartialResponse bool, enableExemplarPartialResponse bool, + enableQueryExperimentalFunctions bool, activeQueryDir string, instantDefaultMaxSourceResolution time.Duration, defaultMetadataTimeRange time.Duration, @@ -513,6 +520,7 @@ func runQuery( enableRulePartialResponse, enableTargetPartialResponse, enableMetricMetadataPartialResponse, + enableQueryExperimentalFunctions, enableExemplarPartialResponse, queryReplicaLabels, flagsMap, diff --git a/pkg/api/query/engine.go b/pkg/api/query/engine.go index a1f5e7221b..e93eba46d4 100644 --- a/pkg/api/query/engine.go +++ b/pkg/api/query/engine.go @@ -88,6 +88,7 @@ func NewQueryFactory( lookbackDelta time.Duration, evaluationInterval time.Duration, enableXFunctions bool, + enableQueryExperimentalFunctions bool, activeQueryTracker *promql.ActiveQueryTracker, mode PromqlQueryMode, ) *QueryFactory { @@ -106,8 +107,9 @@ func NewQueryFactory( EnableNegativeOffset: true, EnableAtModifier: true, }, - EnableXFunctions: enableXFunctions, - EnableAnalysis: true, + EnableXFunctions: enableXFunctions, + EnableQueryExperimentalFunctions: enableQueryExperimentalFunctions, + EnableAnalysis: true, } if activeQueryTracker != nil { opts.ActiveQueryTracker = activeQueryTracker diff --git a/pkg/queryfrontend/config.go b/pkg/queryfrontend/config.go index d2a9b51a4d..b557883b99 100644 --- a/pkg/queryfrontend/config.go +++ b/pkg/queryfrontend/config.go @@ -213,6 +213,7 @@ type Config struct { DefaultTenant string TenantCertField string EnableXFunctions bool + EnableQueryExperimentalFunctions bool } // QueryRangeConfig holds the config for query range tripperware. diff --git a/test/e2e/e2ethanos/services.go b/test/e2e/e2ethanos/services.go index 916e265423..79b90c4035 100644 --- a/test/e2e/e2ethanos/services.go +++ b/test/e2e/e2ethanos/services.go @@ -282,6 +282,7 @@ type QuerierBuilder struct { queryDistributedWithOverlappingInterval bool enableXFunctions bool deduplicationFunc string + enableQueryExperimentalFunctions bool replicaLabels []string tracingConfig string @@ -391,6 +392,11 @@ func (q *QuerierBuilder) WithEnableXFunctions() *QuerierBuilder { return q } +func (q *QuerierBuilder) WithEnableExperimentalFunctions() *QuerierBuilder { + q.enableQueryExperimentalFunctions = true + return q +} + func (q *QuerierBuilder) WithDeduplicationFunc(deduplicationFunc string) *QuerierBuilder { q.deduplicationFunc = deduplicationFunc return q From e5b0d3c9543d908bf6bb37236f678e90d9423ffd Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Sun, 6 Apr 2025 01:55:01 +0530 Subject: [PATCH 2/6] fix lint error Signed-off-by: Sujal Gupta --- pkg/api/query/engine.go | 6 +++--- pkg/queryfrontend/config.go | 22 +++++++++++----------- test/e2e/e2ethanos/services.go | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/api/query/engine.go b/pkg/api/query/engine.go index e93eba46d4..d129e24e4e 100644 --- a/pkg/api/query/engine.go +++ b/pkg/api/query/engine.go @@ -107,9 +107,9 @@ func NewQueryFactory( EnableNegativeOffset: true, EnableAtModifier: true, }, - EnableXFunctions: enableXFunctions, - EnableQueryExperimentalFunctions: enableQueryExperimentalFunctions, - EnableAnalysis: true, + EnableXFunctions: enableXFunctions, + EnableQueryExperimentalFunctions: enableQueryExperimentalFunctions, + EnableAnalysis: true, } if activeQueryTracker != nil { opts.ActiveQueryTracker = activeQueryTracker diff --git a/pkg/queryfrontend/config.go b/pkg/queryfrontend/config.go index b557883b99..ae56ba3fdb 100644 --- a/pkg/queryfrontend/config.go +++ b/pkg/queryfrontend/config.go @@ -202,17 +202,17 @@ type Config struct { LabelsConfig DownstreamTripperConfig - CortexHandlerConfig *transport.HandlerConfig - CompressResponses bool - CacheCompression string - RequestLoggingDecision string - DownstreamURL string - ForwardHeaders []string - NumShards int - TenantHeader string - DefaultTenant string - TenantCertField string - EnableXFunctions bool + CortexHandlerConfig *transport.HandlerConfig + CompressResponses bool + CacheCompression string + RequestLoggingDecision string + DownstreamURL string + ForwardHeaders []string + NumShards int + TenantHeader string + DefaultTenant string + TenantCertField string + EnableXFunctions bool EnableQueryExperimentalFunctions bool } diff --git a/test/e2e/e2ethanos/services.go b/test/e2e/e2ethanos/services.go index 79b90c4035..a8a15bd424 100644 --- a/test/e2e/e2ethanos/services.go +++ b/test/e2e/e2ethanos/services.go @@ -282,7 +282,7 @@ type QuerierBuilder struct { queryDistributedWithOverlappingInterval bool enableXFunctions bool deduplicationFunc string - enableQueryExperimentalFunctions bool + enableQueryExperimentalFunctions bool replicaLabels []string tracingConfig string From 95f9ce65158bfe96f08762b20e1f50ecd86e6626 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Sun, 6 Apr 2025 02:09:16 +0530 Subject: [PATCH 3/6] update changelog Signed-off-by: Sujal Gupta --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7718364cdb..e753b0cb8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Added +- [#8191](https://github.com/thanos-io/thanos/pull/8191) Query: Add `--enable-feature=promql-experimental-functions` flag to enable experimental functions in query. + ### Changed ### Removed From f53f873618e7d244227abd5e23df5e5ec36ac1b0 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Mon, 7 Apr 2025 17:29:22 +0200 Subject: [PATCH 4/6] Sidecar: increase default prometheus timeout (#8192) Adjust the default get-config timeout to match the default get-config interval. Signed-off-by: Michael Hoffmann Signed-off-by: Sujal Gupta --- CHANGELOG.md | 2 ++ cmd/thanos/config.go | 2 +- docs/components/sidecar.md | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e753b0cb8c..911f616db2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Changed +- [#8192](https://github.com/thanos-io/thanos/pull/8192) Sidecar: fix default get config timeout + ### Removed ### Fixed diff --git a/cmd/thanos/config.go b/cmd/thanos/config.go index f16f885737..a7ea6aa29c 100644 --- a/cmd/thanos/config.go +++ b/cmd/thanos/config.go @@ -136,7 +136,7 @@ func (pc *prometheusConfig) registerFlag(cmd extkingpin.FlagClause) *prometheusC Default("30s").DurationVar(&pc.getConfigInterval) cmd.Flag("prometheus.get_config_timeout", "Timeout for getting Prometheus config"). - Default("5s").DurationVar(&pc.getConfigTimeout) + Default("30s").DurationVar(&pc.getConfigTimeout) pc.httpClient = extflag.RegisterPathOrContent( cmd, "prometheus.http-client", diff --git a/docs/components/sidecar.md b/docs/components/sidecar.md index 01295a5d4d..b72f30aea5 100644 --- a/docs/components/sidecar.md +++ b/docs/components/sidecar.md @@ -161,7 +161,7 @@ Flags: https://thanos.io/tip/thanos/storage.md/#configuration --prometheus.get_config_interval=30s How often to get Prometheus config - --prometheus.get_config_timeout=5s + --prometheus.get_config_timeout=30s Timeout for getting Prometheus config --prometheus.http-client= Alternative to 'prometheus.http-client-file' From f85b8e766d04648f9718329f13cb73669f099aac Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Sat, 19 Apr 2025 23:09:44 +0530 Subject: [PATCH 5/6] enable experimental function using parser Signed-off-by: Sujal Gupta --- cmd/thanos/query.go | 7 +------ pkg/api/query/engine.go | 11 +++++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 3fc0d2d5d6..c454f31844 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -133,8 +133,7 @@ func registerQuery(app *extkingpin.App) { enableMetricMetadataPartialResponse := cmd.Flag("metric-metadata.partial-response", "Enable partial response for metric metadata endpoint. --no-metric-metadata.partial-response for disabling."). Hidden().Default("true").Bool() - - enableQueryExperimentalFunctions := cmd.Flag("--enable-feature=promql-experimental-functions", "Enable experimental functions for queries.") + activeQueryDir := cmd.Flag("query.active-query-path", "Directory to log currently active queries in the queries.active file.").Default("").String() featureList := cmd.Flag("enable-feature", "Comma separated experimental feature names to enable. The current list of features is: promql-experimental-functions (enables experimental PromQL functions).").Hidden().Default("").Strings() @@ -219,9 +218,6 @@ func registerQuery(app *extkingpin.App) { if feature == queryPushdown { level.Warn(logger).Log("msg", "This option for --enable-feature is now permanently deprecated and therefore ignored.", "option", queryPushdown) } - if feature == promqlExperimentalFunctions { - level.Warn(logger).Log("msg", "This option for --enable-feature is now permanently enabled and therefore a no-op.", "option", promqlExperimentalFunctions) - } } httpLogOpts, err := logging.ParseHTTPOptions(reqLogConfig) @@ -322,7 +318,6 @@ func registerQuery(app *extkingpin.App) { *enableTargetPartialResponse, *enableMetricMetadataPartialResponse, *enableExemplarPartialResponse, - *enableQueryExperimentalFunctions, *activeQueryDir, time.Duration(*instantDefaultMaxSourceResolution), *defaultMetadataTimeRange, diff --git a/pkg/api/query/engine.go b/pkg/api/query/engine.go index d129e24e4e..ab22ecf6bf 100644 --- a/pkg/api/query/engine.go +++ b/pkg/api/query/engine.go @@ -27,6 +27,7 @@ import ( "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/prometheus/promql" + "github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/storage" "github.com/thanos-io/promql-engine/api" @@ -88,11 +89,14 @@ func NewQueryFactory( lookbackDelta time.Duration, evaluationInterval time.Duration, enableXFunctions bool, - enableQueryExperimentalFunctions bool, + enablePromQLExperimentalFunctions bool, activeQueryTracker *promql.ActiveQueryTracker, mode PromqlQueryMode, ) *QueryFactory { makeOpts := func(registry prometheus.Registerer) engine.Opts { + // Set global experimental functions flag + parser.EnableExperimentalFunctions = enablePromQLExperimentalFunctions + opts := engine.Opts{ EngineOpts: promql.EngineOpts{ Logger: logutil.GoKitLogToSlog(logger), @@ -107,9 +111,8 @@ func NewQueryFactory( EnableNegativeOffset: true, EnableAtModifier: true, }, - EnableXFunctions: enableXFunctions, - EnableQueryExperimentalFunctions: enableQueryExperimentalFunctions, - EnableAnalysis: true, + EnableXFunctions: enableXFunctions, + EnableAnalysis: true, } if activeQueryTracker != nil { opts.ActiveQueryTracker = activeQueryTracker From 706b3c24ddc575dc30facf6bb8a750ce52d95614 Mon Sep 17 00:00:00 2001 From: Sujal Gupta Date: Sat, 19 Apr 2025 23:32:50 +0530 Subject: [PATCH 6/6] fix build Signed-off-by: Sujal Gupta --- cmd/thanos/query.go | 5 +++-- pkg/api/query/v1_test.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index c454f31844..ecf03b3ac9 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -133,7 +133,7 @@ func registerQuery(app *extkingpin.App) { enableMetricMetadataPartialResponse := cmd.Flag("metric-metadata.partial-response", "Enable partial response for metric metadata endpoint. --no-metric-metadata.partial-response for disabling."). Hidden().Default("true").Bool() - + activeQueryDir := cmd.Flag("query.active-query-path", "Directory to log currently active queries in the queries.active file.").Default("").String() featureList := cmd.Flag("enable-feature", "Comma separated experimental feature names to enable. The current list of features is: promql-experimental-functions (enables experimental PromQL functions).").Hidden().Default("").Strings() @@ -318,6 +318,7 @@ func registerQuery(app *extkingpin.App) { *enableTargetPartialResponse, *enableMetricMetadataPartialResponse, *enableExemplarPartialResponse, + false, *activeQueryDir, time.Duration(*instantDefaultMaxSourceResolution), *defaultMetadataTimeRange, @@ -466,6 +467,7 @@ func runQuery( lookbackDelta, defaultEvaluationInterval, extendedFunctionsEnabled, + enableQueryExperimentalFunctions, activeQueryTracker, queryMode, ) @@ -515,7 +517,6 @@ func runQuery( enableRulePartialResponse, enableTargetPartialResponse, enableMetricMetadataPartialResponse, - enableQueryExperimentalFunctions, enableExemplarPartialResponse, queryReplicaLabels, flagsMap, diff --git a/pkg/api/query/v1_test.go b/pkg/api/query/v1_test.go index b410c67427..2fc926bbbc 100644 --- a/pkg/api/query/v1_test.go +++ b/pkg/api/query/v1_test.go @@ -97,6 +97,7 @@ var ( 5*time.Minute, 30*time.Second, true, + false, nil, PromqlQueryModeLocal, )