mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 10:22:10 +08:00
Loki: Fix healthcheck logger always appending endpoint
(#96531)
* Loki: Fix healthcheck logger always appending `endpoint` * add test
This commit is contained in:
@ -186,8 +186,9 @@ func (l *logWrapper) Level() sdklog.Level {
|
||||
}
|
||||
|
||||
func (l *logWrapper) With(args ...any) sdklog.Logger {
|
||||
l.logger = l.logger.New(args...)
|
||||
return l
|
||||
return &logWrapper{
|
||||
logger: l.logger.New(args...),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *logWrapper) FromContext(ctx context.Context) sdklog.Logger {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/grafana/grafana/pkg/plugins/log"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -62,3 +63,14 @@ func TestNewPlugin(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogger(t *testing.T) {
|
||||
t.Run("logger.With should create a new logger", func(t *testing.T) {
|
||||
wrapper := &logWrapper{
|
||||
logger: log.New("test"),
|
||||
}
|
||||
newLogger := wrapper.With("key", "value")
|
||||
|
||||
require.NotSame(t, newLogger.(*logWrapper).logger, wrapper.logger, "`With` should not return the same instance")
|
||||
})
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ const (
|
||||
|
||||
func (s *Service) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult,
|
||||
error) {
|
||||
logger := s.logger.With("endpoint", "CheckHealth")
|
||||
logger := s.logger.With("endpoint", "checkHealth")
|
||||
ds, err := s.im.Get(ctx, req.PluginContext)
|
||||
// check that the datasource exists
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user