-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Run OTEL collector without configuration file #2148
Changes from all commits
cf19d4c
a3b42e0
225f84d
9bf07e7
bd9852a
1fd6716
7cb3c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// 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" | ||
"strings" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
"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/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/cassandra" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/elasticsearch" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/kafka" | ||
) | ||
|
||
// Config creates default configuration. | ||
// It enables default Jaeger receivers, processors and exporters. | ||
func Config(storageType string, factories config.Factories) (*configmodels.Config, error) { | ||
exporters, err := createExporters(storageType, factories) | ||
if err != nil { | ||
return nil, err | ||
} | ||
types := []string{} | ||
for _, v := range exporters { | ||
types = append(types, v.Type()) | ||
} | ||
return &configmodels.Config{ | ||
Receivers: createReceivers(factories), | ||
Exporters: exporters, | ||
Processors: createProcessors(factories), | ||
Service: configmodels.Service{ | ||
Pipelines: map[string]*configmodels.Pipeline{ | ||
"traces": { | ||
InputType: configmodels.TracesDataType, | ||
Receivers: []string{"jaeger"}, | ||
Exporters: types, | ||
Processors: []string{"batch"}, | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} | ||
|
||
func createReceivers(factories config.Factories) configmodels.Receivers { | ||
rec := factories.Receivers["jaeger"].CreateDefaultConfig().(*jaegerreceiver.Config) | ||
// TODO load and serve sampling strategies | ||
// TODO bind sampling strategies file | ||
rec.Protocols = map[string]*receiver.SecureReceiverSettings{ | ||
"grpc": { | ||
ReceiverSettings: configmodels.ReceiverSettings{ | ||
Endpoint: "localhost:14250", | ||
}, | ||
}, | ||
"thrift_http": { | ||
ReceiverSettings: configmodels.ReceiverSettings{ | ||
Endpoint: "localhost:14268", | ||
}, | ||
}, | ||
"thrift_compact": { | ||
ReceiverSettings: configmodels.ReceiverSettings{ | ||
Endpoint: "localhost:6831", | ||
}, | ||
}, | ||
"thrift_binary": { | ||
ReceiverSettings: configmodels.ReceiverSettings{ | ||
Endpoint: "localhost:6832", | ||
}, | ||
}, | ||
} | ||
return map[string]configmodels.Receiver{ | ||
"jaeger": rec, | ||
} | ||
} | ||
|
||
func createExporters(storageTypes string, factories config.Factories) (configmodels.Exporters, error) { | ||
exporters := configmodels.Exporters{} | ||
for _, s := range strings.Split(storageTypes, ",") { | ||
switch s { | ||
case "cassandra": | ||
cass := factories.Exporters[cassandra.TypeStr].CreateDefaultConfig() | ||
exporters[cassandra.TypeStr] = cass | ||
case "elasticsearch": | ||
es := factories.Exporters[elasticsearch.TypeStr].CreateDefaultConfig() | ||
exporters[elasticsearch.TypeStr] = es | ||
case "kafka": | ||
kaf := factories.Exporters[kafka.TypeStr].CreateDefaultConfig() | ||
exporters[kafka.TypeStr] = kaf | ||
default: | ||
return nil, fmt.Errorf("unknown storage type: %s", s) | ||
} | ||
} | ||
return exporters, nil | ||
} | ||
|
||
func createProcessors(factories config.Factories) configmodels.Processors { | ||
batch := factories.Processors["batch"].CreateDefaultConfig().(*batchprocessor.Config) | ||
return map[string]configmodels.Processor{ | ||
"batch": batch, | ||
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. How did we decide this list of default processors? I'd like to think 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. Good point - the other reason for using 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. I have used the batch as a starting point since there has to be at least one processor. In the production-ready settings we might run batch, retry and memory limiter. Let's handle this in a separate task.
The highest priority we had was to be a drop-in replacement for the current collector. The OTEL collector fails without the config file which is not compatible behavior with our collector. 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. 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.
IIRC, this is no longer true, but yes I agree, let's start with the batch processor and merge this soon. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// 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 ( | ||
"sort" | ||
"testing" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector/config" | ||
"github.com/open-telemetry/opentelemetry-collector/config/configmodels" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
"github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/cassandra" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/elasticsearch" | ||
"github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/kafka" | ||
) | ||
|
||
func TestDefaultConfig(t *testing.T) { | ||
factories := Components(viper.New()) | ||
tests := []struct { | ||
storageType string | ||
exporterTypes []string | ||
pipeline map[string]*configmodels.Pipeline | ||
err string | ||
}{ | ||
{ | ||
storageType: "elasticsearch", | ||
exporterTypes: []string{elasticsearch.TypeStr}, | ||
pipeline: map[string]*configmodels.Pipeline{ | ||
"traces": { | ||
InputType: configmodels.TracesDataType, | ||
Receivers: []string{"jaeger"}, | ||
Exporters: []string{elasticsearch.TypeStr}, | ||
Processors: []string{"batch"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
storageType: "cassandra", | ||
exporterTypes: []string{cassandra.TypeStr}, | ||
pipeline: map[string]*configmodels.Pipeline{ | ||
"traces": { | ||
InputType: configmodels.TracesDataType, | ||
Receivers: []string{"jaeger"}, | ||
Exporters: []string{cassandra.TypeStr}, | ||
Processors: []string{"batch"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
storageType: "kafka", | ||
exporterTypes: []string{kafka.TypeStr}, | ||
pipeline: map[string]*configmodels.Pipeline{ | ||
"traces": { | ||
InputType: configmodels.TracesDataType, | ||
Receivers: []string{"jaeger"}, | ||
Exporters: []string{kafka.TypeStr}, | ||
Processors: []string{"batch"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
storageType: "cassandra,elasticsearch", | ||
exporterTypes: []string{cassandra.TypeStr, elasticsearch.TypeStr}, | ||
pipeline: map[string]*configmodels.Pipeline{ | ||
"traces": { | ||
InputType: configmodels.TracesDataType, | ||
Receivers: []string{"jaeger"}, | ||
Exporters: []string{cassandra.TypeStr, elasticsearch.TypeStr}, | ||
Processors: []string{"batch"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
storageType: "floppy", | ||
err: "unknown storage type: floppy", | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.storageType, func(t *testing.T) { | ||
cfg, err := Config(test.storageType, factories) | ||
if test.err != "" { | ||
require.Nil(t, cfg) | ||
assert.EqualError(t, err, test.err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.NoError(t, config.ValidateConfig(cfg, zap.NewNop())) | ||
|
||
assert.Equal(t, 1, len(cfg.Receivers)) | ||
assert.Equal(t, "jaeger", cfg.Receivers["jaeger"].Name()) | ||
assert.Equal(t, 1, len(cfg.Processors)) | ||
assert.Equal(t, "batch", cfg.Processors["batch"].Name()) | ||
assert.Equal(t, len(test.exporterTypes), len(cfg.Exporters)) | ||
|
||
types := []string{} | ||
for _, v := range cfg.Exporters { | ||
types = append(types, v.Type()) | ||
} | ||
sort.Strings(types) | ||
assert.Equal(t, test.exporterTypes, types) | ||
assert.EqualValues(t, test.pipeline, cfg.Service.Pipelines) | ||
}) | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a switch case here and error out on a bad storage type here, instead of passing it down to
main.go
and handling it instorageFlags()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the switch, the
storageFlags
from main also parses the variable but it has a different functionality