Skip to content

Commit

Permalink
Merge pull request prometheus#404 from dgl/draining-labels
Browse files Browse the repository at this point in the history
Ensure requests are checked while draining
  • Loading branch information
beorn7 authored May 18, 2021
2 parents b944c4c + c5ec238 commit bb180b7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 5 additions & 1 deletion storage/diskmetricstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ func (dms *DiskMetricStore) loop(persistenceInterval time.Duration) {
for {
select {
case wr := <-dms.writeQueue:
dms.processWriteRequest(wr)
if dms.checkWriteRequest(wr) {
dms.processWriteRequest(wr)
} else {
dms.setPushFailedTimestamp(wr)
}
default:
dms.done <- dms.persist()
return
Expand Down
44 changes: 41 additions & 3 deletions storage/diskmetricstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,19 @@ var (
},
},
}
mfUnlabelled = &dto.MetricFamily{
Name: proto.String("mf_unlabelled"),
Help: proto.String("Metric with no labels to check sanitizeLabels."),
Type: dto.MetricType_GAUGE.Enum(),
Metric: []*dto.Metric{
{
Label: []*dto.LabelPair{},
Gauge: &dto.Gauge{
Value: proto.Float64(42),
},
},
},
}
)

func addGroup(
Expand Down Expand Up @@ -892,17 +905,42 @@ func TestAddDeletePersistRestore(t *testing.T) {
MetricFamilies: testutil.MetricFamiliesMap(mf4),
})
}
grouping6 := map[string]string{
"job": "job4",
"instance": "instance1",
}
dms.SubmitWriteRequest(WriteRequest{
Labels: grouping6,
Timestamp: ts5,
MetricFamilies: testutil.MetricFamiliesMap(mfUnlabelled),
})
if err := dms.Shutdown(); err != nil {
t.Fatal(err)
}
pushTimestamp.Metric = append(
pushTimestamp.Metric, newPushTimestampGauge(grouping5, ts5).Metric[0],
pushTimestamp.Metric,
newPushTimestampGauge(grouping5, ts5).Metric[0],
newPushTimestampGauge(grouping6, ts5).Metric[0],
)
pushFailedTimestamp.Metric = append(
pushFailedTimestamp.Metric, newPushFailedTimestampGauge(grouping5, time.Time{}).Metric[0],
pushFailedTimestamp.Metric,
newPushFailedTimestampGauge(grouping5, time.Time{}).Metric[0],
newPushFailedTimestampGauge(grouping6, time.Time{}).Metric[0],
)
mfLabelled := proto.Clone(mfUnlabelled).(*dto.MetricFamily)
// SanitizeLabels should add these labels to the unlabelled metric.
mfLabelled.Metric[0].Label = []*dto.LabelPair{
{
Name: proto.String("instance"),
Value: proto.String("instance1"),
},
{
Name: proto.String("job"),
Value: proto.String("job4"),
},
}
if err := checkMetricFamilies(
dms, mf1a, mf2, mf4,
dms, mf1a, mf2, mf4, mfLabelled,
pushTimestamp, pushFailedTimestamp,
); err != nil {
t.Error(err)
Expand Down

0 comments on commit bb180b7

Please sign in to comment.