Plugins: Refactor plugin config into separate env var and request scoped services (#83261)
* seperate services for env + req * merge with main * fix tests * undo changes to golden file * fix linter * remove unused fields * split out new config struct * provide config * undo go mod changes * more renaming * fix tests * undo bra.toml changes * update go.work.sum * undo changes * trigger * apply PR feedback
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package pluginconfig
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewTracingCfg(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
cfg := setting.NewCfg()
|
||||
|
||||
tracingCfg, err := newTracingCfg(cfg)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, tracingCfg.IsEnabled(), "tracing should be disabled")
|
||||
assert.Empty(t, tracingCfg.OpenTelemetry.Address)
|
||||
assert.Empty(t, tracingCfg.OpenTelemetry.Propagation)
|
||||
})
|
||||
|
||||
t.Run("enabled", func(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
propagation string
|
||||
}{
|
||||
{"empty", ""},
|
||||
{"jaeger", "jaeger"},
|
||||
{"w3c", "w3c"},
|
||||
{"multiple", "jaeger,w3c"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
const address = "127.0.0.1:4317"
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
otlpSect := cfg.Raw.Section("tracing.opentelemetry.otlp")
|
||||
otlpSect.Key("address").SetValue(address)
|
||||
if tc.propagation != "" {
|
||||
otlpSect.Key("propagation").SetValue(tc.propagation)
|
||||
}
|
||||
|
||||
tracingCfg, err := newTracingCfg(cfg)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, tracingCfg.IsEnabled(), "tracing should be enabled")
|
||||
assert.Equal(t, address, tracingCfg.OpenTelemetry.Address)
|
||||
assert.Equal(t, tc.propagation, tracingCfg.OpenTelemetry.Propagation)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user