Skip to content

Commit

Permalink
Revert "*: removing gogoproto extensions (#7718)"
Browse files Browse the repository at this point in the history
This reverts commit 97710f4.

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS committed Oct 1, 2024
1 parent 7013ad3 commit cb8705d
Show file tree
Hide file tree
Showing 127 changed files with 3,253 additions and 6,802 deletions.
6 changes: 0 additions & 6 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ $(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: 0 additions & 5 deletions .bingo/protoc-go-inject-tag.mod

This file was deleted.

2 changes: 0 additions & 2 deletions .bingo/protoc-go-inject-tag.sum

This file was deleted.

2 changes: 0 additions & 2 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ 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: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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) $(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
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

.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 @@ -796,7 +796,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: 31 additions & 30 deletions internal/cortex/cortexpb/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,46 @@ 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"
)

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)
}

return m
// 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 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
})
// 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 labels
// 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 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),
// 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),
})
}
sort.Slice(labels, func(i, j int) bool {
return strings.Compare(string(labels[i].Name), string(labels[j].Name)) < 0
})

return labels
sort.Sort(byLabel(result)) // The labels should be sorted upon initialisation.
return result
}

type byLabel []LabelAdapter
Expand Down
19 changes: 12 additions & 7 deletions internal/cortex/cortexpb/cortex.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@ 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;
repeated TimeSeries timeseries = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "PreallocTimeseries"];
enum SourceEnum {
API = 0;
RULE = 1;
}
SourceEnum Source = 2;
repeated MetricMetadata metadata = 3;
repeated MetricMetadata metadata = 3 [(gogoproto.nullable) = true];

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

message WriteResponse {}

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

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

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

message Exemplar {
// Exemplar labels, different than series labels
repeated LabelPair labels = 1;
repeated LabelPair labels = 1 [(gogoproto.nullable) = false, (gogoproto.customtype) = "LabelAdapter"];
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 *S
}
}

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.LabelPair, 10)
lbls := make([]cortexpb.LabelAdapter, 10)
for i := range lbls {
lbls[i].Name = []byte("a_medium_size_label_name")
lbls[i].Value = []byte("a_medium_size_label_value_that_is_used_to_benchmark_marshalling")
lbls[i].Name = "a_medium_size_label_name"
lbls[i].Value = "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 cb8705d

Please sign in to comment.