Tempo: Switch to sdk logger from infra logger (#78524)

Switch to sdk logger from infra logger
This commit is contained in:
Joey 2023-11-28 09:41:26 +00:00 committed by GitHub
parent d201d3f7db
commit add096ac8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -10,14 +10,13 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/tempo/pkg/tempopb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)
var logger = log.New("tsdb.tempo")
var logger = backend.NewLoggerWith("logger", "tsdb.tempo")
// This function creates a new gRPC client to connect to a streaming query service.
// It starts by parsing the URL from the data source settings and extracting the host, since that's what the gRPC connection expects.

View File

@ -11,14 +11,13 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/tsdb/tempo/kinds/dataquery"
"github.com/grafana/tempo/pkg/tempopb"
"google.golang.org/grpc/metadata"
)
func TestProcessStream_ValidInput_ReturnsNoError(t *testing.T) {
logger := log.New("tsdb.tempo.test")
logger := backend.NewLoggerWith("logger", "tsdb.tempo.test")
service := &Service{
logger: logger,
}
@ -30,7 +29,7 @@ func TestProcessStream_ValidInput_ReturnsNoError(t *testing.T) {
}
}
func TestProcessStream_InvalidInput_ReturnsError(t *testing.T) {
logger := log.New("tsdb.tempo.test")
logger := backend.NewLoggerWith("logger", "tsdb.tempo.test")
service := &Service{
logger: logger,
}
@ -44,7 +43,7 @@ func TestProcessStream_InvalidInput_ReturnsError(t *testing.T) {
}
}
func TestProcessStream_ValidInput_ReturnsExpectedOutput(t *testing.T) {
logger := log.New("tsdb.tempo.test")
logger := backend.NewLoggerWith("logger", "tsdb.tempo.test")
service := &Service{
logger: logger,
}

View File

@ -11,7 +11,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana/pkg/tsdb/tempo/kinds/dataquery"
"github.com/grafana/tempo/pkg/tempopb"
)
@ -40,7 +40,7 @@ func logEntrypoint() string {
func ProvideService(httpClientProvider *httpclient.Provider) *Service {
return &Service{
logger: log.New("tsdb.tempo"),
logger: backend.NewLoggerWith("logger", "tsdb.tempo"),
im: datasource.NewInstanceManager(newInstanceSettings(httpClientProvider)),
}
}
@ -53,7 +53,7 @@ type Datasource struct {
func newInstanceSettings(httpClientProvider *httpclient.Provider) datasource.InstanceFactoryFunc {
return func(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
ctxLogger := log.New("tsdb.tempo").FromContext(ctx)
ctxLogger := backend.NewLoggerWith("logger", "tsdb.tempo").FromContext(ctx)
opts, err := settings.HTTPClientOptions(ctx)
if err != nil {
ctxLogger.Error("Failed to get HTTP client options", "error", err, "function", logEntrypoint())

View File

@ -4,21 +4,21 @@ import (
"context"
"testing"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTempo(t *testing.T) {
t.Run("createRequest without time range - success", func(t *testing.T) {
service := &Service{logger: log.New("tempo-test")}
service := &Service{logger: backend.NewLoggerWith("logger", "tempo-test")}
req, err := service.createRequest(context.Background(), &Datasource{}, "traceID", 0, 0)
require.NoError(t, err)
assert.Equal(t, 1, len(req.Header))
})
t.Run("createRequest with time range - success", func(t *testing.T) {
service := &Service{logger: log.New("tempo-test")}
service := &Service{logger: backend.NewLoggerWith("logger", "tempo-test")}
req, err := service.createRequest(context.Background(), &Datasource{}, "traceID", 1, 2)
require.NoError(t, err)
assert.Equal(t, 1, len(req.Header))