* Tracing: Pass OTLP address and propagation format to plugins * Fix unit tests * Fix indentation * Fix plugin manager integration tests * Goimports * Pass plugin version to plugins * Do not add GF_PLUGIN_VERSION if plugin version is not set, add tests * Allow disabling plugins distributed tracing on a per-plugin basis * Moved disabled plugins to tracing.opentelemetry config section * Pre-allocate DisabledPlugins map to the correct size * Moved disable tracing setting flags in plugin settings * Renamed plugin env vars for tracing endpoint and propagation * Fix plugin initializer tests * Refactoring: Moved OpentelemetryCfg from pkg/infra to pkg/plugins * Changed GetSection to Section in parseSettingsOpentelemetry * Add tests for NewOpentelemetryCfg * Fix test case names in TestNewOpentelemetryCfg * OpenTelemetry: Remove redundant error checks
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNewOpentelemetryCfg(t *testing.T) {
|
|
t.Run("empty", func(t *testing.T) {
|
|
cfg := setting.NewCfg()
|
|
|
|
otelCfg, err := NewOpentelemetryCfg(cfg)
|
|
require.NoError(t, err)
|
|
assert.False(t, otelCfg.IsEnabled(), "otel should be disabled")
|
|
assert.Empty(t, otelCfg.Address)
|
|
assert.Empty(t, otelCfg.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)
|
|
}
|
|
|
|
otelCfg, err := NewOpentelemetryCfg(cfg)
|
|
require.NoError(t, err)
|
|
assert.True(t, otelCfg.IsEnabled(), "otel should be enabled")
|
|
assert.Equal(t, address, otelCfg.Address)
|
|
assert.Equal(t, tc.propagation, otelCfg.Propagation)
|
|
})
|
|
}
|
|
})
|
|
}
|