Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ require (
github.com/prometheus/alertmanager v0.25.0
github.com/prometheus/common/sigv4 v0.1.0
github.com/richardartoul/molecule v1.0.0
github.com/sourcegraph/conc v0.3.0
github.com/thanos-io/objstore v0.0.0-20230201072718-11ffbc490204
github.com/willf/bloom v2.0.3+incompatible
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f
Expand Down Expand Up @@ -300,7 +301,7 @@ require (
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/metric v0.37.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/term v0.10.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,8 @@ github.com/soniah/gosnmp v1.25.0/go.mod h1:8YvfZxH388NIIw2A+X5z2Oh97VcNhtmxDLt5Q
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/sony/gobreaker v0.5.0 h1:dRCvqm0P490vZPmy7ppEk2qCnCieBooFJ+YoXGYB+yg=
github.com/sony/gobreaker v0.5.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down Expand Up @@ -1777,8 +1779,8 @@ go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
Expand Down
43 changes: 23 additions & 20 deletions pkg/querier/multi_tenant_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/go-kit/log"
"github.com/grafana/dskit/user"
"github.com/prometheus/prometheus/model/labels"
"github.com/sourcegraph/conc/pool"

"github.com/grafana/dskit/tenant"

Expand Down Expand Up @@ -53,17 +54,18 @@ func (q *MultiTenantQuerier) SelectLogs(ctx context.Context, params logql.Select
matchedTenants, filteredMatchers := filterValuesByMatchers(defaultTenantLabel, tenantIDs, selector.Matchers()...)
params.Selector = replaceMatchers(selector, filteredMatchers).String()

iters := make([]iter.EntryIterator, len(matchedTenants))
i := 0
p := pool.NewWithResults[iter.EntryIterator]().WithErrors() //.WithContext(ctx).WithCancelOnError()
for id := range matchedTenants {
singleContext := user.InjectOrgID(ctx, id)
iter, err := q.Querier.SelectLogs(singleContext, params)
if err != nil {
return nil, err
}

iters[i] = NewTenantEntryIterator(iter, id)
i++
id := id
p.Go(func() (iter.EntryIterator, error) {
singleContext := user.InjectOrgID(ctx, id)
iter, err := q.Querier.SelectLogs(singleContext, params)
return NewTenantEntryIterator(iter, id), err
})
}
iters, err := p.Wait()
if err != nil {
return nil, err
}
return iter.NewSortEntryIterator(iters, params.Direction), nil
}
Expand All @@ -84,17 +86,18 @@ func (q *MultiTenantQuerier) SelectSamples(ctx context.Context, params logql.Sel
}
params.Selector = updatedSelector.String()

iters := make([]iter.SampleIterator, len(matchedTenants))
i := 0
p := pool.NewWithResults[iter.SampleIterator]().WithErrors() //.WithContext(ctx).WithCancelOnError()
for id := range matchedTenants {
singleContext := user.InjectOrgID(ctx, id)
iter, err := q.Querier.SelectSamples(singleContext, params)
if err != nil {
return nil, err
}

iters[i] = NewTenantSampleIterator(iter, id)
i++
id := id
p.Go(func() (iter.SampleIterator, error) {
singleContext := user.InjectOrgID(ctx, id)
iter, err := q.Querier.SelectSamples(singleContext, params)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fails with a cancelled context when run a second time. I have a hard time understanding why.

return NewTenantSampleIterator(iter, id), err
})
}
iters, err := p.Wait()
if err != nil {
return nil, err
}
return iter.NewSortSampleIterator(iters), nil
}
Expand Down
19 changes: 12 additions & 7 deletions pkg/querier/multi_tenant_querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestMultiTenantQuerier_SelectLogs(t *testing.T) {
`{__tenant_id__="1", type="test"}`,
`{__tenant_id__="1", type="test"}`,
},
[]string{"line 1", "line 2", "line 1", "line 2"},
[]string{"line 1", "line 2"},
},
{
"two tenants with selector and pipeline filter",
Expand All @@ -63,7 +63,7 @@ func TestMultiTenantQuerier_SelectLogs(t *testing.T) {
`{__tenant_id__="1", type="test"}`,
`{__tenant_id__="1", type="test"}`,
},
[]string{"line 1", "line 2", "line 1", "line 2"},
[]string{"line 1", "line 2"},
},
{
"one tenant",
Expand Down Expand Up @@ -94,13 +94,14 @@ func TestMultiTenantQuerier_SelectLogs(t *testing.T) {
iter, err := multiTenantQuerier.SelectLogs(ctx, params)
require.NoError(t, err)

entriesCount := 0
actualLabels := make([]string, 0)
actualLines := make([]string, 0)
for iter.Next() {
require.Equal(t, tc.expLabels[entriesCount], iter.Labels())
require.Equal(t, tc.expLines[entriesCount], iter.Entry().Line)
entriesCount++
actualLabels = append(actualLabels, iter.Labels())
actualLines = append(actualLines, iter.Entry().Line)
}
require.Equalf(t, len(tc.expLabels), entriesCount, "Expected %d entries but got %d", len(tc.expLabels), entriesCount)
require.ElementsMatch(t, tc.expLabels, actualLabels)
require.ElementsMatch(t, tc.expLines, actualLines)
})
}
}
Expand Down Expand Up @@ -165,6 +166,10 @@ func TestMultiTenantQuerier_SelectSamples(t *testing.T) {
iter, err := multiTenantQuerier.SelectSamples(ctx, params)
require.NoError(t, err)

// Subsequent calls succeed
_, err = multiTenantQuerier.SelectSamples(ctx, params)
require.NoError(t, err)

received := make([]string, 0, len(tc.expLabels))
for iter.Next() {
received = append(received, iter.Labels())
Expand Down
8 changes: 8 additions & 0 deletions tools/dev/loki-boltdb-storage-s3/config/datasource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ datasources:
httpHeaderName1: 'X-Scope-OrgID'
secureJsonData:
httpHeaderValue1: '1'
- name: Loki-Cross-Tenant
type: loki
access: proxy
url: http://query-frontend:8007
jsonData:
httpHeaderName1: 'X-Scope-OrgID'
secureJsonData:
httpHeaderValue1: '1|2'
- name: Loki-Limited
type: loki
access: proxy
Expand Down
11 changes: 11 additions & 0 deletions vendor/github.com/sourcegraph/conc/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/sourcegraph/conc/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading