|
|
|
|
@ -1379,6 +1379,81 @@ func TestScrapeLoopAppend(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestScrapeLoopAppendForConflictingPrefixedLabels(t *testing.T) { |
|
|
|
|
testcases := map[string]struct { |
|
|
|
|
targetLabels []string |
|
|
|
|
exposedLabels string |
|
|
|
|
expected []string |
|
|
|
|
}{ |
|
|
|
|
"One target label collides with existing label": { |
|
|
|
|
targetLabels: []string{"foo", "2"}, |
|
|
|
|
exposedLabels: `metric{foo="1"} 0`, |
|
|
|
|
expected: []string{"__name__", "metric", "exported_foo", "1", "foo", "2"}, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
"One target label collides with existing label, plus target label already with prefix 'exported'": { |
|
|
|
|
targetLabels: []string{"foo", "2", "exported_foo", "3"}, |
|
|
|
|
exposedLabels: `metric{foo="1"} 0`, |
|
|
|
|
expected: []string{"__name__", "metric", "exported_exported_foo", "1", "exported_foo", "3", "foo", "2"}, |
|
|
|
|
}, |
|
|
|
|
"One target label collides with existing label, plus existing label already with prefix 'exported": { |
|
|
|
|
targetLabels: []string{"foo", "3"}, |
|
|
|
|
exposedLabels: `metric{foo="1" exported_foo="2"} 0`, |
|
|
|
|
expected: []string{"__name__", "metric", "exported_exported_foo", "1", "exported_foo", "2", "foo", "3"}, |
|
|
|
|
}, |
|
|
|
|
"One target label collides with existing label, both already with prefix 'exported'": { |
|
|
|
|
targetLabels: []string{"exported_foo", "2"}, |
|
|
|
|
exposedLabels: `metric{exported_foo="1"} 0`, |
|
|
|
|
expected: []string{"__name__", "metric", "exported_exported_foo", "1", "exported_foo", "2"}, |
|
|
|
|
}, |
|
|
|
|
"Two target labels collide with existing labels, both with and without prefix 'exported'": { |
|
|
|
|
targetLabels: []string{"foo", "3", "exported_foo", "4"}, |
|
|
|
|
exposedLabels: `metric{foo="1" exported_foo="2"} 0`, |
|
|
|
|
expected: []string{"__name__", "metric", "exported_exported_foo", "1", "exported_exported_exported_foo", |
|
|
|
|
"2", "exported_foo", "4", "foo", "3"}, |
|
|
|
|
}, |
|
|
|
|
"Extreme example": { |
|
|
|
|
targetLabels: []string{"foo", "0", "exported_exported_foo", "1", "exported_exported_exported_foo", "2"}, |
|
|
|
|
exposedLabels: `metric{foo="3" exported_foo="4" exported_exported_exported_foo="5"} 0`, |
|
|
|
|
expected: []string{ |
|
|
|
|
"__name__", "metric", |
|
|
|
|
"exported_exported_exported_exported_exported_foo", "5", |
|
|
|
|
"exported_exported_exported_exported_foo", "3", |
|
|
|
|
"exported_exported_exported_foo", "2", |
|
|
|
|
"exported_exported_foo", "1", |
|
|
|
|
"exported_foo", "4", |
|
|
|
|
"foo", "0", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for name, tc := range testcases { |
|
|
|
|
t.Run(name, func(t *testing.T) { |
|
|
|
|
app := &collectResultAppender{} |
|
|
|
|
sl := newScrapeLoop(context.Background(), nil, nil, nil, |
|
|
|
|
func(l labels.Labels) labels.Labels { |
|
|
|
|
return mutateSampleLabels(l, &Target{labels: labels.FromStrings(tc.targetLabels...)}, false, nil) |
|
|
|
|
}, |
|
|
|
|
nil, |
|
|
|
|
func(ctx context.Context) storage.Appender { return app }, nil, 0, true, 0, nil, 0, 0, false, |
|
|
|
|
) |
|
|
|
|
slApp := sl.appender(context.Background()) |
|
|
|
|
_, _, _, err := sl.append(slApp, []byte(tc.exposedLabels), "", time.Date(2000, 1, 1, 1, 0, 0, 0, time.UTC)) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
require.NoError(t, slApp.Commit()) |
|
|
|
|
|
|
|
|
|
require.Equal(t, []sample{ |
|
|
|
|
{ |
|
|
|
|
metric: labels.FromStrings(tc.expected...), |
|
|
|
|
t: timestamp.FromTime(time.Date(2000, 1, 1, 1, 0, 0, 0, time.UTC)), |
|
|
|
|
v: 0, |
|
|
|
|
}, |
|
|
|
|
}, app.result) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) { |
|
|
|
|
// collectResultAppender's AddFast always returns ErrNotFound if we don't give it a next.
|
|
|
|
|
app := &collectResultAppender{} |
|
|
|
|
|