Skip to content

Commit

Permalink
removed gogo-proto extensions from *.proto (#1)
Browse files Browse the repository at this point in the history
* removed gogo-proto extensions from rpc.proto

Signed-off-by: rahulii <[email protected]>

* store: convert to a slice of pointers

Signed-off-by: Giedrius Statkevičius <[email protected]>

* removed gogoproto specific extensions and generated code

* removed Zlabel custom type and ran make proto

Signed-off-by: rahulii <[email protected]>

* labelpb: update functions to not use ZLabels

Signed-off-by: Giedrius Statkevičius <[email protected]>

* store: convert chunks to pointers

Signed-off-by: Giedrius Statkevičius <[email protected]>

* *: convert to use *labelpb.Label

Signed-off-by: Giedrius Statkevičius <[email protected]>

* resolve errors

* make use of custom json tag

* more changes and resolve errors

* store: convert more places to use pointers

Signed-off-by: Giedrius Statkevičius <[email protected]>

* replaced gogo-json-tag with protoc-go-inject-tag

* scripts/genproto: add hack for protobuf types

Signed-off-by: Giedrius Statkevičius <[email protected]>

* convert time.Time to protobuf.Timestamp

* migrate time.Time to protobuf.Timestamp

* resolving tests error

* resolve tests errors

* implement custom MarshalJSON

* partial fix to tests

* fix to tests

* fix to tests

* fix to more tests

* rules: make tests clearer

Signed-off-by: Giedrius Statkevičius <[email protected]>

* rulespb: fix some timestamp stuff

Signed-off-by: Giedrius Statkevičius <[email protected]>

* api: reuse same function, fix tests

Signed-off-by: Giedrius Statkevičius <[email protected]>

* rules: use proper default value for Timestamp

Signed-off-by: Giedrius Statkevičius <[email protected]>

* fix to tests

* fix tests

* metadata: fix tests

Signed-off-by: Giedrius Statkevičius <[email protected]>

* *: remove unused files

Signed-off-by: Giedrius Statkevičius <[email protected]>

* e2e: fix more timestamp problems

Signed-off-by: Giedrius Statkevičius <[email protected]>

Co-authored-by: rahulii <[email protected]>
Co-authored-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
3 people authored Nov 9, 2021
1 parent 4cdc570 commit 9eceeea
Show file tree
Hide file tree
Showing 87 changed files with 4,343 additions and 1,914 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/efficientgo/e2e v0.11.1-0.20210829161758-f4cc6dbdc6ea
github.com/efficientgo/tools/extkingpin v0.0.0-20210609125236-d73259166f20
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
github.com/fatih/structtag v1.1.0
github.com/fatih/structtag v1.2.0
github.com/felixge/fgprof v0.9.1
github.com/fortytw2/leaktest v1.3.0
github.com/fsnotify/fsnotify v1.4.9
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,9 @@ github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:bH6Xx7IW
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/structtag v1.1.0 h1:6j4mUV/ES2duvnAzKMFkN6/A5mCaNYPD3xfbAkLLOF8=
github.com/fatih/structtag v1.1.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/felixge/fgprof v0.9.1 h1:E6FUJ2Mlv043ipLOCFqo8+cHo9MhQ203E2cdEK/isEs=
github.com/felixge/fgprof v0.9.1/go.mod h1:7/HK6JFtFaARhIljgP2IV8rJLIoHDoOYoUphsnGvqxE=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ func NewMetricMetadataHandler(client metadata.UnaryClient, enablePartialResponse
defer span.Finish()

var (
t map[string][]metadatapb.Meta
t map[string][]*metadatapb.Meta
warnings storage.Warnings
err error
)
Expand Down
71 changes: 36 additions & 35 deletions pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1445,64 +1445,63 @@ func TestParseStoreDebugMatchersParam(t *testing.T) {
}

func TestRulesHandler(t *testing.T) {
twoHAgo := time.Now().Add(-2 * time.Hour)
all := []*rulespb.Rule{
rulespb.NewRecordingRule(&rulespb.RecordingRule{
Name: "1",
LastEvaluation: time.Time{}.Add(1 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(1 * time.Minute)),
EvaluationDurationSeconds: 12,
Health: "x",
Query: "sum(up)",
Labels: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "some", Value: "label"}}},
Labels: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "some", Value: "label"}}},
LastError: "err1",
}),
rulespb.NewRecordingRule(&rulespb.RecordingRule{
Name: "2",
LastEvaluation: time.Time{}.Add(2 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(2 * time.Minute)),
EvaluationDurationSeconds: 12,
Health: "x",
Query: "sum(up1)",
Labels: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "some", Value: "label2"}}},
Labels: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "some", Value: "label2"}}},
}),
rulespb.NewAlertingRule(&rulespb.Alert{
Name: "3",
LastEvaluation: time.Time{}.Add(3 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(3 * time.Minute)),
EvaluationDurationSeconds: 12,
Health: "x",
Query: "sum(up2) == 2",
DurationSeconds: 101,
Labels: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "some", Value: "label3"}}},
Annotations: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "ann", Value: "a1"}}},
Labels: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "some", Value: "label3"}}},
Annotations: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "ann", Value: "a1"}}},
Alerts: []*rulespb.AlertInstance{
{
Labels: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "inside", Value: "1"}}},
Annotations: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "insideann", Value: "2"}}},
Labels: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "inside", Value: "1"}}},
Annotations: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "insideann", Value: "2"}}},
State: rulespb.AlertState_FIRING,
ActiveAt: &twoHAgo,
Value: "1",
// This is unlikely if groups is warn, but test nevertheless.
PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT,
ActiveAt: rulespb.TimeToTimestamp(time.Time{}),
},
{
Labels: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "inside", Value: "3"}}},
Annotations: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "insideann", Value: "4"}}},
Labels: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "inside", Value: "3"}}},
Annotations: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "insideann", Value: "4"}}},
State: rulespb.AlertState_PENDING,
ActiveAt: nil,
Value: "2",
// This is unlikely if groups is warn, but test nevertheless.
PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT,
ActiveAt: rulespb.TimeToTimestamp(time.Time{}),
},
},
State: rulespb.AlertState_FIRING,
}),
rulespb.NewAlertingRule(&rulespb.Alert{
Name: "4",
LastEvaluation: time.Time{}.Add(4 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(4 * time.Minute)),
EvaluationDurationSeconds: 122,
Health: "x",
DurationSeconds: 102,
Query: "sum(up3) == 3",
Labels: labelpb.ZLabelSet{Labels: []labelpb.ZLabel{{Name: "some", Value: "label4"}}},
Labels: &labelpb.ZLabelSet{Labels: []*labelpb.Label{{Name: "some", Value: "label4"}}},
State: rulespb.AlertState_INACTIVE,
}),
}
Expand All @@ -1516,7 +1515,7 @@ func TestRulesHandler(t *testing.T) {
Rules: all,
Interval: 1,
EvaluationDurationSeconds: 214,
LastEvaluation: time.Time{}.Add(10 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(10 * time.Minute)),
PartialResponseStrategy: storepb.PartialResponseStrategy_WARN,
},
{
Expand All @@ -1525,7 +1524,7 @@ func TestRulesHandler(t *testing.T) {
Rules: all[3:],
Interval: 10,
EvaluationDurationSeconds: 2142,
LastEvaluation: time.Time{}.Add(100 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(100 * time.Minute)),
PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT,
},
},
Expand All @@ -1536,7 +1535,7 @@ func TestRulesHandler(t *testing.T) {
Rules: all[:2],
Interval: 1,
EvaluationDurationSeconds: 214,
LastEvaluation: time.Time{}.Add(20 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(20 * time.Minute)),
PartialResponseStrategy: storepb.PartialResponseStrategy_WARN,
},
},
Expand All @@ -1547,7 +1546,7 @@ func TestRulesHandler(t *testing.T) {
Rules: all[2:],
Interval: 1,
EvaluationDurationSeconds: 214,
LastEvaluation: time.Time{}.Add(30 * time.Minute),
LastEvaluation: rulespb.TimeToTimestamp(time.Time{}.Add(30 * time.Minute)),
PartialResponseStrategy: storepb.PartialResponseStrategy_WARN,
},
},
Expand All @@ -1559,52 +1558,54 @@ func TestRulesHandler(t *testing.T) {
query url.Values
response interface{}
}
l0 := labelpb.ProtobufLabelsToPromLabels(all[2].GetAlert().Alerts[0].Labels.Labels)
a0 := labelpb.ProtobufLabelsToPromLabels(all[2].GetAlert().Alerts[0].Annotations.Labels)
l1 := labelpb.ProtobufLabelsToPromLabels(all[2].GetAlert().Alerts[1].Labels.Labels)
a1 := labelpb.ProtobufLabelsToPromLabels(all[2].GetAlert().Alerts[1].Annotations.Labels)
expectedAll := []testpromcompatibility.Rule{
testpromcompatibility.RecordingRule{
Name: all[0].GetRecording().Name,
Query: all[0].GetRecording().Query,
Labels: labelpb.ZLabelsToPromLabels(all[0].GetRecording().Labels.Labels),
Labels: labelpb.ProtobufLabelsToPromLabels(all[0].GetRecording().Labels.Labels),
Health: rules.RuleHealth(all[0].GetRecording().Health),
LastError: all[0].GetRecording().LastError,
LastEvaluation: all[0].GetRecording().LastEvaluation,
LastEvaluation: rulespb.TimestampToTime(all[0].GetRecording().LastEvaluation),
EvaluationTime: all[0].GetRecording().EvaluationDurationSeconds,
Type: "recording",
},
testpromcompatibility.RecordingRule{
Name: all[1].GetRecording().Name,
Query: all[1].GetRecording().Query,
Labels: labelpb.ZLabelsToPromLabels(all[1].GetRecording().Labels.Labels),
Labels: labelpb.ProtobufLabelsToPromLabels(all[1].GetRecording().Labels.Labels),
Health: rules.RuleHealth(all[1].GetRecording().Health),
LastError: all[1].GetRecording().LastError,
LastEvaluation: all[1].GetRecording().LastEvaluation,
LastEvaluation: rulespb.TimestampToTime(all[1].GetRecording().LastEvaluation),
EvaluationTime: all[1].GetRecording().EvaluationDurationSeconds,
Type: "recording",
},
testpromcompatibility.AlertingRule{
State: strings.ToLower(all[2].GetAlert().State.String()),
Name: all[2].GetAlert().Name,
Query: all[2].GetAlert().Query,
Labels: labelpb.ZLabelsToPromLabels(all[2].GetAlert().Labels.Labels),
Labels: labelpb.ProtobufLabelsToPromLabels(all[2].GetAlert().Labels.Labels),
Health: rules.RuleHealth(all[2].GetAlert().Health),
LastError: all[2].GetAlert().LastError,
LastEvaluation: all[2].GetAlert().LastEvaluation,
LastEvaluation: rulespb.TimestampToTime(all[2].GetAlert().LastEvaluation),
EvaluationTime: all[2].GetAlert().EvaluationDurationSeconds,
Duration: all[2].GetAlert().DurationSeconds,
Annotations: labelpb.ZLabelsToPromLabels(all[2].GetAlert().Annotations.Labels),
Annotations: labelpb.ProtobufLabelsToPromLabels(all[2].GetAlert().Annotations.Labels),
Alerts: []*testpromcompatibility.Alert{
{
Labels: labelpb.ZLabelsToPromLabels(all[2].GetAlert().Alerts[0].Labels.Labels),
Annotations: labelpb.ZLabelsToPromLabels(all[2].GetAlert().Alerts[0].Annotations.Labels),
Labels: &l0,
Annotations: &a0,
State: strings.ToLower(all[2].GetAlert().Alerts[0].State.String()),
ActiveAt: all[2].GetAlert().Alerts[0].ActiveAt,
Value: all[2].GetAlert().Alerts[0].Value,
PartialResponseStrategy: all[2].GetAlert().Alerts[0].PartialResponseStrategy.String(),
},
{
Labels: labelpb.ZLabelsToPromLabels(all[2].GetAlert().Alerts[1].Labels.Labels),
Annotations: labelpb.ZLabelsToPromLabels(all[2].GetAlert().Alerts[1].Annotations.Labels),
Labels: &l1,
Annotations: &a1,
State: strings.ToLower(all[2].GetAlert().Alerts[1].State.String()),
ActiveAt: all[2].GetAlert().Alerts[1].ActiveAt,
Value: all[2].GetAlert().Alerts[1].Value,
PartialResponseStrategy: all[2].GetAlert().Alerts[1].PartialResponseStrategy.String(),
},
Expand All @@ -1615,10 +1616,10 @@ func TestRulesHandler(t *testing.T) {
State: strings.ToLower(all[3].GetAlert().State.String()),
Name: all[3].GetAlert().Name,
Query: all[3].GetAlert().Query,
Labels: labelpb.ZLabelsToPromLabels(all[3].GetAlert().Labels.Labels),
Labels: labelpb.ProtobufLabelsToPromLabels(all[3].GetAlert().Labels.Labels),
Health: rules.RuleHealth(all[2].GetAlert().Health),
LastError: all[3].GetAlert().LastError,
LastEvaluation: all[3].GetAlert().LastEvaluation,
LastEvaluation: rulespb.TimestampToTime(all[3].GetAlert().LastEvaluation),
EvaluationTime: all[3].GetAlert().EvaluationDurationSeconds,
Duration: all[3].GetAlert().DurationSeconds,
Annotations: nil,
Expand Down
6 changes: 3 additions & 3 deletions pkg/exemplars/exemplars.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func dedupExemplarsResponse(exemplarsData []*exemplarspb.ExemplarData, replicaLa
continue
}
e.SeriesLabels.Labels = removeReplicaLabels(e.SeriesLabels.Labels, replicaLabels)
h := labelpb.ZLabelsToPromLabels(e.SeriesLabels.Labels).Hash()
h := labelpb.ProtobufLabelsToPromLabels(e.SeriesLabels.Labels).Hash()
if ref, ok := hashToExemplar[h]; ok {
ref.Exemplars = append(ref.Exemplars, e.Exemplars...)
} else {
Expand Down Expand Up @@ -144,11 +144,11 @@ func dedupExemplars(exemplars []*exemplarspb.Exemplar) []*exemplarspb.Exemplar {
return exemplars[:i+1]
}

func removeReplicaLabels(labels []labelpb.ZLabel, replicaLabels map[string]struct{}) []labelpb.ZLabel {
func removeReplicaLabels(labels []*labelpb.Label, replicaLabels map[string]struct{}) []*labelpb.Label {
if len(replicaLabels) == 0 {
return labels
}
newLabels := make([]labelpb.ZLabel, 0, len(labels))
newLabels := make([]*labelpb.Label, 0, len(labels))
for _, l := range labels {
if _, ok := replicaLabels[l.Name]; !ok {
newLabels = append(newLabels, l)
Expand Down
Loading

0 comments on commit 9eceeea

Please sign in to comment.