diff --git a/pkg/config/sampling/sampling.go b/pkg/config/sampling/sampling.go index ecbe6e8efb..903524f3e1 100644 --- a/pkg/config/sampling/sampling.go +++ b/pkg/config/sampling/sampling.go @@ -26,11 +26,11 @@ func NewConfig(jaeger *v1.Jaeger) *Config { } // Get returns a configmap specification for the current instance -func (u *Config) Get(options *[]string) *corev1.ConfigMap { +func (u *Config) Get() *corev1.ConfigMap { var jsonObject []byte var err error - if CheckForSamplingConfigFile(u.jaeger, options) { + if CheckForSamplingConfigFile(u.jaeger) { return nil } // Check for empty map @@ -51,8 +51,6 @@ func (u *Config) Get(options *[]string) *corev1.ConfigMap { "sampling": string(jsonObject), } - fmt.Println(data) - return &corev1.ConfigMap{ TypeMeta: metav1.TypeMeta{ APIVersion: "v1", @@ -85,13 +83,20 @@ func (u *Config) Get(options *[]string) *corev1.ConfigMap { // CheckForSamplingConfigFile will check if there is a config file present // if there is one it returns true -func CheckForSamplingConfigFile(jaeger *v1.Jaeger, options *[]string) bool { - for _, option := range *options { - if strings.Contains(option, "sampling.strategies-file") { - jaeger.Logger().Warn("Sampling strategy file is already passed as an option to collector. Will not be using default sampling strategy") - return true - } +func CheckForSamplingConfigFile(jaeger *v1.Jaeger) bool { + jsonObject, err := jaeger.Spec.Sampling.Options.MarshalJSON() + + if err != nil { + return false } + data := map[string]string{ + "sampling": string(jsonObject), + } + if strings.Contains(data["sampling"], "sampling.strategies-file") { + jaeger.Logger().Warn("Sampling strategy file is already passed as an option to collector. Will not be using default sampling strategy") + return true + } + return false } @@ -99,15 +104,7 @@ func CheckForSamplingConfigFile(jaeger *v1.Jaeger, options *[]string) bool { // support for the Sampling configmap. func Update(jaeger *v1.Jaeger, commonSpec *v1.JaegerCommonSpec, options *[]string) { - // // Check to validate if sampling strategy file is already passed as an option - // for _, option := range *options { - // if strings.Contains(option, "sampling.strategies-file") { - // jaeger.Logger().Warn("Sampling strategy file is already passed as an option to collector. Will not be using default sampling strategy") - // return - // } - // } - - if CheckForSamplingConfigFile(jaeger, options) { + if CheckForSamplingConfigFile(jaeger) { return } diff --git a/pkg/config/sampling/sampling_test.go b/pkg/config/sampling/sampling_test.go index 2ce23d0508..e06ae5cf28 100644 --- a/pkg/config/sampling/sampling_test.go +++ b/pkg/config/sampling/sampling_test.go @@ -13,8 +13,7 @@ func TestNoSamplingConfig(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestNoSamplingConfig"}) config := NewConfig(jaeger) - options := []string{} - cm := config.Get(&options) + cm := config.Get() assert.NotNil(t, cm) assert.Equal(t, defaultSamplingStrategy, cm.Data["sampling"]) } @@ -25,8 +24,8 @@ func TestWithEmptySamplingConfig(t *testing.T) { jaeger.Spec.UI.Options = uiconfig config := NewConfig(jaeger) - options := []string{} - cm := config.Get(&options) + + cm := config.Get() assert.NotNil(t, cm) assert.Equal(t, defaultSamplingStrategy, cm.Data["sampling"]) } @@ -42,8 +41,7 @@ func TestWithSamplingConfig(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestWithSamplingConfig"}) jaeger.Spec.Sampling.Options = samplingconfig config := NewConfig(jaeger) - options := []string{} - cm := config.Get(&options) + cm := config.Get() assert.Equal(t, json, cm.Data["sampling"]) } @@ -85,23 +83,24 @@ func TestUpdateWithSamplingConfig(t *testing.T) { func TestUpdateWithSamplingConfigFileOption(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestUpdateWithSamplingConfigFileOption"}) - options := []string{ - 0: "--sampling.strategies-file=/etc/jaeger/sampling.json", - } + jaeger.Spec.Sampling.Options = v1.NewFreeForm(map[string]interface{}{ + "sampling.strategies-file": "/etc/jaeger/sampling.json", + }) + options := []string{} commonSpec := v1.JaegerCommonSpec{} Update(jaeger, &commonSpec, &options) - assert.Len(t, options, 1) - assert.Equal(t, "--sampling.strategies-file=/etc/jaeger/sampling.json", options[0]) + assert.Len(t, commonSpec.Volumes, 0) + assert.Len(t, commonSpec.VolumeMounts, 0) + assert.Len(t, options, 0) } func TestGetWithSamplingConfigFileOption(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestGetWithSamplingConfigFileOption"}) - options := []string{ - 0: "--sampling.strategies-file=/etc/jaeger/sampling.json", - } + jaeger.Spec.Sampling.Options = v1.NewFreeForm(map[string]interface{}{ + "sampling.strategies-file": "/etc/jaeger/sampling.json", + }) + config := NewConfig(jaeger) - cm := config.Get(&options) - assert.Len(t, options, 1) - assert.Equal(t, "--sampling.strategies-file=/etc/jaeger/sampling.json", options[0]) + cm := config.Get() assert.Nil(t, cm) }