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

#4147 added tenant_id tag to tracing spans #4186

Conversation

vlad-diachenko
Copy link
Contributor

@vlad-diachenko vlad-diachenko commented May 14, 2021

What this PR does:

  1. added logic to add tag tenant_ids to tracing spans if tenant is defined in context.
  2. added additional tracing spans to merge_querier's methods

Which issue(s) this PR fixes:
Fixes #4147

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

1. added logic to add tag `tenant_id` to tracing spans if tenant is defined in context.
2. added additional tracing spans to merge_querier's methods

Signed-off-by: Vladyslav Diachenko <[email protected]>
@vlad-diachenko vlad-diachenko force-pushed the added_tenant_id_tag_to_tracing_span branch from 62a9c87 to acef697 Compare May 17, 2021 11:31
Copy link
Contributor

@simonswine simonswine left a comment

Choose a reason for hiding this comment

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

Thanks this looks already quite good. 👍

See my comments in-line and feel free to ping me when things are unclear

Comment on lines +100 to +102
// TODO: it's necessary to think how to override context inside querier
// to mark spans created inside querier as child of a span created inside
// methods of merged querier.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make sense to create a span during the creation of the queriers and the finish the span once Close() of the resulting mergeQuerier is called.

I have played with that here:

6ebd273

That's how that looks like:
scrn-2021-05-17-12-46-02

Copy link
Contributor

Choose a reason for hiding this comment

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

This feels at least like it can group the same tenants nicely together. Obvisouly for a real fix we need context propagation as a part of LabelValues,LabelName, Select.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it will help to group spans by tenant_id . thanks, i will implement it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

however, it might confuse a little bit because all spans mergeQuerier.NewQuerier will take almost similar time for each tenant. but inside this span we will see real picture.
in current implementation it looks less confusing, i think.
image

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest I agree partly with your point, but I am not too sure, how to fix this properly.

I guess part of the problem is that the a query is only finished once Close() is called, which happens at the same time for underlying queriers.

I think the most confusing part of not grouping spans by tenant_id is seeing all (and even unrelated) spans together. I think until we implement context passing in those methods, we won't be able to solve that properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could instantiate the queriers (call the callback inside LabelValues, etc.) and the right context will be applied.

@@ -34,6 +39,9 @@ func New(ctx context.Context, method string, kvps ...interface{}) (*SpanLogger,
// retrieved with FromContext or FromContextWithFallback.
func NewWithLogger(ctx context.Context, l log.Logger, method string, kvps ...interface{}) (*SpanLogger, context.Context) {
span, ctx := opentracing.StartSpanFromContext(ctx, method)
if ids, _ := tenant.TenantIDs(ctx); ids != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not too sure what other side effects this could have, but I think in general it is a good idea to always have the context's tenant_id(s) in the tracing span.

1.changed value of tenant_id tag in tracing span from string value to array
2. removed import alias for spanlogger

Signed-off-by: Vladyslav Diachenko <[email protected]>
Copy link
Contributor

@replay replay left a comment

Choose a reason for hiding this comment

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

LGTM, I only have minor comments

(note that I'm not a maintainer, so this approval doesn't count towards the required approval count)

1. fixed tests
2. fixed name of the spans in mergeQuerier

Signed-off-by: Vladyslav Diachenko <[email protected]>
Signed-off-by: Vladyslav Diachenko <[email protected]>
Copy link
Contributor

@gouthamve gouthamve left a comment

Choose a reason for hiding this comment

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

LGTM, and I wonder how bad is creating the queriers inside Select, LabelValues, etc.

…gSlice function to create inner spans under this context

Signed-off-by: Vladyslav Diachenko <[email protected]>
Copy link
Contributor

@simonswine simonswine left a comment

Choose a reason for hiding this comment

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

LGTM

I think there is still a go mod vendor necessary to make the CI/CD work

@simonswine
Copy link
Contributor

I wonder how bad is creating the queriers inside Select, LabelValues, etc.

I think with Select it might be problematic, as it would have to Close() before the stoarge.SeriesSet is fully iterated through

@vlad-diachenko vlad-diachenko force-pushed the added_tenant_id_tag_to_tracing_span branch from 54b81ba to 669b8d2 Compare May 20, 2021 10:31
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM modulo a couple of nits I would be glad to see fixed before merging. Thanks!

…am that is not used in callback function

Signed-off-by: Vladyslav Diachenko <[email protected]>
Signed-off-by: Vladyslav Diachenko <[email protected]>
@pracucci pracucci enabled auto-merge (squash) May 20, 2021 18:53
@pracucci pracucci merged commit f675736 into cortexproject:master May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tracing to the tenant federation mergeQueryable
6 participants