mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 00:21:42 -08:00
Merge pull request #404 from grafana/fixup-labels-usage2
Fixup labels usage
This commit is contained in:
commit
174b26a5c0
|
@ -3114,17 +3114,11 @@ func TestRangeQuery(t *testing.T) {
|
|||
Result: Matrix{
|
||||
Series{
|
||||
Points: []Point{{V: 1, T: 0}, {V: 3, T: 60000}, {V: 5, T: 120000}},
|
||||
Metric: labels.Labels{
|
||||
labels.Label{Name: "__name__", Value: "bar"},
|
||||
labels.Label{Name: "job", Value: "2"},
|
||||
},
|
||||
Metric: labels.FromStrings("__name__", "bar", "job", "2"),
|
||||
},
|
||||
Series{
|
||||
Points: []Point{{V: 3, T: 60000}, {V: 5, T: 120000}},
|
||||
Metric: labels.Labels{
|
||||
labels.Label{Name: "__name__", Value: "foo"},
|
||||
labels.Label{Name: "job", Value: "1"},
|
||||
},
|
||||
Metric: labels.FromStrings("__name__", "foo", "job", "1"),
|
||||
},
|
||||
},
|
||||
Start: time.Unix(0, 0),
|
||||
|
|
|
@ -831,7 +831,7 @@ func TestUpdate_AlwaysRestore(t *testing.T) {
|
|||
ruleManager.start()
|
||||
defer ruleManager.Stop()
|
||||
|
||||
err := ruleManager.Update(10*time.Second, []string{"fixtures/rules_alerts.yaml"}, nil, "", nil)
|
||||
err := ruleManager.Update(10*time.Second, []string{"fixtures/rules_alerts.yaml"}, labels.EmptyLabels(), "", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, g := range ruleManager.groups {
|
||||
|
@ -840,7 +840,7 @@ func TestUpdate_AlwaysRestore(t *testing.T) {
|
|||
}
|
||||
|
||||
// Use different file, so groups haven't changed, therefore, we expect state restoration
|
||||
err = ruleManager.Update(10*time.Second, []string{"fixtures/rules_alerts2.yaml"}, nil, "", nil)
|
||||
err = ruleManager.Update(10*time.Second, []string{"fixtures/rules_alerts2.yaml"}, labels.EmptyLabels(), "", nil)
|
||||
for _, g := range ruleManager.groups {
|
||||
require.True(t, g.shouldRestore)
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ func TestUpdate_AlwaysRestoreDoesntAffectUnchangedGroups(t *testing.T) {
|
|||
ruleManager.start()
|
||||
defer ruleManager.Stop()
|
||||
|
||||
err := ruleManager.Update(10*time.Second, files, nil, "", nil)
|
||||
err := ruleManager.Update(10*time.Second, files, labels.EmptyLabels(), "", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, g := range ruleManager.groups {
|
||||
|
@ -872,7 +872,7 @@ func TestUpdate_AlwaysRestoreDoesntAffectUnchangedGroups(t *testing.T) {
|
|||
}
|
||||
|
||||
// Use the same file, so groups haven't changed, therefore, we don't expect state restoration
|
||||
err = ruleManager.Update(10*time.Second, files, nil, "", nil)
|
||||
err = ruleManager.Update(10*time.Second, files, labels.EmptyLabels(), "", nil)
|
||||
for _, g := range ruleManager.groups {
|
||||
require.False(t, g.shouldRestore)
|
||||
}
|
||||
|
@ -1090,7 +1090,7 @@ func reloadRules(rgs *rulefmt.RuleGroups, t *testing.T, tmpFile *os.File, ruleMa
|
|||
_, _ = tmpFile.Seek(0, 0)
|
||||
_, err = tmpFile.Write(bs)
|
||||
require.NoError(t, err)
|
||||
err = ruleManager.Update(interval, []string{tmpFile.Name()}, nil, "", nil)
|
||||
err = ruleManager.Update(interval, []string{tmpFile.Name()}, labels.EmptyLabels(), "", nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -1686,7 +1686,7 @@ groups:
|
|||
},
|
||||
})
|
||||
m.start()
|
||||
err = m.Update(time.Second, []string{fname}, nil, "", nil)
|
||||
err = m.Update(time.Second, []string{fname}, labels.EmptyLabels(), "", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
rgs := m.RuleGroups()
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
type unknownRule struct{}
|
||||
|
||||
func (u unknownRule) Name() string { return "" }
|
||||
func (u unknownRule) Labels() labels.Labels { return nil }
|
||||
func (u unknownRule) Labels() labels.Labels { return labels.EmptyLabels() }
|
||||
func (u unknownRule) Eval(ctx context.Context, evalDelay time.Duration, time time.Time, queryFunc QueryFunc, url *url.URL, i int) (promql.Vector, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -1176,13 +1176,17 @@ func (c *LeveledCompactor) populateSymbols(sets []storage.ChunkSeriesSet, outBlo
|
|||
obIx = labels.StableHash(s.Labels()) % uint64(len(outBlocks))
|
||||
}
|
||||
|
||||
for _, l := range s.Labels() {
|
||||
err := s.Labels().Validate(func(l labels.Label) error {
|
||||
if err := batchers[obIx].addSymbol(l.Name); err != nil {
|
||||
return errors.Wrap(err, "addSymbol to batcher")
|
||||
}
|
||||
if err := batchers[obIx].addSymbol(l.Value); err != nil {
|
||||
return errors.Wrap(err, "addSymbol to batcher")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -593,13 +593,13 @@ func TestCompaction_CompactWithSplitting(t *testing.T) {
|
|||
ref := p.At()
|
||||
require.NoError(t, idxr.Series(ref, &lbls, nil))
|
||||
|
||||
require.Equal(t, uint64(shardIndex), lbls.Labels().Hash()%shardCount)
|
||||
require.Equal(t, uint64(shardIndex), labels.StableHash(lbls.Labels())%shardCount)
|
||||
|
||||
// Collect all symbols used by series.
|
||||
for _, l := range lbls.Labels() {
|
||||
lbls.Labels().Range(func(l labels.Label) {
|
||||
seriesSymbols[l.Name] = struct{}{}
|
||||
seriesSymbols[l.Value] = struct{}{}
|
||||
}
|
||||
})
|
||||
}
|
||||
require.NoError(t, p.Err())
|
||||
|
||||
|
|
|
@ -2448,10 +2448,7 @@ func TestHeadShardedPostings(t *testing.T) {
|
|||
// Append some series.
|
||||
app := head.Appender(context.Background())
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err := app.Append(0, labels.Labels{
|
||||
{Name: "unique", Value: fmt.Sprintf("value%d", i)},
|
||||
{Name: "const", Value: "1"},
|
||||
}, 100, 0)
|
||||
_, err := app.Append(0, labels.FromStrings("unique", fmt.Sprintf("value%d", i), "const", "1"), 100, 0)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.NoError(t, app.Commit())
|
||||
|
@ -2498,7 +2495,7 @@ func TestHeadShardedPostings(t *testing.T) {
|
|||
var lbls labels.ScratchBuilder
|
||||
|
||||
require.NoError(t, ir.Series(id, &lbls, nil))
|
||||
require.Equal(t, shardIndex, lbls.Labels().Hash()%shardCount)
|
||||
require.Equal(t, shardIndex, labels.StableHash(lbls.Labels())%shardCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ func TestIndexRW_Postings(t *testing.T) {
|
|||
var lbls labels.ScratchBuilder
|
||||
|
||||
require.NoError(t, ir.Series(id, &lbls, nil))
|
||||
require.Equal(t, shardIndex, lbls.Labels().Hash()%shardCount)
|
||||
require.Equal(t, shardIndex, labels.StableHash(lbls.Labels())%shardCount)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -630,10 +630,8 @@ func BenchmarkReader_ShardedPostings(b *testing.B) {
|
|||
require.NoError(b, iw.AddSymbol("unique"))
|
||||
|
||||
for i := 1; i <= numSeries; i++ {
|
||||
require.NoError(b, iw.AddSeries(storage.SeriesRef(i), labels.Labels{
|
||||
{Name: "const", Value: fmt.Sprintf("%10d", 1)},
|
||||
{Name: "unique", Value: fmt.Sprintf("%10d", i)},
|
||||
}))
|
||||
require.NoError(b, iw.AddSeries(storage.SeriesRef(i),
|
||||
labels.FromStrings("const", fmt.Sprintf("%10d", 1), "unique", fmt.Sprintf("%10d", i))))
|
||||
}
|
||||
|
||||
require.NoError(b, iw.Close())
|
||||
|
|
Loading…
Reference in a new issue