-
Notifications
You must be signed in to change notification settings - Fork 823
#4147 added tenant_id
tag to tracing spans
#4186
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
Changes from 7 commits
3a3cb4b
acef697
f3c5648
4865018
3ff0b80
1d15a71
669b8d2
f0fb3bd
aed8dab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import ( | |
|
||
"github.com/cortexproject/cortex/pkg/tenant" | ||
"github.com/cortexproject/cortex/pkg/util/concurrency" | ||
"github.com/cortexproject/cortex/pkg/util/spanlogger" | ||
) | ||
|
||
const ( | ||
|
@@ -96,6 +97,9 @@ type mergeQueryable struct { | |
// Querier returns a new mergeQuerier, which aggregates results from multiple | ||
// underlying queriers into a single result. | ||
func (m *mergeQueryable) Querier(ctx context.Context, mint int64, maxt int64) (storage.Querier, error) { | ||
// 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. | ||
Comment on lines
+100
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I have played with that here: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
ids, queriers, err := m.callback(ctx, mint, maxt) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -133,6 +137,8 @@ type mergeQuerier struct { | |
// For the label "original_" + `idLabelName it will return all the values | ||
// of the underlying queriers for `idLabelName`. | ||
func (m *mergeQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([]string, storage.Warnings, error) { | ||
log, ctx := spanlogger.New(m.ctx, "mergeQuerier.LabelValues") | ||
defer log.Span.Finish() | ||
if name == m.idLabelName { | ||
return m.ids, nil, nil | ||
} | ||
|
@@ -143,7 +149,8 @@ func (m *mergeQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([] | |
name = m.idLabelName | ||
} | ||
|
||
return m.mergeDistinctStringSlice(func(ctx context.Context, q storage.Querier) ([]string, storage.Warnings, error) { | ||
return m.mergeDistinctStringSlice(ctx, func(ctx context.Context, | ||
q storage.Querier) ([]string, storage.Warnings, error) { | ||
vlad-diachenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return q.LabelValues(name, matchers...) | ||
}) | ||
} | ||
|
@@ -152,7 +159,10 @@ func (m *mergeQuerier) LabelValues(name string, matchers ...*labels.Matcher) ([] | |
// queriers. It also adds the `idLabelName` and if present in the original | ||
// results the original `idLabelName`. | ||
func (m *mergeQuerier) LabelNames() ([]string, storage.Warnings, error) { | ||
labelNames, warnings, err := m.mergeDistinctStringSlice(func(ctx context.Context, q storage.Querier) ([]string, storage.Warnings, error) { | ||
log, ctx := spanlogger.New(m.ctx, "mergeQuerier.LabelNames") | ||
defer log.Span.Finish() | ||
labelNames, warnings, err := m.mergeDistinctStringSlice(ctx, func(ctx context.Context, | ||
vlad-diachenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
q storage.Querier) ([]string, storage.Warnings, error) { | ||
return q.LabelNames() | ||
}) | ||
if err != nil { | ||
|
@@ -196,7 +206,8 @@ type stringSliceFuncJob struct { | |
// on per querier in parallel. It removes duplicates and sorts the result. It | ||
// doesn't require the output of the stringSliceFunc to be sorted, as results | ||
// of LabelValues are not sorted. | ||
func (m *mergeQuerier) mergeDistinctStringSlice(f stringSliceFunc) ([]string, storage.Warnings, error) { | ||
func (m *mergeQuerier) mergeDistinctStringSlice(ctx context.Context, | ||
vlad-diachenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
f stringSliceFunc) ([]string, storage.Warnings, error) { | ||
var jobs = make([]interface{}, len(m.ids)) | ||
|
||
for pos := range m.ids { | ||
|
@@ -221,7 +232,7 @@ func (m *mergeQuerier) mergeDistinctStringSlice(f stringSliceFunc) ([]string, st | |
return nil | ||
} | ||
|
||
err := concurrency.ForEach(m.ctx, jobs, maxConcurrency, run) | ||
err := concurrency.ForEach(ctx, jobs, maxConcurrency, run) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
@@ -272,6 +283,8 @@ type selectJob struct { | |
// matching. The forwarded labelSelector is not containing those that operate | ||
// on `idLabelName`. | ||
func (m *mergeQuerier) Select(sortSeries bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet { | ||
log, ctx := spanlogger.New(m.ctx, "mergeQuerier.Select") | ||
defer log.Span.Finish() | ||
matchedValues, filteredMatchers := filterValuesByMatchers(m.idLabelName, m.ids, matchers...) | ||
var jobs = make([]interface{}, len(matchedValues)) | ||
var seriesSets = make([]storage.SeriesSet, len(matchedValues)) | ||
|
@@ -305,7 +318,7 @@ func (m *mergeQuerier) Select(sortSeries bool, hints *storage.SelectHints, match | |
return nil | ||
} | ||
|
||
err := concurrency.ForEach(m.ctx, jobs, maxConcurrency, run) | ||
err := concurrency.ForEach(ctx, jobs, maxConcurrency, run) | ||
if err != nil { | ||
return storage.ErrSeriesSet(err) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.