forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added routing exporter (open-telemetry#907)
Closes open-telemetry/opentelemetry-collector#1260 Supersedes open-telemetry/opentelemetry-collector#1611 **Testing:** unit tests + manual tests (see open-telemetry/opentelemetry-collector#1611) **Documentation:** README included. Signed-off-by: Juraci Paixão Kröhling <[email protected]>
- Loading branch information
1 parent
4f2f5cc
commit 1b925a1
Showing
16 changed files
with
2,620 additions
and
34 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
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,39 @@ | ||
# Routing processor | ||
|
||
Routes traces to specific exporters. | ||
|
||
This processor will read a header from the incoming HTTP request (gRPC or plain HTTP) and direct the trace information to specific exporters based on the attribute's value. | ||
|
||
This processor *does not* let traces to continue through the pipeline and will emit a warning in case other processor(s) are defined after this one. Similarly, exporters defined as part of the pipeline are not authoritative: if you add an exporter to the pipeline, make sure you add it to this processor *as well*, otherwise it won't be used at all. All exporters defined as part of this processor *must also* be defined as part of the pipeline's exporters. | ||
|
||
Given that this processor depends on information provided by the client via HTTP headers, processors that aggregate data like `batch` or `groupbytrace` should not be used when this processor is part of the pipeline. | ||
|
||
The following settings are required: | ||
|
||
- `from_attribute`: contains the HTTP header name to look up the route's value. Only the OTLP exporter has been tested in connection with the OTLP gRPC Receiver, but any other gRPC receiver should work fine, as long as the client sends the specified HTTP header. | ||
- `table`: the routing table for this processor. | ||
- `table.value`: a possible value for the attribute specified under FromAttribute. | ||
- `table.exporters`: the list of exporters to use when the value from the FromAttribute field matches this table item. | ||
|
||
The following settings can be optionally configured: | ||
|
||
- `default_exporters` contains the list of exporters to use when a more specific record can't be found in the routing table. | ||
|
||
Example: | ||
|
||
```yaml | ||
processors: | ||
routing: | ||
from_attribute: X-Tenant | ||
default_exporters: jaeger | ||
table: | ||
- value: acme | ||
exporters: [jaeger/acme] | ||
exporters: | ||
jaeger: | ||
endpoint: localhost:14250 | ||
jaeger/acme: | ||
endpoint: localhost:24250 | ||
``` | ||
|
||
The full list of settings exposed for this processor are documented [here](./config.go) with detailed sample configuration [here](./testdata/config.yaml). |
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,52 @@ | ||
// Copyright The 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:https://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 routingprocessor | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
) | ||
|
||
// Config defines configuration for the Routing processor. | ||
type Config struct { | ||
configmodels.ProcessorSettings `mapstructure:",squash"` | ||
|
||
// DefaultExporters contains the list of exporters to use when a more specific record can't be found in the routing table. | ||
// Optional. | ||
DefaultExporters []string `mapstructure:"default_exporters"` | ||
|
||
// FromAttribute contains the attribute name to look up the route value. This attribute should be part of the context propagated | ||
// down from the previous receivers and/or processors. If all the receivers and processors are propagating the entire context correctly, | ||
// this could be the HTTP/gRPC header from the original request/RPC. Typically, aggregation processors (batch, queued_retry, groupbytrace) | ||
// will create a new context, so, those should be avoided when using this processor.Although the HTTP spec allows headers to be repeated, | ||
// this processor will only use the first value. | ||
// Required. | ||
FromAttribute string `mapstructure:"from_attribute"` | ||
|
||
// Table contains the routing table for this processor. | ||
// Required. | ||
Table []RoutingTableItem `mapstructure:"table"` | ||
} | ||
|
||
// RoutingTableItem specifies how data should be routed to the different exporters | ||
type RoutingTableItem struct { | ||
// Value represents a possible value for the field specified under FromAttribute. Required. | ||
Value string `mapstructure:"value"` | ||
|
||
// Exporters contains the list of exporters to use when the value from the FromAttribute field matches this table item. | ||
// When no exporters are specified, the ones specified under DefaultExporters are used, if any. | ||
// The routing processor will fail upon the first failure from these exporters. | ||
// Optional. | ||
Exporters []string `mapstructure:"exporters"` | ||
} |
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,66 @@ | ||
// Copyright The 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:https://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 routingprocessor | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/config/configtest" | ||
"go.opentelemetry.io/collector/exporter/jaegerexporter" | ||
"go.opentelemetry.io/collector/exporter/otlpexporter" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
factories, err := componenttest.ExampleComponents() | ||
assert.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Processors[typeStr] = factory | ||
|
||
// we don't need to use them in this test, but the config has them | ||
factories.Exporters["otlp"] = otlpexporter.NewFactory() | ||
factories.Exporters["jaeger"] = jaegerexporter.NewFactory() | ||
|
||
cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
parsed := cfg.Processors["routing"] | ||
assert.Equal(t, parsed, | ||
&Config{ | ||
ProcessorSettings: configmodels.ProcessorSettings{ | ||
NameVal: "routing", | ||
TypeVal: "routing", | ||
}, | ||
DefaultExporters: []string{"otlp"}, | ||
FromAttribute: "X-Tenant", | ||
Table: []RoutingTableItem{ | ||
{ | ||
Value: "acme", | ||
Exporters: []string{"jaeger/acme", "otlp/acme"}, | ||
}, | ||
{ | ||
Value: "globex", | ||
Exporters: []string{"otlp/globex"}, | ||
}, | ||
}, | ||
}) | ||
} |
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,50 @@ | ||
// Copyright The 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:https://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 routingprocessor | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/processor/processorhelper" | ||
) | ||
|
||
const ( | ||
// The value of "type" key in configuration. | ||
typeStr = "routing" | ||
) | ||
|
||
// NewFactory creates a factory for the routing processor. | ||
func NewFactory() component.ProcessorFactory { | ||
return processorhelper.NewFactory( | ||
typeStr, | ||
createDefaultConfig, | ||
processorhelper.WithTraces(createTraceProcessor), | ||
) | ||
} | ||
|
||
func createDefaultConfig() configmodels.Processor { | ||
return &Config{} | ||
} | ||
|
||
func createTraceProcessor(_ context.Context, params component.ProcessorCreateParams, cfg configmodels.Processor, nextConsumer consumer.TraceConsumer) (component.TraceProcessor, error) { | ||
_, ok := nextConsumer.(component.Processor) | ||
if ok { | ||
params.Logger.Warn("another processor has been defined after the routing processor: it will NOT receive any data!") | ||
} | ||
return newProcessor(params.Logger, cfg) | ||
} |
Oops, something went wrong.