-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add Zipkin exporter factory #207
Merged
pjanotti
merged 6 commits into
open-telemetry:master
from
pjanotti:add-zipkin-exporter-factory
Aug 1, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8695b67
Add Zipkin exporter factory
45bce77
PR Feedback: add 1 test plus some comments
9f86f57
Rename endpoint to http-url and related field
d4d082c
Fix goimports issue
e49f7b8
Remove TODO commented code
bb5dd01
Rename the field used to specify destination
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 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 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 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 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
Submodule ocsender
added at
878037
This file contains 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,28 @@ | ||
// Copyright 2019, OpenTelemetry 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 zipkinexporter | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-service/config/configmodels" | ||
) | ||
|
||
// Config defines configuration settings for the Zipkin exporter. | ||
type Config struct { | ||
configmodels.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. | ||
|
||
// The URL to send the Zipkin trace data to (e.g.: | ||
// http://some.url:9411/api/v2/spans). | ||
URL string `mapstructure:"url"` | ||
} |
This file contains 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,53 @@ | ||
// Copyright 2019, OpenTelemetry 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 zipkinexporter | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-service/config" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
receivers, processors, exporters, err := config.ExampleComponents() | ||
assert.Nil(t, err) | ||
|
||
factory := &Factory{} | ||
exporters[typeStr] = factory | ||
cfg, err := config.LoadConfigFile( | ||
t, path.Join(".", "testdata", "config.yaml"), receivers, processors, exporters, | ||
) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
e0 := cfg.Exporters["zipkin"] | ||
|
||
// URL doesn't have a default value so set it directly. | ||
defaultCfg := factory.CreateDefaultConfig().(*Config) | ||
defaultCfg.URL = "http://some.location.org:9411/api/v2/spans" | ||
assert.Equal(t, defaultCfg, e0) | ||
|
||
e1 := cfg.Exporters["zipkin/2"] | ||
assert.Equal(t, "zipkin/2", e1.(*Config).Name()) | ||
assert.Equal(t, "https://somedest:1234/api/v2/spans", e1.(*Config).URL) | ||
_, _, err = factory.CreateTraceExporter(zap.NewNop(), e1) | ||
require.NoError(t, err) | ||
} |
This file contains 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,71 @@ | ||
// Copyright 2019, OpenTelemetry 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 zipkinexporter | ||
|
||
import ( | ||
"errors" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-service/config/configerror" | ||
"github.com/open-telemetry/opentelemetry-service/config/configmodels" | ||
"github.com/open-telemetry/opentelemetry-service/consumer" | ||
"github.com/open-telemetry/opentelemetry-service/exporter" | ||
) | ||
|
||
const ( | ||
// The value of "type" key in configuration. | ||
typeStr = "zipkin" | ||
) | ||
|
||
// Factory is the factory for OpenCensus exporter. | ||
type Factory struct { | ||
} | ||
|
||
// Type gets the type of the Exporter config created by this factory. | ||
func (f *Factory) Type() string { | ||
return typeStr | ||
} | ||
|
||
// CreateDefaultConfig creates the default configuration for exporter. | ||
func (f *Factory) CreateDefaultConfig() configmodels.Exporter { | ||
return &Config{ | ||
ExporterSettings: configmodels.ExporterSettings{ | ||
TypeVal: typeStr, | ||
NameVal: typeStr, | ||
}, | ||
} | ||
} | ||
|
||
// CreateTraceExporter creates a trace exporter based on this config. | ||
func (f *Factory) CreateTraceExporter(logger *zap.Logger, config configmodels.Exporter) (consumer.TraceConsumer, exporter.StopFunc, error) { | ||
cfg := config.(*Config) | ||
|
||
if cfg.URL == "" { | ||
return nil, nil, errors.New("exporter config requires a non-empty 'url'") // TODO: better error | ||
} | ||
|
||
ze, err := newZipkinExporter(cfg.URL, "<missing service name>", 0) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return ze, ze.stop, nil | ||
} | ||
|
||
// CreateMetricsExporter creates a metrics exporter based on this config. | ||
func (f *Factory) CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (consumer.MetricsConsumer, exporter.StopFunc, error) { | ||
return nil, nil, configerror.ErrDataTypeIsNotSupported | ||
} |
This file contains 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,64 @@ | ||
// Copyright 2019, OpenTelemetry 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 zipkinexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.uber.org/zap" | ||
|
||
"github.com/open-telemetry/opentelemetry-service/config/configerror" | ||
) | ||
|
||
func TestCreateDefaultConfig(t *testing.T) { | ||
factory := Factory{} | ||
cfg := factory.CreateDefaultConfig() | ||
assert.NotNil(t, cfg, "failed to create default config") | ||
} | ||
|
||
func TestCreateMetricsExporter(t *testing.T) { | ||
factory := Factory{} | ||
cfg := factory.CreateDefaultConfig() | ||
|
||
_, _, err := factory.CreateMetricsExporter(zap.NewNop(), cfg) | ||
assert.Error(t, err, configerror.ErrDataTypeIsNotSupported) | ||
} | ||
|
||
func TestCreateInstanceViaFactory(t *testing.T) { | ||
factory := Factory{} | ||
|
||
cfg := factory.CreateDefaultConfig() | ||
|
||
// Default config doesn't have default endpoint so creating from it should | ||
// fail. | ||
ze, zeStopFn, err := factory.CreateTraceExporter( | ||
zap.NewNop(), | ||
cfg) | ||
assert.Error(t, err) | ||
assert.Nil(t, ze) | ||
assert.Nil(t, zeStopFn) | ||
|
||
// URL doesn't have a default value so set it directly. | ||
zeCfg := cfg.(*Config) | ||
zeCfg.URL = "http://some.location.org:9411/api/v2/spans" | ||
ze, zeStopFn, err = factory.CreateTraceExporter( | ||
zap.NewNop(), | ||
cfg) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, ze) | ||
assert.NotNil(t, zeStopFn) | ||
assert.NoError(t, zeStopFn()) | ||
} |
This file contains 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,17 @@ | ||
receivers: | ||
examplereceiver: | ||
|
||
processors: | ||
exampleprocessor: | ||
|
||
exporters: | ||
zipkin: | ||
url: "http://some.location.org:9411/api/v2/spans" | ||
zipkin/2: | ||
url: "https://somedest:1234/api/v2/spans" | ||
|
||
pipelines: | ||
traces: | ||
receivers: [examplereceiver] | ||
processors: [exampleprocessor] | ||
exporters: [zipkin, zipkin/2] |
This file contains 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
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.
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.
Should this be added to new config?
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.
UploadPeriod
is an option for the Zipkin exporter that i t should be handled in equivalent form via the pipeline, the same way that we do for OC (eg.: batcher, queued-retry).ServiceName
shouldn't actually be necessary, of course it still possible to have some bug in a client library not providing that information but it doesn't make much sense to inject it at the service as a configurable option, a place holder should suffice.