Skip to content

Commit

Permalink
Emit max concurrency metric
Browse files Browse the repository at this point in the history
Signed-off-by: 🌲 Harry 🌊 John 🏔 <johrry@amazon.com>
  • Loading branch information
harry671003 committed May 25, 2023
1 parent 6a63df3 commit 025be2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql"
Expand Down Expand Up @@ -173,6 +174,14 @@ func New(cfg Config, limits *validation.Overrides, distributor Distributor, stor
return lazyquery.NewLazyQuerier(querier), nil
})

// Emit max_concurrent config as a metric.
maxConcurrentMetric := promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Namespace: "cortex",
Name: "querier_max_concurrent",
Help: "The maximum concurrency of the querier.",
})
maxConcurrentMetric.Set(float64(cfg.MaxConcurrent))

var queryEngine v1.QueryEngine
opts := promql.EngineOpts{
Logger: logger,
Expand Down
24 changes: 24 additions & 0 deletions pkg/querier/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import (
"github.com/cortexproject/cortex/pkg/util/chunkcompat"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/cortexproject/cortex/pkg/util/validation"

"github.com/prometheus/client_golang/prometheus"
promutil "github.com/prometheus/client_golang/prometheus/testutil"
)

const (
Expand Down Expand Up @@ -363,6 +366,27 @@ func TestQuerier(t *testing.T) {
}
}

func TestQuerierMetric(t *testing.T) {
var cfg Config
flagext.DefaultValues(&cfg)
cfg.MaxConcurrent = 120

overrides, err := validation.NewOverrides(DefaultLimitsConfig(), nil)
require.NoError(t, err)

chunkStore, through := makeMockChunkStore(t, 24, promchunk.PrometheusXorChunk)
distributor := mockDistibutorFor(t, chunkStore, through)

queryables := []QueryableWithFilter{}
reg := prometheus.NewRegistry()
New(cfg, overrides, distributor, queryables, purger.NewNoopTombstonesLoader(), reg, log.NewNopLogger())
assert.NoError(t, promutil.GatherAndCompare(reg, strings.NewReader(`
# HELP cortex_querier_max_concurrent The maximum concurrency of the querier.
# TYPE cortex_querier_max_concurrent gauge
cortex_querier_max_concurrent 120
`), "cortex_querier_max_concurrent"))
}

func mockTSDB(t *testing.T, labels []labels.Labels, mint model.Time, samples int, step, chunkOffset time.Duration, samplesPerChunk int) (storage.Queryable, []cortexpb.Sample) {
//parallel testing causes data race
opts := tsdb.DefaultHeadOptions()
Expand Down

0 comments on commit 025be2c

Please sign in to comment.