Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement federated exemplar API #3846

Merged
merged 15 commits into from
Mar 22, 2021
Merged

Implement federated exemplar API #3846

merged 15 commits into from
Mar 22, 2021

Conversation

goku321
Copy link
Contributor

@goku321 goku321 commented Feb 26, 2021

Signed-off-by: Deepak [email protected]

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Fixes: #3435

This PR follows the PR #3350 and comment #3345 to implement the Prometheus exemplar API

Changes

Add federated exemplar api to query and sidecar.

Verification

testing in progress

@goku321
Copy link
Contributor Author

goku321 commented Feb 26, 2021

@bwplotka @yeya24 I've tried to complete this as much as possible but there are still few gaps. A review would really be helpful to find out all the issues this pr has.

Changes I'm not sure about:

  1. pkg/exemplars/exemplarspb/custom.go
  2. pkg/exemplars/exemplars.go
  3. test/e2e/exemplars_api_test.go

Also, I'll make sure to add required tests.

Thank you for your support and guidance.

@yeya24
Copy link
Contributor

yeya24 commented Feb 26, 2021

Thanks for the great work! Looks perfect at the first glance. I will do some detailed review next week.

Have you tested this manually with the WIP upstream branch? prometheus/prometheus#6635

@goku321
Copy link
Contributor Author

goku321 commented Feb 26, 2021

Have you tested this manually with the WIP upstream branch? prometheus/prometheus#6635

Not yet 😅 . Will be doing it very soon.

@yeya24
Copy link
Contributor

yeya24 commented Feb 27, 2021

I fixed some existing problems in this pr and it is working now! Will add some detailed comments tomorrow. Feel free to check my commit here.

If you want to experiment with this, feel free to try this tns app https://github.com/yeya24/tns/tree/thanos/production/docker-compose. I added Thanos sidecar and querier there.

Screenshot from 2021-02-27 01-34-54

It works smoothly. Thanks @goku321!

@@ -152,6 +158,8 @@ func (qapi *QueryAPI) Register(r *route.Router, tracer opentracing.Tracer, logge
r.Get("/rules", instr("rules", NewRulesHandler(qapi.ruleGroups, qapi.enableRulePartialResponse)))

r.Get("/metadata", instr("metadata", NewMetricMetadataHandler(qapi.metadatas, qapi.enableMetricMetadataPartialResponse)))

r.Get("/exemplars", instr("exemplars", NewExemplarsHandler(qapi.exemplars, qapi.enableExemplarPartialResponse)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

return func(r *http.Request) (interface{}, []error, *api.ApiError) {
typeParam := r.URL.Query().Get("type")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this param for?
Let's be consistent with the upstream pr.
The params we want to have are:

- `query=<string>`: Prometheus expression query string.
- `start=<rfc3339 | unix_timestamp>`: Start timestamp.
- `end=<rfc3339 | unix_timestamp>`: End timestamp.

string instance = 1 [(gogoproto.jsontag) = "instance"];
string job = 2 [(gogoproto.jsontag) = "job"];
string service = 3 [(gogoproto.jsontag) = "service"];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems not used. Let's remove it.

double value = 2 [(gogoproto.jsontag) = "value"];
google.protobuf.Timestamp ts = 3 [(gogoproto.jsontag) = "timestamp", (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
bool hasts = 4 [(gogoproto.jsontag) = "hasTimestamp"];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line.

message Exemplar {
ZLabelSet labels = 1 [(gogoproto.jsontag) = "labels", (gogoproto.nullable) = false];
double value = 2 [(gogoproto.jsontag) = "value"];
google.protobuf.Timestamp ts = 3 [(gogoproto.jsontag) = "timestamp", (gogoproto.stdtime) = true, (gogoproto.nullable) = false ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// NOTE: This method is tested in pkg/store/prometheus_test.go against Prometheus.
func (c *Client) ExemplarsInGRPC(ctx context.Context, base *url.URL, typeExemplars string) ([]*exemplarspb.ExemplarData, error) {
u := *base
u.Path = path.Join(u.Path, "/api/v1/exemplars")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Let's change the endpoint.

// Prometheus does not support PartialResponseStrategy, and probably would never do. Make it Abort by default.
for _, g := range m.Data {
g.PartialResponseStrategy = storepb.PartialResponseStrategy_ABORT
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need to keep this PartialResponseStrategy field in the proto. Let's remove it for now.

// message Label {
// string name = 1 [(gogoproto.jsontag) = "name"];
// string value = 2 [(gogoproto.jsontag) = "value"];
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this


warnings []error
data []*exemplarspb.ExemplarData
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add two additional methods for it yeya24@1b6abfc#diff-d09c4014e056aee5c67a76aca788de273aecb440edefc8a3b040bc77e27f2c38R39-R55, otherwise it will panic.

@yeya24
Copy link
Contributor

yeya24 commented Mar 3, 2021

@goku321 Let me know your availability. If it is acceptable I can open a pr to your branch as I have a working version already yeya24@1b6abfc.

@goku321
Copy link
Contributor Author

goku321 commented Mar 3, 2021

Hi @yeya24 , I was a bit caught up, thanks for your patience.

By all means. Please go ahead with the pr. I am glad to have your help on this. I really appreciate your time and effort on fixing this pr.

If it is acceptable I can open a pr to your branch as I have a working version already

@yeya24
Copy link
Contributor

yeya24 commented Mar 3, 2021

It is not urgent. Anyway, we need to wait for the upstream Prometheus pr first XD

@goku321
Copy link
Contributor Author

goku321 commented Mar 3, 2021

I fixed some existing problems in this pr and it is working now! Will add some detailed comments tomorrow. Feel free to check my commit here.

If you want to experiment with this, feel free to try this tns app https://github.com/yeya24/tns/tree/thanos/production/docker-compose. I added Thanos sidecar and querier there.

Screenshot from 2021-02-27 01-34-54

It works smoothly. Thanks @goku321!

Sure, I'll try out the tns app to get a better understanding.

)

// Proxy implements exemplarspb.Exemplars gRPC that fanouts requests to
// given exemplarspb.Exemplars and de-duplication on the way.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update this comment. Currently, Proxy itself does not deduplicate. Instead, the it seems to be a responsibility of the caller of proxy.Exemplars to deduplication. Alternatively, we can make it so that the Proxy needs to deduplication.

test/e2e/e2ethanos/services.go Outdated Show resolved Hide resolved
test/e2e/e2ethanos/services.go Outdated Show resolved Hide resolved
test/e2e/e2ethanos/services.go Outdated Show resolved Hide resolved
test/e2e/e2ethanos/services.go Outdated Show resolved Hide resolved
pkg/exemplars/exemplars_test.go Show resolved Hide resolved
pkg/exemplars/exemplarspb/custom.go Outdated Show resolved Hide resolved
pkg/exemplars/exemplarspb/custom.go Outdated Show resolved Hide resolved
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goku321 Thanks for the great work! This is super close now, only some nits and testcases are left.

pkg/api/query/v1.go Show resolved Hide resolved
pkg/exemplars/exemplarspb/custom.go Outdated Show resolved Hide resolved
goku321 added 2 commits March 22, 2021 22:21
Signed-off-by: Deepak <[email protected]>
@goku321 goku321 requested a review from yeya24 March 22, 2021 16:56
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect work @goku321. One last thing, can you please update the changelog?
I think this pr is ready to merge. But it would be better to have another 👀 for a final look.

Note: There is no E2E API test for this feature now as we don't have an app instrumented with exemplars. We can move E2E part to another pr.

goku321 added 2 commits March 22, 2021 23:08
Signed-off-by: Deepak <[email protected]>
@goku321 goku321 requested a review from squat March 22, 2021 17:43
Copy link
Member

@squat squat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean to me!

@yeya24 yeya24 merged commit 468d0d6 into thanos-io:main Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exemplar API: For now in sidecar and querier
3 participants