Skip to content

Commit acef697

Browse files
#4147 fixed errors reported by linters
Signed-off-by: Vladyslav Diachenko <[email protected]>
1 parent 3a3cb4b commit acef697

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

pkg/querier/tenantfederation/merge_queryable_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010
"time"
1111

12-
sl "github.com/cortexproject/cortex/pkg/util/spanlogger"
1312
"github.com/opentracing/opentracing-go"
1413
"github.com/opentracing/opentracing-go/mocktracer"
1514
"github.com/prometheus/common/model"
@@ -21,6 +20,7 @@ import (
2120

2221
"github.com/cortexproject/cortex/pkg/querier/series"
2322
"github.com/cortexproject/cortex/pkg/tenant"
23+
sl "github.com/cortexproject/cortex/pkg/util/spanlogger"
2424
)
2525

2626
const (
@@ -507,9 +507,9 @@ func TestTracingMergeQueryable(t *testing.T) {
507507

508508
require.NoError(t, seriesSet.Err())
509509
spans := mockTracer.FinishedSpans()
510-
assertSpanExist(t, spans, "mergeQuerier.select", map[string]string{sl.TenantIdTagName: "team-a|team-b"})
511-
assertSpanExist(t, spans, "mockTenantQuerier.select", map[string]string{sl.TenantIdTagName: "team-a"})
512-
assertSpanExist(t, spans, "mockTenantQuerier.select", map[string]string{sl.TenantIdTagName: "team-b"})
510+
assertSpanExist(t, spans, "mergeQuerier.select", map[string]string{sl.TenantIDTagName: "team-a|team-b"})
511+
assertSpanExist(t, spans, "mockTenantQuerier.select", map[string]string{sl.TenantIDTagName: "team-a"})
512+
assertSpanExist(t, spans, "mockTenantQuerier.select", map[string]string{sl.TenantIDTagName: "team-b"})
513513
}
514514

515515
func assertSpanExist(t *testing.T,

pkg/util/spanlogger/spanlogger.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
opentracing "github.com/opentracing/opentracing-go"
99
"github.com/opentracing/opentracing-go/ext"
1010
otlog "github.com/opentracing/opentracing-go/log"
11-
"github.com/weaveworks/common/user"
1211

12+
"github.com/cortexproject/cortex/pkg/tenant"
1313
util_log "github.com/cortexproject/cortex/pkg/util/log"
1414
)
1515

1616
type loggerCtxMarker struct{}
1717

1818
const (
19-
TenantIdTagName = "tenant_id"
19+
TenantIDTagName = "tenant_id"
2020
)
2121

2222
var (
@@ -39,8 +39,8 @@ func New(ctx context.Context, method string, kvps ...interface{}) (*SpanLogger,
3939
// retrieved with FromContext or FromContextWithFallback.
4040
func NewWithLogger(ctx context.Context, l log.Logger, method string, kvps ...interface{}) (*SpanLogger, context.Context) {
4141
span, ctx := opentracing.StartSpanFromContext(ctx, method)
42-
if orgId, err := user.ExtractOrgID(ctx); err == nil {
43-
span.SetTag(TenantIdTagName, orgId)
42+
if ids, _ := tenant.TenantIDs(ctx); ids != nil {
43+
span.SetTag(TenantIDTagName, tenant.JoinTenantIDs(ids))
4444
}
4545
logger := &SpanLogger{
4646
Logger: log.With(util_log.WithContext(ctx, l), "method", method),

pkg/util/spanlogger/spanlogger_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ func TestSpanLogger_CustomLogger(t *testing.T) {
5050
func TestSpanCreatedWithTenantTag(t *testing.T) {
5151
mockSpan := createSpan(user.InjectOrgID(context.Background(), "team-a"))
5252

53-
require.Equal(t, "team-a", mockSpan.Tag(TenantIdTagName))
53+
require.Equal(t, "team-a", mockSpan.Tag(TenantIDTagName))
5454
}
5555

5656
func TestSpanCreatedWithoutTenantTag(t *testing.T) {
5757
mockSpan := createSpan(context.Background())
5858

59-
_, exist := mockSpan.Tags()[TenantIdTagName]
59+
_, exist := mockSpan.Tags()[TenantIDTagName]
6060
require.False(t, exist)
6161
}
6262

0 commit comments

Comments
 (0)