Skip to content

Commit

Permalink
Review comment fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Reid <[email protected]>
  • Loading branch information
Tyler Reid committed Jun 29, 2021
1 parent 7a985e6 commit 2011307
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## master / unreleased
* [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

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

Expand All @@ -26,7 +27,6 @@
* Ensure that a ring store is configured using `-alertmanager.sharding-ring.store`, and set the flags relevant to the chosen store type.
* Enable the feature using `-alertmanager.sharding-enabled`.
* 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.
* [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
* [ENHANCEMENT] Alertmanager: Cleanup persisted state objects from remote storage when a tenant configuration is deleted. #4167
* [ENHANCEMENT] Storage: Added the ability to disable Open Census within GCS client (e.g `-gcs.enable-opencensus=false`). #4219
* [ENHANCEMENT] Etcd: Added username and password to etcd config. #4205
Expand Down
9 changes: 4 additions & 5 deletions pkg/ruler/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ func MetricsQueryFunc(qf rules.QueryFunc, queries, failedQueries prometheus.Coun
return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
queries.Inc()

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

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

Expand Down
4 changes: 2 additions & 2 deletions pkg/ruler/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type Config struct {

RingCheckPeriod time.Duration `yaml:"-"`

RulerEnableQueryStats bool `yaml:"enable_query_stats"`
EnableQueryStats bool `yaml:"query_stats_enabled"`
}

// Validate config and returns error on failure
Expand Down Expand Up @@ -175,7 +175,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
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.")
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.")

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

cfg.RingCheckPeriod = 5 * time.Second
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ruler/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func defaultRulerConfig(store rulestore.RuleStore) (Config, func()) {
cfg.Ring.ListenPort = 0
cfg.Ring.InstanceAddr = "localhost"
cfg.Ring.InstanceID = "localhost"
cfg.RulerEnableQueryStats = false
cfg.EnableQueryStats = false

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

0 comments on commit 2011307

Please sign in to comment.