Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation): update traces migration #405

Merged
merged 11 commits into from
Dec 23, 2022
10 changes: 10 additions & 0 deletions src/go/cmd/update-collection-v3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
removeloadconfigfile "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/remove-load-config-file"
tailingsidecaroperatorupgrade "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tailing-sidecar-operator-upgrade"
tracingreplaces "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tracing-replaces"
tracingconfig "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tracing-config"
tracingobjectchanges "github.com/SumoLogic/sumologic-kubernetes-collection/tools/cmd/update-collection-v3/migrations/tracing-objects-changes"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -121,6 +123,14 @@ var migrations = []Migration{
directory: "fluentd-logs-configs",
action: fluentdlogsconfigs.Migrate,
},
{
directory: "tracing-objects-changes",
action: tracingobjectchanges.Migrate,
},
{
directory: "tracing-config",
action: tracingconfig.Migrate,
},
}

func migrateYaml(input string) (string, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package tracingconfig

import (
"bytes"
"fmt"

"gopkg.in/yaml.v3"
)

func Migrate(input string) (string, error) {
inputValues, err := parseValues(input)
if err != nil {
return "", fmt.Errorf("error parsing input yaml: %v", err)
}

if &inputValues.Otelcol != nil {
outputValues, err := migrate(&inputValues)
if err != nil {
return "", fmt.Errorf("error migrating: %v", err)
}

buffer := bytes.Buffer{}
encoder := yaml.NewEncoder(&buffer)
encoder.SetIndent(2)
err = encoder.Encode(outputValues)
fmt.Sprintln(buffer.String())
fmt.Println("WARNING! Tracing config migrated to v3, please check the output file. For more details see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md#tracinginstrumentation-changes")
return buffer.String(), err
}

return input, err
}

func parseValues(input string) (ValuesInput, error) {
var outputValues ValuesInput
err := yaml.Unmarshal([]byte(input), &outputValues)
return outputValues, err
}

func migrate(inputValues *ValuesInput) (ValuesOutput, error) {
outputValues := ValuesOutput{
Rest: inputValues.Rest,
}
// migrate otelcol source processor to otelcol-instrumentation
outputValues.OtelcolInstrumentation.Config.Processors.Source = inputValues.Otelcol.Config.Processors.Source
// migrate otelcol cascading_filter processor to tracesSampler
outputValues.TracesSampler.Config.Processors.CascadingFilter = inputValues.Otelcol.Config.Processors.CascadingFilter

return outputValues, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tracingconfig

type ValuesInput struct {
Otelcol Otelcol `yaml:"otelcol,omitempty"`
Otelagent map[string]interface{} `yaml:"otelagent,omitempty"`
Otelgateway map[string]interface{} `yaml:"otelgateway,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

type Otelcol struct {
Config struct {
Processors struct {
CascadingFilter map[string]interface{} `yaml:"cascading_filter,omitempty"`
Source map[string]interface{} `yaml:"source,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"processors,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"config,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tracingconfig

type ValuesOutput struct {
OtelcolInstrumentation OtelcolInstrumentation `yaml:"otelcolInstrumentation,omitempty"`
TracesSampler TracesSampler `yaml:"tracesSampler,omitempty"`
Otelcol map[string]interface{} `yaml:"-"`
Otelagent map[string]interface{} `yaml:"-"`
Otelgateway map[string]interface{} `yaml:"-"`
Rest map[string]interface{} `yaml:",inline"`
}

type OtelcolInstrumentation struct {
Config struct {
Processors struct {
Source map[string]interface{} `yaml:"source,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"processors,omitempty"`
} `yaml:"config,omitempty"`
}

type TracesSampler struct {
Config struct {
Processors struct {
CascadingFilter map[string]interface{} `yaml:"cascading_filter,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"processors,omitempty"`
} `yaml:"config,omitempty"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tracingobjectchanges

import (
"fmt"

"gopkg.in/yaml.v3"
)

func Migrate(input string) (string, error) {
inputValues, err := parseValues(input)
if err != nil {
return "", fmt.Errorf("error parsing input yaml: %v", err)
}

if &inputValues.Sumologic.Traces != nil {
if inputValues.Sumologic.Traces.Enabled == true {
fmt.Println("WARNING! Found enabled otelcol, for details please see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md#tracinginstrumentation-changes")
}

}

if &inputValues.Otelagent != nil {
if inputValues.Otelagent.Enabled == true {
fmt.Println("WARNING! Found enabled otelagent, for details please see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md#tracinginstrumentation-changes")
}
}

if &inputValues.Otelgateway != nil {
if inputValues.Otelgateway.Enabled == true {
fmt.Println("WARNING! Found enabled otelgateway, for details please see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md#tracinginstrumentation-changes")
}
}

return input, err
}

func parseValues(input string) (ValuesInput, error) {
var inputValues ValuesInput
err := yaml.Unmarshal([]byte(input), &inputValues)
return inputValues, err
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tracingobjectchanges

type ValuesInput struct {
Sumologic struct {
Traces struct {
Enabled bool `yaml:"enabled,omitempty"`
} `yaml:"traces,omitempty"`
} `yaml:"sumologic,omitempty"`
Otelcol map[string]interface{} `yaml:"otelcol,omitempty"`
Otelagent struct {
Enabled bool `yaml:"enabled,omitempty"`
} `yaml:"otelagent,omitempty"`
Otelgateway struct {
Enabled bool `yaml:"enabled,omitempty"`
} `yaml:"otelgateway,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"gopkg.in/yaml.v3"
)

var otelagentReplaces []string = []string{
"exporters.otlpmetrics.endpoint.replace",
"exporters.otlptraces.endpoint.replace",
}

var otelcolReplaces []string = []string{
"processors.source.collector.replace",
"processors.source.name.replace",
Expand All @@ -24,53 +19,37 @@ var otelcolReplaces []string = []string{
"processors.source.exclude_container_regex.replace",
"processors.source.exclude_host_regex.replace",
"processors.resource.cluster.replace",
"exporters.sumologic.source_name.replace",
"exporters.sumologic.source_category.replace",
}

func Migrate(yamlV2 string) (yamlV3 string, err error) {
valuesV2, err := parseValues(yamlV2)
func Migrate(input string) (string, error) {
inputValues, err := parseValues(input)
if err != nil {
return "", fmt.Errorf("error parsing input yaml: %v", err)
}

if valuesV2.Otelagent != nil {
foundOtelagentReplaces := []string{}
foundOtelagentReplaces, err = findUsedReplaces(valuesV2.Otelagent.Config, otelagentReplaces)
if err != nil {
return "", fmt.Errorf("error parsing otelcol configuration: %v", err)
}

if len(foundOtelagentReplaces) != 0 {
fmt.Println("WARNING! Found following special values in otelagent configuration which must be manually migrated:")
fmt.Println(strings.Join(foundOtelagentReplaces, "\n"))
fmt.Println("for details please see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md")
}
}

if valuesV2.Otelcol != nil {
if &inputValues.Otelcol != nil {
foundOtelcolReplaces := []string{}
foundOtelcolReplaces, err = findUsedReplaces(valuesV2.Otelcol.Config, otelcolReplaces)
foundOtelcolReplaces, err = findUsedReplaces(inputValues.Otelcol, otelcolReplaces)
if err != nil {
return "", fmt.Errorf("error parsing otelcol configuration: %v", err)
}
if len(foundOtelcolReplaces) != 0 {
fmt.Println("WARNING! Found following special values in otelcol configuration which must be manually migrated:")
fmt.Println(strings.Join(foundOtelcolReplaces, "\n"))
fmt.Println("for details please see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md")
fmt.Println("for details please see documentation: https://github.com/SumoLogic/sumologic-kubernetes-collection/blob/main/docs/v3-migration-doc.md#replace-special-configuration-values-marked-by-replace-suffix")
}
}

return yamlV2, err
return input, err
}

func parseValues(yamlV2 string) (ValuesV2, error) {
var valuesV2 ValuesV2
err := yaml.Unmarshal([]byte(yamlV2), &valuesV2)
return valuesV2, err
func parseValues(input string) (ValuesInput, error) {
var inputValues ValuesInput
err := yaml.Unmarshal([]byte(input), &inputValues)
return inputValues, err
}

func parseConfigToString(config map[string]interface{}) (string, error) {
func parseConfigToString(config Otelcol) (string, error) {
buffer := bytes.Buffer{}
encoder := yaml.NewEncoder(&buffer)
encoder.SetIndent(2)
Expand All @@ -81,8 +60,8 @@ func parseConfigToString(config map[string]interface{}) (string, error) {
return buffer.String(), err
}

func findUsedReplaces(config map[string]interface{}, replaces []string) ([]string, error) {
if config == nil {
func findUsedReplaces(config Otelcol, replaces []string) ([]string, error) {
if &config == nil {
return []string{}, nil
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tracingreplaces

type ValuesInput struct {
Otelcol Otelcol `yaml:"otelcol,omitempty"`
Otelagent map[string]interface{} `yaml:"otelagent,omitempty"`
Otelgateway map[string]interface{} `yaml:"otelgateway,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}

type Otelcol struct {
Config struct {
Processors struct {
CascadingFilter map[string]interface{} `yaml:"cascading_filter,omitempty"`
Source map[string]interface{} `yaml:"source,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"processors,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
} `yaml:"config,omitempty"`
Rest map[string]interface{} `yaml:",inline"`
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
sumologic:
traces:
enabled: true
otelagent:
enabled: true
config:
exporters:
otlphttp/metrics:
endpoint: http://exporters.otlpmetrics.endpoint.replace:4318
otlphttp/traces:
endpoint: http://exporters.otlptraces.endpoint.replace:4318
otelgateway:
enabled: true
config:
exporters:
loadbalancing:
otelcol:
config:
exporters:
sumologic:
source_category: exporters.sumologic.source_category.replace
source_name: exporters.sumologic.source_name.replace
processors:
other:
enabled: true
cascading_filter:
num_spans: 200000
source:
annotation_prefix: k8s.pod.annotation.
collector: processors.source.collector.replace
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
otelagent:
otelcolInstrumentation:
config:
exporters:
otlphttp/metrics:
endpoint: http://exporters.otlpmetrics.endpoint.replace:4318
otlphttp/traces:
endpoint: http://exporters.otlptraces.endpoint.replace:4318
otelcol:
config:
exporters:
sumologic:
source_category: exporters.sumologic.source_category.replace
source_name: exporters.sumologic.source_name.replace
processors:
source:
annotation_prefix: k8s.pod.annotation.
Expand All @@ -28,3 +17,11 @@ otelcol:
source_category_replace_dash: processors.source.category_replace_dash.replace
source_host: '%{k8s.pod.hostname}'
source_name: processors.source.name.replace
sumologic:
traces:
enabled: true
tracesSampler:
config:
processors:
cascading_filter:
num_spans: 200000