Skip to content

Commit

Permalink
*: removing gogoproto extensions (thanos-io#7718)
Browse files Browse the repository at this point in the history
Removed all gogoproto extensions and dealt with the changes. 2nd step in
removing gogoproto.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
  • Loading branch information
GiedriusS authored Sep 10, 2024
1 parent 153607f commit 97710f4
Show file tree
Hide file tree
Showing 127 changed files with 6,801 additions and 3,252 deletions.
6 changes: 6 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ $(PROTOC_GEN_GOGOFAST): $(BINGO_DIR)/protoc-gen-gogofast.mod
@echo "(re)installing $(GOBIN)/protoc-gen-gogofast-v1.3.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=protoc-gen-gogofast.mod -o=$(GOBIN)/protoc-gen-gogofast-v1.3.2 "github.com/gogo/protobuf/protoc-gen-gogofast"

PROTOC_GO_INJECT_TAG := $(GOBIN)/protoc-go-inject-tag-v1.4.0
$(PROTOC_GO_INJECT_TAG): $(BINGO_DIR)/protoc-go-inject-tag.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/protoc-go-inject-tag-v1.4.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=protoc-go-inject-tag.mod -o=$(GOBIN)/protoc-go-inject-tag-v1.4.0 "github.com/favadi/protoc-go-inject-tag"

SHFMT := $(GOBIN)/shfmt-v3.8.0
$(SHFMT): $(BINGO_DIR)/shfmt.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
5 changes: 5 additions & 0 deletions .bingo/protoc-go-inject-tag.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.22.6

require github.com/favadi/protoc-go-inject-tag v1.4.0
2 changes: 2 additions & 0 deletions .bingo/protoc-go-inject-tag.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/favadi/protoc-go-inject-tag v1.4.0 h1:K3KXxbgRw5WT4f43LbglARGz/8jVsDOS7uMjG4oNvXY=
github.com/favadi/protoc-go-inject-tag v1.4.0/go.mod h1:AZ+PK+QDKUOLlBRG0rYiKkUX5Hw7+7GTFzlU99GFSbQ=
2 changes: 2 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ PROMU="${GOBIN}/promu-v0.5.0"

PROTOC_GEN_GOGOFAST="${GOBIN}/protoc-gen-gogofast-v1.3.2"

PROTOC_GO_INJECT_TAG="${GOBIN}/protoc-go-inject-tag-v1.4.0"

SHFMT="${GOBIN}/shfmt-v3.8.0"

1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ executors:
docker:
- image: cimg/go:1.22-node
golang-test:
resource_class: 'large'
docker:
- image: cimg/go:1.22-node
- image: quay.io/thanos/docker-swift-onlyone-authv2-keystone:v0.1
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ go-format: $(GOIMPORTS)

.PHONY: proto
proto: ## Generates Go files from Thanos proto files.
proto: check-git $(GOIMPORTS) $(PROTOC) $(PROTOC_GEN_GOGOFAST)
@GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" PROTOC_GEN_GOGOFAST_BIN="$(PROTOC_GEN_GOGOFAST)" PROTOC_VERSION="$(PROTOC_VERSION)" scripts/genproto.sh
proto: check-git $(GOIMPORTS) $(PROTOC) $(PROTOC_GEN_GOGOFAST) $(PROTOC_GO_INJECT_TAG)
@GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" PROTOC_GEN_GOGOFAST_BIN="$(PROTOC_GEN_GOGOFAST)" PROTOC_VERSION="$(PROTOC_VERSION)" PROTOC_GO_INJECT_TAG_BIN="$(PROTOC_GO_INJECT_TAG)" scripts/genproto.sh

.PHONY: tarballs-release
tarballs-release: ## Build tarballs.
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ func runQuery(

infoSrv := info.NewInfoServer(
component.Query.String(),
info.WithLabelSetFunc(func() []labelpb.LabelSet { return proxyStore.LabelSet() }),
info.WithLabelSetFunc(func() []*labelpb.LabelSet { return proxyStore.LabelSet() }),
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
if httpProbe.IsReady() {
mint, maxt := proxyStore.TimeRange()
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func runReceive(

infoSrv := info.NewInfoServer(
component.Receive.String(),
info.WithLabelSetFunc(func() []labelpb.LabelSet { return proxy.LabelSet() }),
info.WithLabelSetFunc(func() []*labelpb.LabelSet { return proxy.LabelSet() }),
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
if httpProbe.IsReady() {
minTime, maxTime := proxy.TimeRange()
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func runRule(
tsdbStore := store.NewTSDBStore(logger, tsdbDB, component.Rule, conf.lset)
infoOptions = append(
infoOptions,
info.WithLabelSetFunc(func() []labelpb.LabelSet {
info.WithLabelSetFunc(func() []*labelpb.LabelSet {
return tsdbStore.LabelSet()
}),
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func runSidecar(

infoSrv := info.NewInfoServer(
component.Sidecar.String(),
info.WithLabelSetFunc(func() []labelpb.LabelSet {
info.WithLabelSetFunc(func() []*labelpb.LabelSet {
return promStore.LabelSet()
}),
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func runStore(

infoSrv := info.NewInfoServer(
component.Store.String(),
info.WithLabelSetFunc(func() []labelpb.LabelSet {
info.WithLabelSetFunc(func() []*labelpb.LabelSet {
return bs.LabelSet()
}),
info.WithStoreInfoFunc(func() (*infopb.StoreInfo, error) {
Expand Down
61 changes: 30 additions & 31 deletions internal/cortex/cortexpb/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,45 @@ import (

jsoniter "github.com/json-iterator/go"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/thanos-io/thanos/internal/cortex/util"
)

// FromLabelAdaptersToLabels casts []LabelAdapter to labels.Labels.
// It uses unsafe, but as LabelAdapter == labels.Label this should be safe.
// This allows us to use labels.Labels directly in protos.
//
// Note: while resulting labels.Labels is supposedly sorted, this function
// doesn't enforce that. If input is not sorted, output will be wrong.
func FromLabelAdaptersToLabels(ls []LabelAdapter) labels.Labels {
return *(*labels.Labels)(unsafe.Pointer(&ls))
}
func LabelPairToModelMetric(labels []*LabelPair) model.Metric {
m := make(model.Metric, len(labels))
for _, l := range labels {
m[model.LabelName(l.Name)] = model.LabelValue(l.Value)
}

// FromLabelsToLabelAdapters casts labels.Labels to []LabelAdapter.
// It uses unsafe, but as LabelAdapter == labels.Label this should be safe.
// This allows us to use labels.Labels directly in protos.
func FromLabelsToLabelAdapters(ls labels.Labels) []LabelAdapter {
return *(*[]LabelAdapter)(unsafe.Pointer(&ls))
return m
}

// FromLabelAdaptersToMetric converts []LabelAdapter to a model.Metric.
// Don't do this on any performance sensitive paths.
func FromLabelAdaptersToMetric(ls []LabelAdapter) model.Metric {
return util.LabelsToMetric(FromLabelAdaptersToLabels(ls))
func LabelMapToCortexMetric(lbls map[string]string) []*LabelPair {
labels := make([]*LabelPair, 0, len(lbls))
for ln, lv := range lbls {
labels = append(labels, &LabelPair{
Name: []byte(ln),
Value: []byte(lv),
})
}
sort.Slice(labels, func(i, j int) bool {
return strings.Compare(string(labels[i].Name), string(labels[j].Name)) < 0
})

return labels
}

// FromMetricsToLabelAdapters converts model.Metric to []LabelAdapter.
// Don't do this on any performance sensitive paths.
// The result is sorted.
func FromMetricsToLabelAdapters(metric model.Metric) []LabelAdapter {
result := make([]LabelAdapter, 0, len(metric))
for k, v := range metric {
result = append(result, LabelAdapter{
Name: string(k),
Value: string(v),
func ModelMetricToCortexMetric(m model.Metric) []*LabelPair {
labels := make([]*LabelPair, 0, len(m))
for ln, lv := range m {
labels = append(labels, &LabelPair{
Name: []byte(ln),
Value: []byte(lv),
})
}
sort.Sort(byLabel(result)) // The labels should be sorted upon initialisation.
return result
sort.Slice(labels, func(i, j int) bool {
return strings.Compare(string(labels[i].Name), string(labels[j].Name)) < 0
})

return labels
}

type byLabel []LabelAdapter
Expand Down
19 changes: 7 additions & 12 deletions internal/cortex/cortexpb/cortex.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,25 @@ package cortexpb;

option go_package = "cortexpb";

import "gogoproto/gogo.proto";

option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;

message WriteRequest {
repeated TimeSeries timeseries = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "PreallocTimeseries"];
repeated TimeSeries timeseries = 1;
enum SourceEnum {
API = 0;
RULE = 1;
}
SourceEnum Source = 2;
repeated MetricMetadata metadata = 3 [(gogoproto.nullable) = true];
repeated MetricMetadata metadata = 3;

bool skip_label_name_validation = 1000; //set intentionally high to keep WriteRequest compatible with upstream Prometheus
}

message WriteResponse {}

message TimeSeries {
repeated LabelPair labels = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "LabelAdapter"];
repeated LabelPair labels = 1;
// Sorted by time, oldest sample first.
repeated Sample samples = 2 [(gogoproto.nullable) = false];
repeated Exemplar exemplars = 3 [(gogoproto.nullable) = false];
repeated Sample samples = 2;
repeated Exemplar exemplars = 3;
}

message LabelPair {
Expand Down Expand Up @@ -62,12 +57,12 @@ message MetricMetadata {
}

message Metric {
repeated LabelPair labels = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "LabelAdapter"];
repeated LabelPair labels = 1;
}

message Exemplar {
// Exemplar labels, different than series labels
repeated LabelPair labels = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "LabelAdapter"];
repeated LabelPair labels = 1;
double value = 2;
int64 timestamp_ms = 3;
}
10 changes: 5 additions & 5 deletions internal/cortex/querier/queryrange/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func toModelSampleHistogramPair(s SampleHistogramPair) model.SampleHistogramPair
}
}

func fromModelSampleHistogramPair(modelSampleHistogram model.SampleHistogramPair) (s SampleHistogramPair) {
return SampleHistogramPair{
func fromModelSampleHistogramPair(modelSampleHistogram model.SampleHistogramPair) (s *SampleHistogramPair) {
return &SampleHistogramPair{
Timestamp: int64(modelSampleHistogram.Timestamp),
Histogram: fromModelSampleHistogram(modelSampleHistogram.Histogram),
}
}

func fromModelSampleHistogram(modelSampleHistogram *model.SampleHistogram) (s SampleHistogram) {
func fromModelSampleHistogram(modelSampleHistogram *model.SampleHistogram) (s *SampleHistogram) {
buckets := make([]*HistogramBucket, len(modelSampleHistogram.Buckets))

for i, b := range modelSampleHistogram.Buckets {
Expand All @@ -37,14 +37,14 @@ func fromModelSampleHistogram(modelSampleHistogram *model.SampleHistogram) (s Sa
}
}

return SampleHistogram{
return &SampleHistogram{
Count: float64(modelSampleHistogram.Count),
Sum: float64(modelSampleHistogram.Sum),
Buckets: buckets,
}
}

func toModelSampleHistogram(s SampleHistogram) *model.SampleHistogram {
func toModelSampleHistogram(s *SampleHistogram) *model.SampleHistogram {
modelBuckets := make([]*model.HistogramBucket, len(s.Buckets))

for i, b := range s.Buckets {
Expand Down
16 changes: 8 additions & 8 deletions internal/cortex/querier/queryrange/marshaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,33 @@ func BenchmarkPrometheusCodec_EncodeResponse(b *testing.B) {
}

func mockPrometheusResponse(numSeries, numSamplesPerSeries int) *PrometheusResponse {
stream := make([]SampleStream, numSeries)
stream := make([]*SampleStream, numSeries)
for s := 0; s < numSeries; s++ {
// Generate random samples.
samples := make([]cortexpb.Sample, numSamplesPerSeries)
samples := make([]*cortexpb.Sample, numSamplesPerSeries)
for i := 0; i < numSamplesPerSeries; i++ {
samples[i] = cortexpb.Sample{
samples[i] = &cortexpb.Sample{
Value: rand.Float64(),
TimestampMs: int64(i),
}
}

// Generate random labels.
lbls := make([]cortexpb.LabelAdapter, 10)
lbls := make([]*cortexpb.LabelPair, 10)
for i := range lbls {
lbls[i].Name = "a_medium_size_label_name"
lbls[i].Value = "a_medium_size_label_value_that_is_used_to_benchmark_marshalling"
lbls[i].Name = []byte("a_medium_size_label_name")
lbls[i].Value = []byte("a_medium_size_label_value_that_is_used_to_benchmark_marshalling")
}

stream[s] = SampleStream{
stream[s] = &SampleStream{
Labels: lbls,
Samples: samples,
}
}

return &PrometheusResponse{
Status: "success",
Data: PrometheusData{
Data: &PrometheusData{
ResultType: "vector",
Result: stream,
},
Expand Down
Loading

0 comments on commit 97710f4

Please sign in to comment.