Blame SOURCES/002-remove-jaeger-tracing.patch

50fcc5
diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go
6b5415
index 0dace4ebab..f1a4bfde53 100644
50fcc5
--- a/pkg/cmd/grafana-server/server.go
50fcc5
+++ b/pkg/cmd/grafana-server/server.go
0d3998
@@ -23,7 +23,6 @@ import (
50fcc5
 	_ "github.com/grafana/grafana/pkg/infra/metrics"
50fcc5
 	_ "github.com/grafana/grafana/pkg/infra/remotecache"
50fcc5
 	_ "github.com/grafana/grafana/pkg/infra/serverlock"
50fcc5
-	_ "github.com/grafana/grafana/pkg/infra/tracing"
50fcc5
 	_ "github.com/grafana/grafana/pkg/infra/usagestats"
50fcc5
 	"github.com/grafana/grafana/pkg/login"
0d3998
 	"github.com/grafana/grafana/pkg/login/social"
50fcc5
diff --git a/pkg/infra/tracing/tracing.go b/pkg/infra/tracing/tracing.go
50fcc5
deleted file mode 100644
6b5415
index 923459786b..0000000000
50fcc5
--- a/pkg/infra/tracing/tracing.go
50fcc5
+++ /dev/null
6b5415
@@ -1,161 +0,0 @@
50fcc5
-package tracing
50fcc5
-
50fcc5
-import (
50fcc5
-	"context"
0d3998
-	"fmt"
50fcc5
-	"io"
50fcc5
-	"strings"
50fcc5
-
0d3998
-	"github.com/grafana/grafana/pkg/infra/log"
50fcc5
-	"github.com/grafana/grafana/pkg/registry"
50fcc5
-	"github.com/grafana/grafana/pkg/setting"
50fcc5
-
50fcc5
-	opentracing "github.com/opentracing/opentracing-go"
50fcc5
-	jaegercfg "github.com/uber/jaeger-client-go/config"
0d3998
-	"github.com/uber/jaeger-client-go/zipkin"
50fcc5
-)
50fcc5
-
50fcc5
-func init() {
50fcc5
-	registry.RegisterService(&TracingService{})
50fcc5
-}
50fcc5
-
50fcc5
-type TracingService struct {
0d3998
-	enabled                  bool
0d3998
-	address                  string
0d3998
-	customTags               map[string]string
0d3998
-	samplerType              string
0d3998
-	samplerParam             float64
0d3998
-	log                      log.Logger
0d3998
-	closer                   io.Closer
0d3998
-	zipkinPropagation        bool
0d3998
-	disableSharedZipkinSpans bool
50fcc5
-
50fcc5
-	Cfg *setting.Cfg `inject:""`
50fcc5
-}
50fcc5
-
50fcc5
-func (ts *TracingService) Init() error {
50fcc5
-	ts.log = log.New("tracing")
50fcc5
-	ts.parseSettings()
50fcc5
-
50fcc5
-	if ts.enabled {
6b5415
-		return ts.initGlobalTracer()
50fcc5
-	}
50fcc5
-
50fcc5
-	return nil
50fcc5
-}
50fcc5
-
50fcc5
-func (ts *TracingService) parseSettings() {
50fcc5
-	var section, err = ts.Cfg.Raw.GetSection("tracing.jaeger")
50fcc5
-	if err != nil {
50fcc5
-		return
50fcc5
-	}
50fcc5
-
50fcc5
-	ts.address = section.Key("address").MustString("")
50fcc5
-	if ts.address != "" {
50fcc5
-		ts.enabled = true
50fcc5
-	}
50fcc5
-
50fcc5
-	ts.customTags = splitTagSettings(section.Key("always_included_tag").MustString(""))
50fcc5
-	ts.samplerType = section.Key("sampler_type").MustString("")
50fcc5
-	ts.samplerParam = section.Key("sampler_param").MustFloat64(1)
0d3998
-	ts.zipkinPropagation = section.Key("zipkin_propagation").MustBool(false)
0d3998
-	ts.disableSharedZipkinSpans = section.Key("disable_shared_zipkin_spans").MustBool(false)
50fcc5
-}
50fcc5
-
6b5415
-func (ts *TracingService) initJaegerCfg() (jaegercfg.Configuration, error) {
50fcc5
-	cfg := jaegercfg.Configuration{
50fcc5
-		ServiceName: "grafana",
50fcc5
-		Disabled:    !ts.enabled,
50fcc5
-		Sampler: &jaegercfg.SamplerConfig{
50fcc5
-			Type:  ts.samplerType,
50fcc5
-			Param: ts.samplerParam,
50fcc5
-		},
50fcc5
-		Reporter: &jaegercfg.ReporterConfig{
50fcc5
-			LogSpans:           false,
50fcc5
-			LocalAgentHostPort: ts.address,
50fcc5
-		},
50fcc5
-	}
50fcc5
-
6b5415
-	_, err := cfg.FromEnv()
6b5415
-	if err != nil {
6b5415
-		return cfg, err
6b5415
-	}
6b5415
-	return cfg, nil
6b5415
-}
6b5415
-
6b5415
-func (ts *TracingService) initGlobalTracer() error {
6b5415
-	cfg, err := ts.initJaegerCfg()
6b5415
-	if err != nil {
6b5415
-		return err
6b5415
-	}
6b5415
-
50fcc5
-	jLogger := &jaegerLogWrapper{logger: log.New("jaeger")}
50fcc5
-
50fcc5
-	options := []jaegercfg.Option{}
50fcc5
-	options = append(options, jaegercfg.Logger(jLogger))
50fcc5
-
50fcc5
-	for tag, value := range ts.customTags {
50fcc5
-		options = append(options, jaegercfg.Tag(tag, value))
50fcc5
-	}
50fcc5
-
0d3998
-	if ts.zipkinPropagation {
0d3998
-		zipkinPropagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
0d3998
-		options = append(options,
0d3998
-			jaegercfg.Injector(opentracing.HTTPHeaders, zipkinPropagator),
0d3998
-			jaegercfg.Extractor(opentracing.HTTPHeaders, zipkinPropagator),
0d3998
-		)
0d3998
-
0d3998
-		if !ts.disableSharedZipkinSpans {
0d3998
-			options = append(options, jaegercfg.ZipkinSharedRPCSpan(true))
0d3998
-		}
0d3998
-	}
0d3998
-
50fcc5
-	tracer, closer, err := cfg.NewTracer(options...)
50fcc5
-	if err != nil {
50fcc5
-		return err
50fcc5
-	}
50fcc5
-
6b5415
-	opentracing.SetGlobalTracer(tracer)
50fcc5
-
50fcc5
-	ts.closer = closer
50fcc5
-
50fcc5
-	return nil
50fcc5
-}
50fcc5
-
50fcc5
-func (ts *TracingService) Run(ctx context.Context) error {
50fcc5
-	<-ctx.Done()
50fcc5
-
50fcc5
-	if ts.closer != nil {
50fcc5
-		ts.log.Info("Closing tracing")
50fcc5
-		ts.closer.Close()
50fcc5
-	}
50fcc5
-
50fcc5
-	return nil
50fcc5
-}
50fcc5
-
50fcc5
-func splitTagSettings(input string) map[string]string {
50fcc5
-	res := map[string]string{}
50fcc5
-
50fcc5
-	tags := strings.Split(input, ",")
50fcc5
-	for _, v := range tags {
50fcc5
-		kv := strings.Split(v, ":")
50fcc5
-		if len(kv) > 1 {
50fcc5
-			res[kv[0]] = kv[1]
50fcc5
-		}
50fcc5
-	}
50fcc5
-
50fcc5
-	return res
50fcc5
-}
50fcc5
-
50fcc5
-type jaegerLogWrapper struct {
50fcc5
-	logger log.Logger
50fcc5
-}
50fcc5
-
50fcc5
-func (jlw *jaegerLogWrapper) Error(msg string) {
50fcc5
-	jlw.logger.Error(msg)
50fcc5
-}
50fcc5
-
0d3998
-func (jlw *jaegerLogWrapper) Infof(format string, args ...interface{}) {
0d3998
-	msg := fmt.Sprintf(format, args...)
0d3998
-	jlw.logger.Info(msg)
50fcc5
-}
50fcc5
diff --git a/pkg/infra/tracing/tracing_test.go b/pkg/infra/tracing/tracing_test.go
50fcc5
deleted file mode 100644
6b5415
index a6d71cf165..0000000000
50fcc5
--- a/pkg/infra/tracing/tracing_test.go
50fcc5
+++ /dev/null
6b5415
@@ -1,94 +0,0 @@
50fcc5
-package tracing
50fcc5
-
6b5415
-import (
6b5415
-	"github.com/stretchr/testify/assert"
6b5415
-	"github.com/stretchr/testify/require"
6b5415
-	"os"
6b5415
-	"testing"
6b5415
-)
50fcc5
-
50fcc5
-func TestGroupSplit(t *testing.T) {
50fcc5
-	tests := []struct {
50fcc5
-		input    string
50fcc5
-		expected map[string]string
50fcc5
-	}{
50fcc5
-		{
50fcc5
-			input: "tag1:value1,tag2:value2",
50fcc5
-			expected: map[string]string{
50fcc5
-				"tag1": "value1",
50fcc5
-				"tag2": "value2",
50fcc5
-			},
50fcc5
-		},
50fcc5
-		{
50fcc5
-			input:    "",
50fcc5
-			expected: map[string]string{},
50fcc5
-		},
50fcc5
-		{
50fcc5
-			input:    "tag1",
50fcc5
-			expected: map[string]string{},
50fcc5
-		},
50fcc5
-	}
50fcc5
-
50fcc5
-	for _, test := range tests {
50fcc5
-		tags := splitTagSettings(test.input)
50fcc5
-		for k, v := range test.expected {
50fcc5
-			value, exists := tags[k]
6b5415
-			assert.Truef(t, exists, "Tag %q not found for input %q", k, test.input)
6b5415
-			assert.Equalf(t, v, value, "Tag %q has wrong value for input %q", k, test.input)
50fcc5
-		}
50fcc5
-	}
50fcc5
-}
6b5415
-
6b5415
-func TestInitJaegerCfg_Default(t *testing.T) {
6b5415
-	ts := &TracingService{}
6b5415
-	cfg, err := ts.initJaegerCfg()
6b5415
-	require.NoError(t, err)
6b5415
-
6b5415
-	assert.True(t, cfg.Disabled)
6b5415
-}
6b5415
-
6b5415
-func TestInitJaegerCfg_Enabled(t *testing.T) {
6b5415
-	ts := &TracingService{enabled: true}
6b5415
-	cfg, err := ts.initJaegerCfg()
6b5415
-	require.NoError(t, err)
6b5415
-
6b5415
-	assert.False(t, cfg.Disabled)
6b5415
-	assert.Equal(t, "localhost:6831", cfg.Reporter.LocalAgentHostPort)
6b5415
-}
6b5415
-
6b5415
-func TestInitJaegerCfg_DisabledViaEnv(t *testing.T) {
6b5415
-	os.Setenv("JAEGER_DISABLED", "true")
6b5415
-	defer func() {
6b5415
-		os.Unsetenv("JAEGER_DISABLED")
6b5415
-	}()
6b5415
-
6b5415
-	ts := &TracingService{enabled: true}
6b5415
-	cfg, err := ts.initJaegerCfg()
6b5415
-	require.NoError(t, err)
6b5415
-
6b5415
-	assert.True(t, cfg.Disabled)
6b5415
-}
6b5415
-
6b5415
-func TestInitJaegerCfg_EnabledViaEnv(t *testing.T) {
6b5415
-	os.Setenv("JAEGER_DISABLED", "false")
6b5415
-	defer func() {
6b5415
-		os.Unsetenv("JAEGER_DISABLED")
6b5415
-	}()
6b5415
-
6b5415
-	ts := &TracingService{enabled: false}
6b5415
-	cfg, err := ts.initJaegerCfg()
6b5415
-	require.NoError(t, err)
6b5415
-
6b5415
-	assert.False(t, cfg.Disabled)
6b5415
-}
6b5415
-
6b5415
-func TestInitJaegerCfg_InvalidEnvVar(t *testing.T) {
6b5415
-	os.Setenv("JAEGER_DISABLED", "totallybogus")
6b5415
-	defer func() {
6b5415
-		os.Unsetenv("JAEGER_DISABLED")
6b5415
-	}()
6b5415
-
6b5415
-	ts := &TracingService{}
6b5415
-	_, err := ts.initJaegerCfg()
6b5415
-	require.EqualError(t, err, "cannot parse env var JAEGER_DISABLED=totallybogus: strconv.ParseBool: parsing \"totallybogus\": invalid syntax")
6b5415
-}