Skip to content

Commit e739b3d

Browse files
committed
Integrate cortexpbv2 to cortexpb
Signed-off-by: SungJin1212 <[email protected]>
1 parent 2b5ac96 commit e739b3d

29 files changed

+3014
-5702
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ $(foreach exe, $(EXES), $(eval $(call dep_exe, $(exe))))
8585

8686
# Manually declared dependencies And what goes into each exe
8787
pkg/cortexpb/cortex.pb.go: pkg/cortexpb/cortex.proto
88-
pkg/cortexpbv2/cortexv2.pb.go: pkg/cortexpbv2/cortexv2.proto
8988
pkg/ingester/client/ingester.pb.go: pkg/ingester/client/ingester.proto
9089
pkg/distributor/distributorpb/distributor.pb.go: pkg/distributor/distributorpb/distributor.proto
9190
pkg/ingester/wal.pb.go: pkg/ingester/wal.proto

pkg/api/api.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/cortexproject/cortex/pkg/alertmanager/alertmanagerpb"
2424
"github.com/cortexproject/cortex/pkg/compactor"
2525
"github.com/cortexproject/cortex/pkg/cortexpb"
26-
"github.com/cortexproject/cortex/pkg/cortexpbv2"
2726
"github.com/cortexproject/cortex/pkg/distributor"
2827
"github.com/cortexproject/cortex/pkg/distributor/distributorpb"
2928
frontendv1 "github.com/cortexproject/cortex/pkg/frontend/v1"
@@ -318,7 +317,7 @@ type Ingester interface {
318317
AllUserStatsHandler(http.ResponseWriter, *http.Request)
319318
ModeHandler(http.ResponseWriter, *http.Request)
320319
Push(context.Context, *cortexpb.WriteRequest) (*cortexpb.WriteResponse, error)
321-
PushV2(context.Context, *cortexpbv2.WriteRequest) (*cortexpbv2.WriteResponse, error)
320+
PushV2(context.Context, *cortexpb.WriteRequestV2) (*cortexpb.WriteResponseV2, error)
322321
}
323322

324323
// RegisterIngester registers the ingesters HTTP and GRPC service

pkg/cortexpb/codecv2.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cortexpb
2+
3+
import (
4+
"github.com/prometheus/prometheus/model/labels"
5+
)
6+
7+
// ToLabels return model labels.Labels from timeseries' remote labels.
8+
func (t TimeSeriesV2) ToLabels(b *labels.ScratchBuilder, symbols []string) labels.Labels {
9+
return desymbolizeLabels(b, t.GetLabelsRefs(), symbols)
10+
}
11+
12+
// ToLabels return model labels.Labels from exemplar remote labels.
13+
func (e ExemplarV2) ToLabels(b *labels.ScratchBuilder, symbols []string) labels.Labels {
14+
return desymbolizeLabels(b, e.GetLabelsRefs(), symbols)
15+
}
16+
17+
func (m MetadataV2) ToV1Metadata(name string, symbols []string) *MetricMetadata {
18+
return &MetricMetadata{
19+
Type: m.Type,
20+
MetricFamilyName: name,
21+
Unit: symbols[m.UnitRef],
22+
Help: symbols[m.HelpRef],
23+
}
24+
}
25+
26+
// desymbolizeLabels decodes label references, with given symbols to labels.
27+
func desymbolizeLabels(b *labels.ScratchBuilder, labelRefs []uint32, symbols []string) labels.Labels {
28+
b.Reset()
29+
for i := 0; i < len(labelRefs); i += 2 {
30+
b.Add(symbols[labelRefs[i]], symbols[labelRefs[i+1]])
31+
}
32+
b.Sort()
33+
return b.Labels()
34+
}

pkg/cortexpb/compat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
// ToWriteRequest converts matched slices of Labels, Samples, Metadata and Histograms into a WriteRequest proto.
2222
// It gets timeseries from the pool, so ReuseSlice() should be called when done.
23-
func ToWriteRequest(lbls []labels.Labels, samples []Sample, metadata []*MetricMetadata, histograms []Histogram, source WriteRequest_SourceEnum) *WriteRequest {
23+
func ToWriteRequest(lbls []labels.Labels, samples []Sample, metadata []*MetricMetadata, histograms []Histogram, source SourceEnum) *WriteRequest {
2424
req := &WriteRequest{
2525
Timeseries: PreallocTimeseriesSliceFromPool(),
2626
Metadata: metadata,
@@ -170,7 +170,7 @@ func (s byLabel) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
170170

171171
// MetricMetadataMetricTypeToMetricType converts a metric type from our internal client
172172
// to a Prometheus one.
173-
func MetricMetadataMetricTypeToMetricType(mt MetricMetadata_MetricType) model.MetricType {
173+
func MetricMetadataMetricTypeToMetricType(mt MetricType) model.MetricType {
174174
switch mt {
175175
case UNKNOWN:
176176
return model.MetricTypeUnknown

pkg/cortexpb/compat_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func testUnmarshalling(t *testing.T, unmarshalFn func(data []byte, v interface{}
7474
func TestMetricMetadataToMetricTypeToMetricType(t *testing.T) {
7575
tc := []struct {
7676
desc string
77-
input MetricMetadata_MetricType
77+
input MetricType
7878
expected model.MetricType
7979
}{
8080
{
@@ -89,7 +89,7 @@ func TestMetricMetadataToMetricTypeToMetricType(t *testing.T) {
8989
},
9090
{
9191
desc: "with an unknown metric",
92-
input: MetricMetadata_MetricType(100),
92+
input: MetricType(100),
9393
expected: model.MetricTypeUnknown,
9494
},
9595
}

pkg/cortexpbv2/compatv2.go renamed to pkg/cortexpb/compatv2.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
package cortexpbv2
1+
package cortexpb
22

33
import (
44
"github.com/prometheus/prometheus/model/labels"
55
writev2 "github.com/prometheus/prometheus/prompb/io/prometheus/write/v2"
6-
7-
"github.com/cortexproject/cortex/pkg/cortexpb"
86
)
97

108
// ToWriteRequestV2 converts matched slices of Labels, Samples, and Histograms into a WriteRequest proto.
11-
func ToWriteRequestV2(lbls []labels.Labels, samples []Sample, histograms []Histogram, metadata []Metadata, source WriteRequest_SourceEnum, help ...string) *WriteRequest {
9+
func ToWriteRequestV2(lbls []labels.Labels, samples []Sample, histograms []Histogram, metadata []MetadataV2, source SourceEnum, help ...string) *WriteRequestV2 {
1210
st := writev2.NewSymbolTable()
1311
labelRefs := make([][]uint32, 0, len(lbls))
1412
for _, lbl := range lbls {
@@ -21,7 +19,7 @@ func ToWriteRequestV2(lbls []labels.Labels, samples []Sample, histograms []Histo
2119

2220
symbols := st.Symbols()
2321

24-
req := &WriteRequest{
22+
req := &WriteRequestV2{
2523
Timeseries: PreallocTimeseriesV2SliceFromPool(),
2624
Symbols: symbols,
2725
Source: source,
@@ -41,13 +39,13 @@ func ToWriteRequestV2(lbls []labels.Labels, samples []Sample, histograms []Histo
4139
ts.Metadata = metadata[i]
4240
}
4341
i++
44-
req.Timeseries = append(req.Timeseries, PreallocTimeseriesV2{TimeSeries: ts})
42+
req.Timeseries = append(req.Timeseries, PreallocTimeseriesV2{TimeSeriesV2: ts})
4543
}
4644

4745
return req
4846
}
4947

50-
func GetLabelRefsFromLabelAdapters(symbols []string, las []cortexpb.LabelAdapter) []uint32 {
48+
func GetLabelRefsFromLabelAdapters(symbols []string, las []LabelAdapter) []uint32 {
5149
var ret []uint32
5250

5351
symbolMap := map[string]uint32{}

pkg/cortexpbv2/compatv2_test.go renamed to pkg/cortexpb/compatv2_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
1-
package cortexpbv2
1+
package cortexpb
22

33
import (
44
"testing"
55

66
"github.com/prometheus/prometheus/model/labels"
77
"github.com/stretchr/testify/require"
8-
9-
"github.com/cortexproject/cortex/pkg/cortexpb"
108
)
119

1210
func Test_GetLabelRefsFromLabelAdapters(t *testing.T) {
1311
tests := []struct {
1412
symbols []string
15-
lbs []cortexpb.LabelAdapter
13+
lbs []LabelAdapter
1614
expectedSeriesRefs []uint32
1715
}{
1816
{
1917
symbols: []string{"", "__name__", "test_metric", "foo", "bar", "baz", "qux"},
20-
lbs: []cortexpb.LabelAdapter{{Name: "__name__", Value: "test_metric"}, {Name: "foo", Value: "bar"}},
18+
lbs: []LabelAdapter{{Name: "__name__", Value: "test_metric"}, {Name: "foo", Value: "bar"}},
2119
expectedSeriesRefs: []uint32{1, 2, 3, 4},
2220
},
2321
{
2422
symbols: []string{"", "__name__", "test_metric", "foo", "bar", "baz", "qux"},
25-
lbs: []cortexpb.LabelAdapter{{Name: "__name__", Value: "test_metric"}, {Name: "baz", Value: "qux"}},
23+
lbs: []LabelAdapter{{Name: "__name__", Value: "test_metric"}, {Name: "baz", Value: "qux"}},
2624
expectedSeriesRefs: []uint32{1, 2, 5, 6},
2725
},
2826
{
2927
symbols: []string{"", "__name__", "test_metric", "foo", "bar", "baz", "qux", "1"},
30-
lbs: []cortexpb.LabelAdapter{{Name: "__name__", Value: "test_metric"}, {Name: "baz", Value: "qux"}, {Name: "qux", Value: "1"}},
28+
lbs: []LabelAdapter{{Name: "__name__", Value: "test_metric"}, {Name: "baz", Value: "qux"}, {Name: "qux", Value: "1"}},
3129
expectedSeriesRefs: []uint32{1, 2, 5, 6, 6, 7},
3230
},
3331
}

0 commit comments

Comments
 (0)