Skip to content

Commit 5cd9662

Browse files
committed
Emit max concurrency metric
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
1 parent 36683a3 commit 5cd9662

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* [ENHANCEMENT] Update Go version to 1.20.4. #5299
1515
* [ENHANCEMENT] Log: Avoid expensive log.Valuer evaluation for disallowed levels. #5297
1616
* [ENHANCEMENT] Improving Performance on the API Gzip Handler. #5347
17+
* [ENHANCEMENT] Emit querier `max_concurrent` as a metric. #5362
1718
* [BUGFIX] Ruler: Validate if rule group can be safely converted back to rule group yaml from protobuf message #5265
1819
* [BUGFIX] Querier: Convert gRPC `ResourceExhausted` status code from store gateway to 422 limit error. #5286
1920
* [BUGFIX] Alertmanager: Route web-ui requests to the alertmanager distributor when sharding is enabled. #5293

pkg/querier/querier.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/go-kit/log"
1313
"github.com/go-kit/log/level"
1414
"github.com/prometheus/client_golang/prometheus"
15+
"github.com/prometheus/client_golang/prometheus/promauto"
1516
"github.com/prometheus/common/model"
1617
"github.com/prometheus/prometheus/model/labels"
1718
"github.com/prometheus/prometheus/promql"
@@ -173,6 +174,14 @@ func New(cfg Config, limits *validation.Overrides, distributor Distributor, stor
173174
return lazyquery.NewLazyQuerier(querier), nil
174175
})
175176

177+
// Emit max_concurrent config as a metric.
178+
maxConcurrentMetric := promauto.With(reg).NewGauge(prometheus.GaugeOpts{
179+
Namespace: "cortex",
180+
Name: "max_concurrent_queries",
181+
Help: "The maximum number of concurrent queries.",
182+
})
183+
maxConcurrentMetric.Set(float64(cfg.MaxConcurrent))
184+
176185
var queryEngine v1.QueryEngine
177186
opts := promql.EngineOpts{
178187
Logger: logger,

pkg/querier/querier_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import (
3838
"github.com/cortexproject/cortex/pkg/util/chunkcompat"
3939
"github.com/cortexproject/cortex/pkg/util/flagext"
4040
"github.com/cortexproject/cortex/pkg/util/validation"
41+
42+
"github.com/prometheus/client_golang/prometheus"
43+
promutil "github.com/prometheus/client_golang/prometheus/testutil"
4144
)
4245

4346
const (
@@ -363,6 +366,28 @@ func TestQuerier(t *testing.T) {
363366
}
364367
}
365368

369+
func TestQuerierMetric(t *testing.T) {
370+
var cfg Config
371+
flagext.DefaultValues(&cfg)
372+
cfg.MaxConcurrent = 120
373+
374+
overrides, err := validation.NewOverrides(DefaultLimitsConfig(), nil)
375+
require.NoError(t, err)
376+
377+
chunkStore, through := makeMockChunkStore(t, 24, promchunk.PrometheusXorChunk)
378+
distributor := mockDistibutorFor(t, chunkStore, through)
379+
380+
queryables := []QueryableWithFilter{}
381+
r := prometheus.NewRegistry()
382+
reg := prometheus.WrapRegistererWith(prometheus.Labels{"engine": "querier"}, r)
383+
New(cfg, overrides, distributor, queryables, purger.NewNoopTombstonesLoader(), reg, log.NewNopLogger())
384+
assert.NoError(t, promutil.GatherAndCompare(r, strings.NewReader(`
385+
# HELP cortex_max_concurrent_queries The maximum number of concurrent queries.
386+
# TYPE cortex_max_concurrent_queries gauge
387+
cortex_max_concurrent_queries{engine="querier"} 120
388+
`), "cortex_max_concurrent_queries"))
389+
}
390+
366391
func mockTSDB(t *testing.T, labels []labels.Labels, mint model.Time, samples int, step, chunkOffset time.Duration, samplesPerChunk int) (storage.Queryable, []cortexpb.Sample) {
367392
//parallel testing causes data race
368393
opts := tsdb.DefaultHeadOptions()

0 commit comments

Comments
 (0)