Skip to content

Commit 2011307

Browse files
author
Tyler Reid
committed
Review comment fixes
Signed-off-by: Tyler Reid <[email protected]>
1 parent 7a985e6 commit 2011307

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## master / unreleased
4+
* [FEATURE] Ruler: Add new `-ruler.query-stats-enabled` which when enabled will report the `cortex_ruler_query_seconds_total` metric that tracks the sum of the wall time of executing queries in the ruler in seconds. #4317
45

56
## 1.10.0-rc.0 / 2021-06-28
67

@@ -26,7 +27,6 @@
2627
* Ensure that a ring store is configured using `-alertmanager.sharding-ring.store`, and set the flags relevant to the chosen store type.
2728
* Enable the feature using `-alertmanager.sharding-enabled`.
2829
* Note the prior addition of a new configuration option `-alertmanager.persist-interval`. This sets the interval between persisting the current alertmanager state (notification log and silences) to object storage. See the [configuration file reference](https://cortexmetrics.io/docs/configuration/configuration-file/#alertmanager_config) for more information.
29-
* [FEATURE] Ruler: Add new `-ruler.enable-query-stats` which when enabled will report the `cortex_ruler_query_seconds_total` metric that tracks the sum of the wall time of executing queries in the ruler in seconds. #4317
3030
* [ENHANCEMENT] Alertmanager: Cleanup persisted state objects from remote storage when a tenant configuration is deleted. #4167
3131
* [ENHANCEMENT] Storage: Added the ability to disable Open Census within GCS client (e.g `-gcs.enable-opencensus=false`). #4219
3232
* [ENHANCEMENT] Etcd: Added username and password to etcd config. #4205

pkg/ruler/compat.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ func MetricsQueryFunc(qf rules.QueryFunc, queries, failedQueries prometheus.Coun
147147
return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
148148
queries.Inc()
149149

150-
var startTime time.Time
151150
// If we've been passed a counter vec we want to record the wall time spent executing this request.
152151
if queryTime != nil {
153-
startTime = time.Now()
154-
defer func() { queryTime.WithLabelValues(userID).Add(time.Since(startTime).Seconds()) }()
152+
timer := prometheus.NewTimer(nil)
153+
defer func() { queryTime.WithLabelValues(userID).Add(timer.ObserveDuration().Seconds()) }()
155154
}
156155

157156
result, err := qf(ctx, qs, t)
@@ -207,10 +206,10 @@ func DefaultTenantManagerFactory(cfg Config, p Pusher, q storage.Queryable, engi
207206
Help: "Number of failed queries by ruler.",
208207
})
209208
var rulerQuerySeconds *prometheus.CounterVec
210-
if cfg.RulerEnableQueryStats {
209+
if cfg.EnableQueryStats {
211210
rulerQuerySeconds = promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
212211
Name: "cortex_ruler_query_seconds_total",
213-
Help: "Total amount of wall clock time spend processing queries by the ruler.",
212+
Help: "Total amount of wall clock time spent processing queries by the ruler.",
214213
}, []string{"user"})
215214
}
216215

pkg/ruler/ruler.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ type Config struct {
116116

117117
RingCheckPeriod time.Duration `yaml:"-"`
118118

119-
RulerEnableQueryStats bool `yaml:"enable_query_stats"`
119+
EnableQueryStats bool `yaml:"query_stats_enabled"`
120120
}
121121

122122
// Validate config and returns error on failure
@@ -175,7 +175,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
175175
f.Var(&cfg.EnabledTenants, "ruler.enabled-tenants", "Comma separated list of tenants whose rules this ruler can evaluate. If specified, only these tenants will be handled by ruler, otherwise this ruler can process rules from all tenants. Subject to sharding.")
176176
f.Var(&cfg.DisabledTenants, "ruler.disabled-tenants", "Comma separated list of tenants whose rules this ruler cannot evaluate. If specified, a ruler that would normally pick the specified tenant(s) for processing will ignore them instead. Subject to sharding.")
177177

178-
f.BoolVar(&cfg.RulerEnableQueryStats, "ruler.enable-query-stats", false, "Report the wall time for ruler queries to complete as a metric.")
178+
f.BoolVar(&cfg.EnableQueryStats, "ruler.query-stats-enabled", false, "Report the wall time for ruler queries to complete as a metric.")
179179

180180
cfg.RingCheckPeriod = 5 * time.Second
181181
}

pkg/ruler/ruler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func defaultRulerConfig(store rulestore.RuleStore) (Config, func()) {
6060
cfg.Ring.ListenPort = 0
6161
cfg.Ring.InstanceAddr = "localhost"
6262
cfg.Ring.InstanceID = "localhost"
63-
cfg.RulerEnableQueryStats = false
63+
cfg.EnableQueryStats = false
6464

6565
// Create a cleanup function that will be called at the end of the test
6666
cleanup := func() {

0 commit comments

Comments
 (0)