Skip to content

Commit d6f0d23

Browse files
authored
Enhance cortex_ingester_inflight_push_requests metric (#6437)
Signed-off-by: alanprot <[email protected]>
1 parent 27d68c2 commit d6f0d23

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

pkg/ingester/ingester.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ type Ingester struct {
233233
TSDBState TSDBState
234234

235235
// Rate of pushed samples. Only used by V2-ingester to limit global samples push rate.
236-
ingestionRate *util_math.EwmaRate
237-
inflightPushRequests atomic.Int64
236+
ingestionRate *util_math.EwmaRate
237+
inflightPushRequests atomic.Int64
238+
maxInflightPushRequests util_math.MaxTracker
238239

239240
inflightQueryRequests atomic.Int64
240241
maxInflightQueryRequests util_math.MaxTracker
@@ -710,7 +711,7 @@ func New(cfg Config, limits *validation.Overrides, registerer prometheus.Registe
710711
cfg.ActiveSeriesMetricsEnabled,
711712
i.getInstanceLimits,
712713
i.ingestionRate,
713-
&i.inflightPushRequests,
714+
&i.maxInflightPushRequests,
714715
&i.maxInflightQueryRequests,
715716
cfg.BlocksStorageConfig.TSDB.PostingsCache.Blocks.Enabled || cfg.BlocksStorageConfig.TSDB.PostingsCache.Head.Enabled)
716717
i.validateMetrics = validation.NewValidateMetrics(registerer)
@@ -792,7 +793,7 @@ func NewForFlusher(cfg Config, limits *validation.Overrides, registerer promethe
792793
false,
793794
i.getInstanceLimits,
794795
nil,
795-
&i.inflightPushRequests,
796+
&i.maxInflightPushRequests,
796797
&i.maxInflightQueryRequests,
797798
cfg.BlocksStorageConfig.TSDB.PostingsCache.Blocks.Enabled || cfg.BlocksStorageConfig.TSDB.PostingsCache.Head.Enabled,
798799
)
@@ -918,8 +919,8 @@ func (i *Ingester) updateLoop(ctx context.Context) error {
918919
metadataPurgeTicker := time.NewTicker(metadataPurgePeriod)
919920
defer metadataPurgeTicker.Stop()
920921

921-
maxInflightRequestResetTicker := time.NewTicker(maxInflightRequestResetPeriod)
922-
defer maxInflightRequestResetTicker.Stop()
922+
maxTrackerResetTicker := time.NewTicker(maxInflightRequestResetPeriod)
923+
defer maxTrackerResetTicker.Stop()
923924

924925
for {
925926
select {
@@ -937,8 +938,9 @@ func (i *Ingester) updateLoop(ctx context.Context) error {
937938

938939
case <-activeSeriesTickerChan:
939940
i.updateActiveSeries(ctx)
940-
case <-maxInflightRequestResetTicker.C:
941+
case <-maxTrackerResetTicker.C:
941942
i.maxInflightQueryRequests.Tick()
943+
i.maxInflightPushRequests.Tick()
942944
case <-userTSDBConfigTicker.C:
943945
i.updateUserTSDBConfigs()
944946
case <-ctx.Done():
@@ -1068,6 +1070,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
10681070

10691071
// We will report *this* request in the error too.
10701072
inflight := i.inflightPushRequests.Inc()
1073+
i.maxInflightPushRequests.Track(inflight)
10711074
defer i.inflightPushRequests.Dec()
10721075

10731076
gl := i.getInstanceLimits()

pkg/ingester/metrics.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ingester
33
import (
44
"github.com/prometheus/client_golang/prometheus"
55
"github.com/prometheus/client_golang/prometheus/promauto"
6-
"go.uber.org/atomic"
76

87
"github.com/cortexproject/cortex/pkg/storage/tsdb"
98
"github.com/cortexproject/cortex/pkg/util"
@@ -53,10 +52,12 @@ type ingesterMetrics struct {
5352
maxUsersGauge prometheus.GaugeFunc
5453
maxSeriesGauge prometheus.GaugeFunc
5554
maxIngestionRate prometheus.GaugeFunc
56-
ingestionRate prometheus.GaugeFunc
5755
maxInflightPushRequests prometheus.GaugeFunc
58-
inflightRequests prometheus.GaugeFunc
59-
inflightQueryRequests prometheus.GaugeFunc
56+
57+
// Current Usage
58+
ingestionRate prometheus.GaugeFunc
59+
inflightRequests prometheus.GaugeFunc
60+
inflightQueryRequests prometheus.GaugeFunc
6061

6162
// Posting Cache Metrics
6263
expandedPostingsCacheMetrics *tsdb.ExpandedPostingsCacheMetrics
@@ -67,7 +68,7 @@ func newIngesterMetrics(r prometheus.Registerer,
6768
activeSeriesEnabled bool,
6869
instanceLimitsFn func() *InstanceLimits,
6970
ingestionRate *util_math.EwmaRate,
70-
inflightPushRequests *atomic.Int64,
71+
inflightPushRequests *util_math.MaxTracker,
7172
maxInflightQueryRequests *util_math.MaxTracker,
7273
postingsCacheEnabled bool,
7374
) *ingesterMetrics {

pkg/ingester/metrics_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ import (
88
"github.com/prometheus/client_golang/prometheus/promauto"
99
"github.com/prometheus/client_golang/prometheus/testutil"
1010
"github.com/stretchr/testify/require"
11-
"go.uber.org/atomic"
1211

1312
util_math "github.com/cortexproject/cortex/pkg/util/math"
1413
)
1514

1615
func TestIngesterMetrics(t *testing.T) {
1716
mainReg := prometheus.NewPedanticRegistry()
1817
ingestionRate := util_math.NewEWMARate(0.2, instanceIngestionRateTickInterval)
19-
inflightPushRequests := &atomic.Int64{}
18+
inflightPushRequests := util_math.MaxTracker{}
2019
maxInflightQueryRequests := util_math.MaxTracker{}
2120
maxInflightQueryRequests.Track(98)
22-
inflightPushRequests.Store(14)
21+
inflightPushRequests.Track(14)
2322

2423
m := newIngesterMetrics(mainReg,
2524
false,
@@ -33,7 +32,7 @@ func TestIngesterMetrics(t *testing.T) {
3332
}
3433
},
3534
ingestionRate,
36-
inflightPushRequests,
35+
&inflightPushRequests,
3736
&maxInflightQueryRequests,
3837
false)
3938

0 commit comments

Comments
 (0)