Skip to content

Commit

Permalink
DRAFT: update deps to 0.42.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Fitzpatrick committed Jan 10, 2022
1 parent a480fd6 commit 496899d
Show file tree
Hide file tree
Showing 21 changed files with 549 additions and 579 deletions.
34 changes: 22 additions & 12 deletions cmd/otelcol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package main

import (
"bytes"
"flag"
"fmt"
"io"
Expand All @@ -29,6 +28,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configunmarshaler"
"go.opentelemetry.io/collector/service"
"go.uber.org/zap"

Expand Down Expand Up @@ -82,31 +82,38 @@ func main() {
Version: version.Version,
}

parserProvider := configprovider.NewConfigSourceParserProvider(
newBaseParserProvider(),
configMapProviderFromConfigSources := configprovider.NewConfigSourceConfigMapProvider(
baseConfigMapProviders(),
zap.NewNop(), // The service logger is not available yet, setting it to NoP.
info,
configsources.Get()...,
)

var configMapConverters []service.ConfigMapConverterFunc

const noConvertConfigFlag = "--no-convert-config"
if hasFlag(noConvertConfigFlag) {
// the collector complains about this flag if we don't remove it
removeFlag(&os.Args, noConvertConfigFlag)
} else {
parserProvider = configconverter.ParserProvider(
parserProvider,
configMapConverters = append(configMapConverters,
configconverter.RemoveBallastKey,
configconverter.MoveOTLPInsecureKey,
configconverter.MoveHecTLS,
configconverter.RenameK8sTagger,
)
}

serviceConfigProvider := service.NewConfigProvider(
[]configmapprovider.Provider{configMapProviderFromConfigSources},
configMapConverters,
configunmarshaler.NewDefault(),
)

serviceParams := service.CollectorSettings{
BuildInfo: info,
Factories: factories,
ConfigMapProvider: parserProvider,
BuildInfo: info,
Factories: factories,
ConfigProvider: serviceConfigProvider,
}

if err := run(serviceParams); err != nil {
Expand Down Expand Up @@ -370,8 +377,8 @@ func setDefaultEnvVars() {
}
}

// Returns a ParserProvider that reads configuration YAML from an environment variable when applicable.
func newBaseParserProvider() configmapprovider.Provider {
// Returns a []configmapprovider.Provider for reading from yaml env var or config path and set properties
func baseConfigMapProviders() []configmapprovider.Provider {
var configPath string
var ok bool
if ok, configPath = getKeyValue(os.Args[1:], "--config"); !ok {
Expand All @@ -380,10 +387,13 @@ func newBaseParserProvider() configmapprovider.Provider {
configYaml := os.Getenv(configYamlEnvVarName)

if configPath == "" && configYaml != "" {
return configmapprovider.NewExpand(configmapprovider.NewInMemory(bytes.NewBufferString(configYaml)))
return []configmapprovider.Provider{configmapprovider.NewEnv(configYamlEnvVarName)}
}

return configmapprovider.NewDefault(configPath, getSetProperties())
return []configmapprovider.Provider{
configmapprovider.NewFile(configPath),
configmapprovider.NewProperties(getSetProperties()),
}
}

func runInteractive(settings service.CollectorSettings) error {
Expand Down
224 changes: 113 additions & 111 deletions go.mod

Large diffs are not rendered by default.

457 changes: 255 additions & 202 deletions go.sum

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions internal/configconverter/k8s_tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import (
)

// RenameK8sTagger will replace k8s_tagger processor items with k8sattributes ones.
func RenameK8sTagger(in *config.Map) *config.Map {
func RenameK8sTagger(in *config.Map) error {
if in == nil {
return fmt.Errorf("cannot RenameK8sTagger on nil *config.Map")
}

tagger := "k8s_tagger(/\\w+:{0,2})?"
taggerRe, _ := regexp.Compile(tagger)
keyExpr := fmt.Sprintf("processors::%s(.+)?", tagger)
Expand Down Expand Up @@ -64,5 +68,6 @@ func RenameK8sTagger(in *config.Map) *config.Map {
out.Set(k, v)
}
}
return out
*in = *out
return nil
}
16 changes: 6 additions & 10 deletions internal/configconverter/k8s_tagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,21 @@
package configconverter

import (
"context"
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configtest"
)

func TestRenameK8sTaggerTestRenameK8sTagger(t *testing.T) {
pp := &converterProvider{
wrapped: configmapprovider.NewFile("testdata/k8s-tagger.yaml"),
cfgMapFuncs: []CfgMapFunc{RenameK8sTagger},
}
expected, err := configtest.LoadConfigMap("testdata/k8sattributes.yaml")
actual, err := configtest.LoadConfigMap("testdata/k8s-tagger.yaml")
require.NoError(t, err)
require.NotNil(t, actual)

r, err := pp.Retrieve(context.Background(), nil)
require.NoError(t, err)
actual, err := r.Get(context.Background())
expected, err := configtest.LoadConfigMap("testdata/k8sattributes.yaml")
require.NoError(t, err)

RenameK8sTagger(actual)

require.Equal(t, expected.ToStringMap(), actual.ToStringMap())
}
10 changes: 8 additions & 2 deletions internal/configconverter/move_hec_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import (
"go.opentelemetry.io/collector/config"
)

func MoveHecTLS(in *config.Map) *config.Map {
func MoveHecTLS(in *config.Map) error {
if in == nil {
return fmt.Errorf("cannot MoveHecTLS on nil *config.Map")
}

const expression = "exporters::splunk_hec(/\\w+)?::(insecure_skip_verify|ca_file|cert_file|key_file)"
re, _ := regexp.Compile(expression)
out := config.NewMap()
Expand All @@ -46,5 +50,7 @@ func MoveHecTLS(in *config.Map) *config.Map {
"https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/5433",
)
}
return out

*in = *out
return nil
}
14 changes: 5 additions & 9 deletions internal/configconverter/move_hec_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,20 @@
package configconverter

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configtest"
)

func TestMoveHecTLS(t *testing.T) {
cp := &converterProvider{
wrapped: configmapprovider.NewFile("testdata/hec-tls.yaml"),
cfgMapFuncs: []CfgMapFunc{MoveHecTLS},
}
r, err := cp.Retrieve(context.Background(), nil)
cfgMap, err := configtest.LoadConfigMap("testdata/hec-tls.yaml")
require.NoError(t, err)
require.NotNil(t, cfgMap)

MoveHecTLS(cfgMap)

cfgMap, err := r.Get(context.Background())
require.NoError(t, err)
assert.False(t, cfgMap.IsSet("exporters::splunk_hec::ca_file"))
assert.True(t, true, cfgMap.Get("exporters::splunk_hec::tls::insecure_skip_verify"))
assert.Equal(t, "my-ca-file-1", cfgMap.Get("exporters::splunk_hec::tls::ca_file"))
Expand Down
10 changes: 8 additions & 2 deletions internal/configconverter/move_otlp_insecure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import (
"go.opentelemetry.io/collector/config"
)

func MoveOTLPInsecureKey(in *config.Map) *config.Map {
func MoveOTLPInsecureKey(in *config.Map) error {
if in == nil {
return fmt.Errorf("cannot MoveOTLPInsecureKey on nil *config.Map")
}

const expr = "exporters::otlp(/\\w+)?::insecure"
insecureRE, _ := regexp.Compile(expr)
out := config.NewMap()
Expand All @@ -44,5 +48,7 @@ func MoveOTLPInsecureKey(in *config.Map) *config.Map {
"deprecated. Please update the config according to the guideline: " +
"https://github.com/signalfx/splunk-otel-collector#from-0350-to-0360.")
}
return out

*in = *out
return nil
}
48 changes: 16 additions & 32 deletions internal/configconverter/move_otlp_insecure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,32 @@
package configconverter

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configmapprovider"
"go.opentelemetry.io/collector/config/configtest"
)

func TestConverterProvider_Noop(t *testing.T) {
pp := &converterProvider{
wrapped: configmapprovider.NewFile("testdata/otlp-insecure.yaml"),
}
r, err := pp.Retrieve(context.Background(), nil)
require.NoError(t, err)
v, err := r.Get(context.Background())
require.NoError(t, err)
assert.True(t, v.IsSet("exporters::otlp::insecure"))
}

func TestMoveOTLPInsecureKey(t *testing.T) {
pp := &converterProvider{
wrapped: configmapprovider.NewFile("testdata/otlp-insecure.yaml"),
cfgMapFuncs: []CfgMapFunc{MoveOTLPInsecureKey},
}
r, err := pp.Retrieve(context.Background(), nil)
require.NoError(t, err)
v, err := r.Get(context.Background())
cfgMap, err := configtest.LoadConfigMap("testdata/otlp-insecure.yaml")
require.NoError(t, err)
assert.False(t, v.IsSet("exporters::otlp::insecure"))
assert.Equal(t, true, v.Get("exporters::otlp::tls::insecure"))
require.NotNil(t, cfgMap)

MoveOTLPInsecureKey(cfgMap)

assert.False(t, cfgMap.IsSet("exporters::otlp::insecure"))
assert.Equal(t, true, cfgMap.Get("exporters::otlp::tls::insecure"))
}

func TestMoveOTLPInsecureKey_Custom(t *testing.T) {
pp := &converterProvider{
wrapped: configmapprovider.NewFile("testdata/otlp-insecure-custom.yaml"),
cfgMapFuncs: []CfgMapFunc{MoveOTLPInsecureKey},
}
r, err := pp.Retrieve(context.Background(), nil)
require.NoError(t, err)
v, err := r.Get(context.Background())
cfgMap, err := configtest.LoadConfigMap("testdata/otlp-insecure-custom.yaml")
require.NoError(t, err)
assert.False(t, v.IsSet("exporters::otlp/foo::insecure"))
assert.Equal(t, true, v.Get("exporters::otlp/foo::tls::insecure"))
assert.Equal(t, true, v.Get("exporters::otlp/foo::tls::insecure_skip_verify"))
require.NotNil(t, cfgMap)

MoveOTLPInsecureKey(cfgMap)

assert.False(t, cfgMap.IsSet("exporters::otlp/foo::insecure"))
assert.Equal(t, true, cfgMap.Get("exporters::otlp/foo::tls::insecure"))
assert.Equal(t, true, cfgMap.Get("exporters::otlp/foo::tls::insecure_skip_verify"))
}
74 changes: 0 additions & 74 deletions internal/configconverter/parser_provider.go

This file was deleted.

Loading

0 comments on commit 496899d

Please sign in to comment.