|
|
|
@ -74,6 +74,59 @@ var writeRequestFixture = &prompb.WriteRequest{ |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// writeRequestWithRefsFixture represents the same request as writeRequestFixture, but using the reduced representation.
|
|
|
|
|
|
|
|
var writeRequestWithRefsFixture = &prompb.WriteRequestWithRefs{ |
|
|
|
|
|
|
|
StringSymbolTable: map[uint64]string{ |
|
|
|
|
|
|
|
// Names
|
|
|
|
|
|
|
|
0: "__name__", |
|
|
|
|
|
|
|
2: "b", |
|
|
|
|
|
|
|
4: "baz", |
|
|
|
|
|
|
|
6: "d", |
|
|
|
|
|
|
|
8: "foo", |
|
|
|
|
|
|
|
10: "f", |
|
|
|
|
|
|
|
12: "h", |
|
|
|
|
|
|
|
// Values
|
|
|
|
|
|
|
|
1: "test_metric1", |
|
|
|
|
|
|
|
3: "c", |
|
|
|
|
|
|
|
5: "qux", |
|
|
|
|
|
|
|
7: "e", |
|
|
|
|
|
|
|
9: "bar", |
|
|
|
|
|
|
|
11: "g", |
|
|
|
|
|
|
|
13: "i", |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timeseries: []prompb.ReducedTimeSeries{ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Labels: []prompb.LabelRef{ |
|
|
|
|
|
|
|
{NameRef: 0, ValueRef: 1}, |
|
|
|
|
|
|
|
{NameRef: 2, ValueRef: 3}, |
|
|
|
|
|
|
|
{NameRef: 4, ValueRef: 5}, |
|
|
|
|
|
|
|
{NameRef: 6, ValueRef: 7}, |
|
|
|
|
|
|
|
{NameRef: 8, ValueRef: 9}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Samples: []prompb.Sample{{Value: 1, Timestamp: 0}}, |
|
|
|
|
|
|
|
Exemplars: []prompb.ExemplarRef{{Labels: []prompb.LabelRef{ |
|
|
|
|
|
|
|
{NameRef: 10, ValueRef: 11}, |
|
|
|
|
|
|
|
}, Value: 1, Timestamp: 0}}, |
|
|
|
|
|
|
|
Histograms: []prompb.Histogram{HistogramToHistogramProto(0, &testHistogram)}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Labels: []prompb.LabelRef{ |
|
|
|
|
|
|
|
{NameRef: 0, ValueRef: 1}, |
|
|
|
|
|
|
|
{NameRef: 2, ValueRef: 3}, |
|
|
|
|
|
|
|
{NameRef: 4, ValueRef: 5}, |
|
|
|
|
|
|
|
{NameRef: 6, ValueRef: 7}, |
|
|
|
|
|
|
|
{NameRef: 8, ValueRef: 9}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Samples: []prompb.Sample{{Value: 2, Timestamp: 1}}, |
|
|
|
|
|
|
|
Exemplars: []prompb.ExemplarRef{{Labels: []prompb.LabelRef{ |
|
|
|
|
|
|
|
{NameRef: 12, ValueRef: 13}, |
|
|
|
|
|
|
|
}, Value: 2, Timestamp: 1}}, |
|
|
|
|
|
|
|
Histograms: []prompb.Histogram{HistogramToHistogramProto(1, &testHistogram)}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestValidateLabelsAndMetricName(t *testing.T) { |
|
|
|
func TestValidateLabelsAndMetricName(t *testing.T) { |
|
|
|
tests := []struct { |
|
|
|
tests := []struct { |
|
|
|
input []prompb.Label |
|
|
|
input []prompb.Label |
|
|
|
@ -525,7 +578,24 @@ func TestDecodeWriteRequest(t *testing.T) { |
|
|
|
require.Equal(t, writeRequestFixture, actual) |
|
|
|
require.Equal(t, writeRequestFixture, actual) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestNilHistogramProto(*testing.T) { |
|
|
|
func TestDecodeReducedWriteRequest(t *testing.T) { |
|
|
|
|
|
|
|
buf, _, err := buildReducedWriteRequest(writeRequestWithRefsFixture.Timeseries, writeRequestWithRefsFixture.StringSymbolTable, nil, nil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
actual, err := DecodeReducedWriteRequest(bytes.NewReader(buf)) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
require.Equal(t, writeRequestWithRefsFixture, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestReducedWriteRequestToWriteRequest(t *testing.T) { |
|
|
|
|
|
|
|
actual, err := ReducedWriteRequestToWriteRequest(writeRequestWithRefsFixture) |
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, writeRequestFixture, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestNilHistogramProto(t *testing.T) { |
|
|
|
// This function will panic if it impromperly handles nil
|
|
|
|
// This function will panic if it impromperly handles nil
|
|
|
|
// values, causing the test to fail.
|
|
|
|
// values, causing the test to fail.
|
|
|
|
HistogramProtoToHistogram(prompb.Histogram{}) |
|
|
|
HistogramProtoToHistogram(prompb.Histogram{}) |
|
|
|
|