mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
rm overlap, add label builder to fix name bug
Signed-off-by: jessicagreben <jessicagrebens@gmail.com>
This commit is contained in:
parent
05a816bfb7
commit
b0a21f9eab
|
@ -103,6 +103,9 @@ func (importer *ruleImporter) importRule(ctx context.Context, ruleExpr, ruleName
|
||||||
|
|
||||||
currStart := max(startOfBlock/int64(time.Second/time.Millisecond), start.Unix())
|
currStart := max(startOfBlock/int64(time.Second/time.Millisecond), start.Unix())
|
||||||
startWithAlignment := grp.EvalTimestamp(time.Unix(currStart, 0).UTC().UnixNano())
|
startWithAlignment := grp.EvalTimestamp(time.Unix(currStart, 0).UTC().UnixNano())
|
||||||
|
for startWithAlignment.Unix() < currStart {
|
||||||
|
startWithAlignment = startWithAlignment.Add(grp.Interval())
|
||||||
|
}
|
||||||
val, warnings, err := importer.apiClient.QueryRange(ctx,
|
val, warnings, err := importer.apiClient.QueryRange(ctx,
|
||||||
ruleExpr,
|
ruleExpr,
|
||||||
v1.Range{
|
v1.Range{
|
||||||
|
@ -141,22 +144,16 @@ func (importer *ruleImporter) importRule(ctx context.Context, ruleExpr, ruleName
|
||||||
matrix = val.(model.Matrix)
|
matrix = val.(model.Matrix)
|
||||||
|
|
||||||
for _, sample := range matrix {
|
for _, sample := range matrix {
|
||||||
currentLabels := make(labels.Labels, 0, len(sample.Metric)+len(ruleLabels)+1)
|
lb := labels.NewBuilder(ruleLabels)
|
||||||
currentLabels = append(currentLabels, labels.Label{
|
|
||||||
Name: labels.MetricName,
|
|
||||||
Value: ruleName,
|
|
||||||
})
|
|
||||||
|
|
||||||
currentLabels = append(currentLabels, ruleLabels...)
|
|
||||||
|
|
||||||
for name, value := range sample.Metric {
|
for name, value := range sample.Metric {
|
||||||
currentLabels = append(currentLabels, labels.Label{
|
lb.Set(string(name), string(value))
|
||||||
Name: string(name),
|
|
||||||
Value: string(value),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lb.Set(labels.MetricName, ruleName)
|
||||||
|
|
||||||
for _, value := range sample.Values {
|
for _, value := range sample.Values {
|
||||||
if err := app.add(ctx, currentLabels, timestamp.FromTime(value.Timestamp.Time()), float64(value.Value)); err != nil {
|
if err := app.add(ctx, lb.Labels(), timestamp.FromTime(value.Timestamp.Time()), float64(value.Value)); err != nil {
|
||||||
return errors.Wrap(err, "add")
|
return errors.Wrap(err, "add")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ func TestBackfillRuleIntegration(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{"no samples", 1, 0, 0, 0, []*model.SampleStream{}},
|
{"no samples", 1, 0, 0, 0, []*model.SampleStream{}},
|
||||||
{"run importer once", 1, 8, 4, 4, []*model.SampleStream{{Metric: model.Metric{"name1": "val1"}, Values: []model.SamplePair{{Timestamp: testTime, Value: testValue}}}}},
|
{"run importer once", 1, 8, 4, 4, []*model.SampleStream{{Metric: model.Metric{"name1": "val1"}, Values: []model.SamplePair{{Timestamp: testTime, Value: testValue}}}}},
|
||||||
|
{"run importer with dup name label", 1, 8, 4, 4, []*model.SampleStream{{Metric: model.Metric{"__name__": "val1", "name1": "val1"}, Values: []model.SamplePair{{Timestamp: testTime, Value: testValue}}}}},
|
||||||
{"one importer twice", 2, 8, 4, 8, []*model.SampleStream{{Metric: model.Metric{"name1": "val1"}, Values: []model.SamplePair{{Timestamp: testTime, Value: testValue}, {Timestamp: testTime2, Value: testValue2}}}}},
|
{"one importer twice", 2, 8, 4, 8, []*model.SampleStream{{Metric: model.Metric{"name1": "val1"}, Values: []model.SamplePair{{Timestamp: testTime, Value: testValue}, {Timestamp: testTime2, Value: testValue2}}}}},
|
||||||
}
|
}
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
|
@ -194,7 +195,7 @@ func createMultiRuleTestFiles(path string) error {
|
||||||
- record: grp1_rule1
|
- record: grp1_rule1
|
||||||
expr: grp1_rule1_expr
|
expr: grp1_rule1_expr
|
||||||
labels:
|
labels:
|
||||||
testlabel11: testlabelvalue11
|
testlabel11: testlabelvalue12
|
||||||
- name: group2
|
- name: group2
|
||||||
rules:
|
rules:
|
||||||
- record: grp2_rule1
|
- record: grp2_rule1
|
||||||
|
@ -202,7 +203,7 @@ func createMultiRuleTestFiles(path string) error {
|
||||||
- record: grp2_rule2
|
- record: grp2_rule2
|
||||||
expr: grp2_rule2_expr
|
expr: grp2_rule2_expr
|
||||||
labels:
|
labels:
|
||||||
testlabel11: testlabelvalue11
|
testlabel11: testlabelvalue13
|
||||||
`
|
`
|
||||||
return ioutil.WriteFile(path, []byte(recordingRules), 0777)
|
return ioutil.WriteFile(path, []byte(recordingRules), 0777)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue