mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
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))
|
||||
for _, n := range dRules {
|
||||
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 += "Might cause inconsistency while recording expressions"
|
||||
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,
|
||||
// so they can override query output.
|
||||
for _, l := range ruleLabels {
|
||||
ruleLabels.Range(func(l labels.Label) {
|
||||
lb.Set(l.Name, l.Value)
|
||||
}
|
||||
})
|
||||
|
||||
lb.Set(labels.MetricName, ruleName)
|
||||
lbls := lb.Labels(labels.EmptyLabels())
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
|
|||
i := 0
|
||||
|
||||
for scanner.Scan() && i < n {
|
||||
m := make(labels.Labels, 0, 10)
|
||||
m := make([]labels.Label, 0, 10)
|
||||
|
||||
r := strings.NewReplacer("\"", "", "{", "", "}", "")
|
||||
s := r.Replace(scanner.Text())
|
||||
|
@ -325,13 +325,12 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
|
|||
split := strings.Split(labelChunk, ":")
|
||||
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.
|
||||
sort.Sort(m)
|
||||
h := m.Hash()
|
||||
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.
|
||||
h := ml.Hash()
|
||||
if _, ok := hashes[h]; ok {
|
||||
continue
|
||||
}
|
||||
mets = append(mets, m)
|
||||
mets = append(mets, ml)
|
||||
hashes[h] = struct{}{}
|
||||
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.
|
||||
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
|
||||
labelsUncovered[lbl.Name] += uncovered
|
||||
labelpairsUncovered[key] += uncovered
|
||||
labelpairsCount[key]++
|
||||
entries++
|
||||
}
|
||||
})
|
||||
}
|
||||
if p.Err() != nil {
|
||||
return p.Err()
|
||||
|
|
|
@ -284,8 +284,8 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
|
|||
for _, a := range ar.ActiveAlerts() {
|
||||
if a.State == rules.StateFiring {
|
||||
alerts = append(alerts, labelAndAnnotation{
|
||||
Labels: append(labels.Labels{}, a.Labels...),
|
||||
Annotations: append(labels.Labels{}, a.Annotations...),
|
||||
Labels: a.Labels.Copy(),
|
||||
Annotations: a.Annotations.Copy(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue