Update package cmd/promtool for new labels.Labels type
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
fd57569683
commit
bf2c827d91
|
@ -631,9 +631,9 @@ func checkRules(filename string, lintSettings lintConfig) (int, []error) {
|
||||||
errMessage := fmt.Sprintf("%d duplicate rule(s) found.\n", len(dRules))
|
errMessage := fmt.Sprintf("%d duplicate rule(s) found.\n", len(dRules))
|
||||||
for _, n := range dRules {
|
for _, n := range dRules {
|
||||||
errMessage += fmt.Sprintf("Metric: %s\nLabel(s):\n", n.metric)
|
errMessage += fmt.Sprintf("Metric: %s\nLabel(s):\n", n.metric)
|
||||||
for _, l := range n.label {
|
n.label.Range(func(l labels.Label) {
|
||||||
errMessage += fmt.Sprintf("\t%s: %s\n", l.Name, l.Value)
|
errMessage += fmt.Sprintf("\t%s: %s\n", l.Name, l.Value)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
errMessage += "Might cause inconsistency while recording expressions"
|
errMessage += "Might cause inconsistency while recording expressions"
|
||||||
return 0, []error{fmt.Errorf("%w %s", lintError, errMessage)}
|
return 0, []error{fmt.Errorf("%w %s", lintError, errMessage)}
|
||||||
|
|
|
@ -158,14 +158,15 @@ func (importer *ruleImporter) importRule(ctx context.Context, ruleExpr, ruleName
|
||||||
|
|
||||||
// Setting the rule labels after the output of the query,
|
// Setting the rule labels after the output of the query,
|
||||||
// so they can override query output.
|
// so they can override query output.
|
||||||
for _, l := range ruleLabels {
|
ruleLabels.Range(func(l labels.Label) {
|
||||||
lb.Set(l.Name, l.Value)
|
lb.Set(l.Name, l.Value)
|
||||||
}
|
})
|
||||||
|
|
||||||
lb.Set(labels.MetricName, ruleName)
|
lb.Set(labels.MetricName, ruleName)
|
||||||
|
lbls := lb.Labels(labels.EmptyLabels())
|
||||||
|
|
||||||
for _, value := range sample.Values {
|
for _, value := range sample.Values {
|
||||||
if err := app.add(ctx, lb.Labels(nil), timestamp.FromTime(value.Timestamp.Time()), float64(value.Value)); err != nil {
|
if err := app.add(ctx, lbls, timestamp.FromTime(value.Timestamp.Time()), float64(value.Value)); err != nil {
|
||||||
return fmt.Errorf("add: %w", err)
|
return fmt.Errorf("add: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,7 +315,7 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
for scanner.Scan() && i < n {
|
for scanner.Scan() && i < n {
|
||||||
m := make(labels.Labels, 0, 10)
|
m := make([]labels.Label, 0, 10)
|
||||||
|
|
||||||
r := strings.NewReplacer("\"", "", "{", "", "}", "")
|
r := strings.NewReplacer("\"", "", "{", "", "}", "")
|
||||||
s := r.Replace(scanner.Text())
|
s := r.Replace(scanner.Text())
|
||||||
|
@ -325,13 +325,12 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
|
||||||
split := strings.Split(labelChunk, ":")
|
split := strings.Split(labelChunk, ":")
|
||||||
m = append(m, labels.Label{Name: split[0], Value: split[1]})
|
m = append(m, labels.Label{Name: split[0], Value: split[1]})
|
||||||
}
|
}
|
||||||
// Order of the k/v labels matters, don't assume we'll always receive them already sorted.
|
ml := labels.New(m...) // This sorts by name - order of the k/v labels matters, don't assume we'll always receive them already sorted.
|
||||||
sort.Sort(m)
|
h := ml.Hash()
|
||||||
h := m.Hash()
|
|
||||||
if _, ok := hashes[h]; ok {
|
if _, ok := hashes[h]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mets = append(mets, m)
|
mets = append(mets, ml)
|
||||||
hashes[h] = struct{}{}
|
hashes[h] = struct{}{}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
@ -479,13 +478,13 @@ func analyzeBlock(path, blockID string, limit int, runExtended bool) error {
|
||||||
}
|
}
|
||||||
// Amount of the block time range not covered by this series.
|
// Amount of the block time range not covered by this series.
|
||||||
uncovered := uint64(meta.MaxTime-meta.MinTime) - uint64(chks[len(chks)-1].MaxTime-chks[0].MinTime)
|
uncovered := uint64(meta.MaxTime-meta.MinTime) - uint64(chks[len(chks)-1].MaxTime-chks[0].MinTime)
|
||||||
for _, lbl := range lbls {
|
lbls.Range(func(lbl labels.Label) {
|
||||||
key := lbl.Name + "=" + lbl.Value
|
key := lbl.Name + "=" + lbl.Value
|
||||||
labelsUncovered[lbl.Name] += uncovered
|
labelsUncovered[lbl.Name] += uncovered
|
||||||
labelpairsUncovered[key] += uncovered
|
labelpairsUncovered[key] += uncovered
|
||||||
labelpairsCount[key]++
|
labelpairsCount[key]++
|
||||||
entries++
|
entries++
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
if p.Err() != nil {
|
if p.Err() != nil {
|
||||||
return p.Err()
|
return p.Err()
|
||||||
|
|
|
@ -284,8 +284,8 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
|
||||||
for _, a := range ar.ActiveAlerts() {
|
for _, a := range ar.ActiveAlerts() {
|
||||||
if a.State == rules.StateFiring {
|
if a.State == rules.StateFiring {
|
||||||
alerts = append(alerts, labelAndAnnotation{
|
alerts = append(alerts, labelAndAnnotation{
|
||||||
Labels: append(labels.Labels{}, a.Labels...),
|
Labels: a.Labels.Copy(),
|
||||||
Annotations: append(labels.Labels{}, a.Annotations...),
|
Annotations: a.Annotations.Copy(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue