-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Merge hardcoded/default configuration with OTEL config file #2211
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
Merged
pavolloffay
merged 13 commits into
jaegertracing:master
from
pavolloffay:otel-merge-config
May 4, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8da977d
Merge hardcoded/default configuration with OTEL config file
pavolloffay 0d0230e
cleanup
pavolloffay 22f38a9
Copy the func for now
pavolloffay 7e7344a
disable c* exporter
pavolloffay 472bd45
disable grpc
pavolloffay f076773
Try depends on
pavolloffay 13940e4
Use OTEL with wait for ready
pavolloffay ae5bbe4
cleanup
pavolloffay 5c7e93d
Bump otel version that has all fixes
pavolloffay f1f1a4a
Bump OTEL version and remove disabled flag
pavolloffay f839761
change import
pavolloffay 2d75d93
Always override arrays
pavolloffay f774bf4
Remove comment
pavolloffay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) 2020 The Jaeger Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package defaults | ||
|
|
||
| import ( | ||
| "github.com/imdario/mergo" | ||
| "github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
| ) | ||
|
|
||
| // MergeConfigs merges two configs. | ||
| // The src is merged into dst. | ||
| func MergeConfigs(dst, src *configmodels.Config) error { | ||
| if src == nil { | ||
| return nil | ||
| } | ||
| err := mergo.Merge(dst, src, | ||
| mergo.WithOverride) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| // Copyright (c) 2020 The Jaeger Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package defaults | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/open-telemetry/opentelemetry-collector/config" | ||
| "github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
| "github.com/open-telemetry/opentelemetry-collector/processor/attributesprocessor" | ||
| "github.com/open-telemetry/opentelemetry-collector/processor/batchprocessor" | ||
| "github.com/open-telemetry/opentelemetry-collector/receiver" | ||
| "github.com/open-telemetry/opentelemetry-collector/receiver/jaegerreceiver" | ||
| "github.com/open-telemetry/opentelemetry-collector/receiver/zipkinreceiver" | ||
| "github.com/spf13/viper" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/elasticsearch" | ||
| jConfig "github.com/jaegertracing/jaeger/pkg/config" | ||
| ) | ||
|
|
||
| func TestMergeConfigs_nil(t *testing.T) { | ||
| cfg := &configmodels.Config{ | ||
| Receivers: configmodels.Receivers{ | ||
| "jaeger": &jaegerreceiver.Config{ | ||
| RemoteSampling: &jaegerreceiver.RemoteSamplingConfig{StrategyFile: "file.json"}, | ||
| }, | ||
| }, | ||
| } | ||
| err := MergeConfigs(cfg, nil) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, cfg, cfg) | ||
| } | ||
|
|
||
| func TestMergeConfigs(t *testing.T) { | ||
| cfg := &configmodels.Config{ | ||
| Receivers: configmodels.Receivers{ | ||
| "jaeger": &jaegerreceiver.Config{ | ||
| Protocols: map[string]*receiver.SecureReceiverSettings{ | ||
| "grpc": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "def"}}, | ||
| "thrift_compact": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "def"}}, | ||
| }, | ||
| }, | ||
| }, | ||
| Processors: configmodels.Processors{ | ||
| "batch": &batchprocessor.Config{ | ||
| SendBatchSize: uint32(160), | ||
| }, | ||
| }, | ||
| Service: configmodels.Service{ | ||
| Extensions: []string{"def", "def2"}, | ||
| Pipelines: configmodels.Pipelines{ | ||
| "traces": &configmodels.Pipeline{ | ||
| Receivers: []string{"jaeger"}, | ||
| Processors: []string{"batch"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| overrideCfg := &configmodels.Config{ | ||
| Receivers: configmodels.Receivers{ | ||
| "jaeger": &jaegerreceiver.Config{ | ||
| Protocols: map[string]*receiver.SecureReceiverSettings{ | ||
| "grpc": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "master_jaeger_url"}}, | ||
| }, | ||
| }, | ||
| "zipkin": &zipkinreceiver.Config{ | ||
| ReceiverSettings: configmodels.ReceiverSettings{ | ||
| Endpoint: "master_zipkin_url", | ||
| }, | ||
| }, | ||
| }, | ||
| Processors: configmodels.Processors{ | ||
| "attributes": &attributesprocessor.Config{ | ||
| Actions: []attributesprocessor.ActionKeyValue{{Key: "foo"}}, | ||
| }, | ||
| }, | ||
| Service: configmodels.Service{ | ||
| Extensions: []string{"def", "master1", "master2"}, | ||
| Pipelines: configmodels.Pipelines{ | ||
| "traces": &configmodels.Pipeline{ | ||
| Receivers: []string{"jaeger", "zipkin"}, | ||
| Processors: []string{"attributes"}, | ||
| }, | ||
| "traces/2": &configmodels.Pipeline{ | ||
| Processors: []string{"example"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| expected := &configmodels.Config{ | ||
| Receivers: configmodels.Receivers{ | ||
| "jaeger": &jaegerreceiver.Config{ | ||
| Protocols: map[string]*receiver.SecureReceiverSettings{ | ||
| "grpc": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "master_jaeger_url"}}, | ||
| "thrift_compact": {ReceiverSettings: configmodels.ReceiverSettings{Endpoint: "def"}}, | ||
| }, | ||
| }, | ||
| "zipkin": &zipkinreceiver.Config{ | ||
| ReceiverSettings: configmodels.ReceiverSettings{ | ||
| Endpoint: "master_zipkin_url", | ||
| }, | ||
| }, | ||
| }, | ||
| Processors: configmodels.Processors{ | ||
| "batch": &batchprocessor.Config{ | ||
| SendBatchSize: uint32(160), | ||
| }, | ||
| "attributes": &attributesprocessor.Config{ | ||
| Actions: []attributesprocessor.ActionKeyValue{{Key: "foo"}}, | ||
| }, | ||
| }, | ||
| Service: configmodels.Service{ | ||
| Extensions: []string{"def", "master1", "master2"}, | ||
| Pipelines: configmodels.Pipelines{ | ||
| "traces": &configmodels.Pipeline{ | ||
| Receivers: []string{"jaeger", "zipkin"}, | ||
| Processors: []string{"attributes"}, | ||
| }, | ||
| "traces/2": &configmodels.Pipeline{ | ||
| Processors: []string{"example"}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| err := MergeConfigs(cfg, overrideCfg) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expected, cfg) | ||
| } | ||
|
|
||
| func TestMergeConfigFiles(t *testing.T) { | ||
| testFiles := []string{"emptyoverride", "addprocessor", "multiplecomponents"} | ||
| v, _ := jConfig.Viperize(elasticsearch.DefaultOptions().AddFlags) | ||
| cmpts := Components(v) | ||
| for _, f := range testFiles { | ||
| t.Run(f, func(t *testing.T) { | ||
| cfg, err := loadConfig(cmpts, fmt.Sprintf("testdata/%s.yaml", f)) | ||
| require.NoError(t, err) | ||
| override, err := loadConfig(cmpts, fmt.Sprintf("testdata/%s-override.yaml", f)) | ||
| require.NoError(t, err) | ||
| merged, err := loadConfig(cmpts, fmt.Sprintf("testdata/%s-merged.yaml", f)) | ||
| require.NoError(t, err) | ||
| err = MergeConfigs(cfg, override) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, merged, cfg) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func loadConfig(factories config.Factories, file string) (*configmodels.Config, error) { | ||
| // config.Load fails to load an empty config | ||
| if file == "testdata/emptyoverride-override.yaml" { | ||
| return &configmodels.Config{}, nil | ||
| } | ||
| v := viper.New() | ||
| v.SetConfigFile(file) | ||
| err := v.ReadInConfig() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("error loading config file %q: %v", file, err) | ||
| } | ||
| return config.Load(v, factories) | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
cmd/opentelemetry-collector/app/defaults/testdata/addprocessor-merged.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| receivers: | ||
| jaeger: | ||
| protocols: | ||
| grpc: | ||
| thrift_compact: | ||
| thrift_binary: | ||
|
|
||
| processors: | ||
| queued_retry: {} | ||
| batch: | ||
| timeout: 5s | ||
|
|
||
| exporters: | ||
| jaeger_elasticsearch: | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [jaeger] | ||
| processors: [batch] | ||
| exporters: [jaeger_elasticsearch] |
24 changes: 24 additions & 0 deletions
24
cmd/opentelemetry-collector/app/defaults/testdata/addprocessor-override.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # TODO OTEL config.Load() fails if there are no receiver/exporters | ||
| # https://github.com/open-telemetry/opentelemetry-collector/issues/888 | ||
| receivers: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't the receivers and exporters be removed now?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not now. There is a comment in this file explaining why. |
||
| jaeger: | ||
| protocols: | ||
| grpc: | ||
| exporters: | ||
| jaeger_elasticsearch: | ||
| # TODO These two properties have to be overridden here if they were overridden in addprocessor.yaml | ||
| # If we do not override them here the default values from viper will override the values from "default/src" config. | ||
| # However in reality the default config is created from viper, hence when OTEL configuration is created it | ||
| # uses viper to create default values and then it sets the values from config. | ||
| # The viper is not used in tests hence we have to override it here. | ||
| #num_shards: 1 | ||
| #num_replicas: 0 | ||
|
|
||
| processors: | ||
| batch: | ||
| timeout: 5s | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| processors: [batch] | ||
19 changes: 19 additions & 0 deletions
19
cmd/opentelemetry-collector/app/defaults/testdata/addprocessor.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| receivers: | ||
| jaeger: | ||
| protocols: | ||
| grpc: | ||
| thrift_compact: | ||
| thrift_binary: | ||
|
|
||
| processors: | ||
| queued_retry: {} | ||
|
|
||
| exporters: | ||
| jaeger_elasticsearch: | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [jaeger] | ||
| processors: [queued_retry] | ||
| exporters: [jaeger_elasticsearch] |
22 changes: 22 additions & 0 deletions
22
cmd/opentelemetry-collector/app/defaults/testdata/emptyoverride-merged.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| receivers: | ||
| jaeger: | ||
| protocols: | ||
| grpc: | ||
| thrift_compact: | ||
| thrift_binary: | ||
|
|
||
| processors: | ||
| queued_retry: {} | ||
|
|
||
| exporters: | ||
| jaeger_elasticsearch: | ||
| server_urls: http://localhost:9200 | ||
| num_shards: 1 | ||
| num_replicas: 0 | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [jaeger] | ||
| processors: [queued_retry] | ||
| exporters: [jaeger_elasticsearch] |
22 changes: 22 additions & 0 deletions
22
cmd/opentelemetry-collector/app/defaults/testdata/emptyoverride.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| receivers: | ||
| jaeger: | ||
| protocols: | ||
| grpc: | ||
| thrift_compact: | ||
| thrift_binary: | ||
|
|
||
| processors: | ||
| queued_retry: {} | ||
|
|
||
| exporters: | ||
| jaeger_elasticsearch: | ||
| server_urls: http://localhost:9200 | ||
| num_shards: 1 | ||
| num_replicas: 0 | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [jaeger] | ||
| processors: [queued_retry] | ||
| exporters: [jaeger_elasticsearch] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.