Skip to content

Commit 3efe528

Browse files
committed
Update label name
Signed-off-by: Daniel Blando <[email protected]>
1 parent 5f788a1 commit 3efe528

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

pkg/distributor/distributor.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ const (
5757
typeSamples = "samples"
5858
typeMetadata = "metadata"
5959

60-
statusFamily5xx = "5xx"
61-
statusFamily4xx = "4xx"
62-
6360
instanceIngestionRateTickInterval = time.Second
6461
)
6562

@@ -303,7 +300,7 @@ func New(cfg Config, clientConfig ingester_client.Config, limits *validation.Ove
303300
Namespace: "cortex",
304301
Name: "distributor_ingester_append_failures_total",
305302
Help: "The total number of failed batch appends sent to ingesters.",
306-
}, []string{"ingester", "type", "statusFamily"}),
303+
}, []string{"ingester", "type", "status"}),
307304
ingesterQueries: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
308305
Namespace: "cortex",
309306
Name: "distributor_ingester_queries_total",
@@ -822,27 +819,27 @@ func (d *Distributor) send(ctx context.Context, ingester ring.InstanceDesc, time
822819
if len(metadata) > 0 {
823820
d.ingesterAppends.WithLabelValues(ingester.Addr, typeMetadata).Inc()
824821
if err != nil {
825-
d.ingesterAppendFailures.WithLabelValues(ingester.Addr, typeMetadata, getStatusFamily(err)).Inc()
822+
d.ingesterAppendFailures.WithLabelValues(ingester.Addr, typeMetadata, getErrorStatus(err)).Inc()
826823
}
827824
}
828825
if len(timeseries) > 0 {
829826
d.ingesterAppends.WithLabelValues(ingester.Addr, typeSamples).Inc()
830827
if err != nil {
831-
d.ingesterAppendFailures.WithLabelValues(ingester.Addr, typeSamples, getStatusFamily(err)).Inc()
828+
d.ingesterAppendFailures.WithLabelValues(ingester.Addr, typeSamples, getErrorStatus(err)).Inc()
832829
}
833830
}
834831

835832
return err
836833
}
837834

838-
func getStatusFamily(err error) string {
839-
statusFamily := statusFamily5xx
835+
func getErrorStatus(err error) string {
836+
status := "5xx"
840837
httpResp, ok := httpgrpc.HTTPResponseFromError(err)
841838
if ok && httpResp.Code/100 == 4 {
842-
statusFamily = statusFamily4xx
839+
status = "4xx"
843840
}
844841

845-
return statusFamily
842+
return status
846843
}
847844

848845
// ForReplicationSet runs f, in parallel, for all ingesters in the input replication set.

pkg/distributor/distributor_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestDistributor_Push(t *testing.T) {
124124
expectedResponse *cortexpb.WriteResponse
125125
expectedError error
126126
expectedMetrics string
127-
ingesterError error
127+
ingesterError error
128128
}{
129129
"A push of no samples shouldn't block or return error, even if ingesters are sad": {
130130
numIngesters: 3,
@@ -204,7 +204,7 @@ func TestDistributor_Push(t *testing.T) {
204204
expectedMetrics: `
205205
# HELP cortex_distributor_ingester_append_failures_total The total number of failed batch appends sent to ingesters.
206206
# TYPE cortex_distributor_ingester_append_failures_total counter
207-
cortex_distributor_ingester_append_failures_total{ingester="2",statusFamily="5xx",type="samples"} 1
207+
cortex_distributor_ingester_append_failures_total{ingester="2",status="5xx",type="samples"} 1
208208
# HELP cortex_distributor_ingester_appends_total The total number of batch appends sent to ingesters.
209209
# TYPE cortex_distributor_ingester_appends_total counter
210210
cortex_distributor_ingester_appends_total{ingester="0",type="samples"} 1
@@ -223,7 +223,7 @@ func TestDistributor_Push(t *testing.T) {
223223
expectedMetrics: `
224224
# HELP cortex_distributor_ingester_append_failures_total The total number of failed batch appends sent to ingesters.
225225
# TYPE cortex_distributor_ingester_append_failures_total counter
226-
cortex_distributor_ingester_append_failures_total{ingester="2",statusFamily="5xx",type="metadata"} 1
226+
cortex_distributor_ingester_append_failures_total{ingester="2",status="5xx",type="metadata"} 1
227227
# HELP cortex_distributor_ingester_appends_total The total number of batch appends sent to ingesters.
228228
# TYPE cortex_distributor_ingester_appends_total counter
229229
cortex_distributor_ingester_appends_total{ingester="0",type="metadata"} 1
@@ -242,7 +242,7 @@ func TestDistributor_Push(t *testing.T) {
242242
expectedMetrics: `
243243
# HELP cortex_distributor_ingester_append_failures_total The total number of failed batch appends sent to ingesters.
244244
# TYPE cortex_distributor_ingester_append_failures_total counter
245-
cortex_distributor_ingester_append_failures_total{ingester="2",statusFamily="4xx",type="metadata"} 1
245+
cortex_distributor_ingester_append_failures_total{ingester="2",status="4xx",type="metadata"} 1
246246
# HELP cortex_distributor_ingester_appends_total The total number of batch appends sent to ingesters.
247247
# TYPE cortex_distributor_ingester_appends_total counter
248248
cortex_distributor_ingester_appends_total{ingester="0",type="metadata"} 1
@@ -1939,15 +1939,15 @@ func prepare(t *testing.T, cfg prepConfig) ([]*Distributor, []mockIngester, *rin
19391939
})
19401940
}
19411941
for i := cfg.happyIngesters; i < cfg.numIngesters; i++ {
1942-
mi := mockIngester{
1943-
queryDelay: cfg.queryDelay,
1944-
errFail: errFail,
1945-
}
1942+
miError := errFail
19461943
if cfg.errFail != nil {
1947-
mi.errFail = cfg.errFail
1944+
miError = cfg.errFail
19481945
}
19491946

1950-
ingesters = append(ingesters, mi)
1947+
ingesters = append(ingesters, mockIngester{
1948+
queryDelay: cfg.queryDelay,
1949+
failResp: miError,
1950+
})
19511951
}
19521952

19531953
// Use a real ring with a mock KV store to test ring RF logic.
@@ -2178,7 +2178,7 @@ type mockIngester struct {
21782178
client.IngesterClient
21792179
grpc_health_v1.HealthClient
21802180
happy bool
2181-
errFail error
2181+
failResp error
21822182
stats client.UsersStatsResponse
21832183
timeseries map[uint32]*cortexpb.PreallocTimeseries
21842184
metadata map[uint32]map[cortexpb.MetricMetadata]struct{}
@@ -2217,7 +2217,7 @@ func (i *mockIngester) Push(ctx context.Context, req *cortexpb.WriteRequest, opt
22172217
i.trackCall("Push")
22182218

22192219
if !i.happy {
2220-
return nil, i.errFail
2220+
return nil, i.failResp
22212221
}
22222222

22232223
if i.timeseries == nil {

0 commit comments

Comments
 (0)