-
Notifications
You must be signed in to change notification settings - Fork 43
Introduce dynamic routing connector #932
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
Open
lahsivjar
wants to merge
10
commits into
elastic:main
Choose a base branch
from
lahsivjar:ingest-batching-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,138
−0
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0ea42d5
Introduce dynamic routing connector
lahsivjar fda66ca
Merge branch 'main' into ingest-batching-component
lahsivjar 7b91dda
Handle xxhash deletion errors
lahsivjar 9932c90
Update README
lahsivjar dd079ac
Add to versions.yaml
lahsivjar f47dedc
Update connector/dynamicroutingconnector/config.go
lahsivjar e44161b
mutatesData -> false
lahsivjar e102ce9
Merge thresholds and pipelines into one config struct
lahsivjar 00adc36
Allow multiple metadata keys
lahsivjar 8bcabb6
fix dynamic pipeline name
lahsivjar 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| include ../../Makefile.Common | ||
|
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,54 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you 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 dynamicroutingconnector // import "github.com/elastic/opentelemetry-collector-components/connector/dynamicroutingconnector" | ||
|
|
||
| import ( | ||
| "errors" | ||
| "sort" | ||
| "time" | ||
|
|
||
| "go.opentelemetry.io/collector/pipeline" | ||
| ) | ||
|
|
||
| type Config struct { | ||
| DefaultPipelines []pipeline.ID `mapstructure:"default_pipelines"` | ||
| EvaluationInterval time.Duration `mapstructure:"evalaution_interval"` | ||
| Pipelines [][]pipeline.ID `mapstructure:"pipelines"` | ||
lahsivjar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Thresholds []int `mapstructure:"thresholds"` | ||
lahsivjar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| PrimaryMetadataKey string `mapstructure:"primary_metadata_key"` | ||
| MetadataKeys []string `mapstructure:"metadata_keys"` | ||
| } | ||
|
|
||
| func (c *Config) Validate() error { | ||
| if len(c.Pipelines) == 0 { | ||
| return errors.New("atleast one pipeline needs to be defined") | ||
| } | ||
| if len(c.Pipelines)+1 != len(c.Thresholds) { | ||
| return errors.New("pipelines need to be defined for each threshold bucket, including +inf") | ||
| } | ||
| if !sort.IntsAreSorted(c.Thresholds) { | ||
| return errors.New("thresolds is expected to be in increasing order") | ||
| } | ||
|
|
||
| for i := 1; i < len(c.Thresholds); i++ { | ||
| if c.Thresholds[i] == c.Thresholds[i-1] { | ||
| return errors.New("thresholds are expected to be unique") | ||
| } | ||
| } | ||
| 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,21 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you 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. | ||
|
|
||
| //go:generate mdatagen metadata.yaml | ||
|
|
||
| // Package dynamicroutingconnector provides a connector for dynamically routing requests to different pipelines depending on the configuration. | ||
| package dynamicroutingconnector // import "github.com/elastic/opentelemetry-collector-components/connector/dynamicroutingconnector" |
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,70 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you 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 dynamicroutingconnector // import "github.com/elastic/opentelemetry-collector-components/connector/dynamicroutingconnector" | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "go.opentelemetry.io/collector/component" | ||
| "go.opentelemetry.io/collector/connector" | ||
| "go.opentelemetry.io/collector/consumer" | ||
|
|
||
| "github.com/elastic/opentelemetry-collector-components/connector/dynamicroutingconnector/internal/metadata" | ||
| ) | ||
|
|
||
| // NewFactory returns a connector.Factory. | ||
| func NewFactory() connector.Factory { | ||
| return connector.NewFactory( | ||
| metadata.Type, | ||
| createDefaultConfig, | ||
| connector.WithTracesToTraces(createTracesToTraces, metadata.TracesToTracesStability), | ||
| connector.WithLogsToLogs(createLogsToLogs, metadata.LogsToLogsStability), | ||
| connector.WithMetricsToMetrics(createMetricsToMetrics, metadata.MetricsToMetricsStability), | ||
| ) | ||
| } | ||
|
|
||
| func createTracesToTraces( | ||
| _ context.Context, | ||
| set connector.Settings, | ||
| cfg component.Config, | ||
| traces consumer.Traces, | ||
| ) (connector.Traces, error) { | ||
| return newTracesConnector(set, cfg, traces) | ||
| } | ||
|
|
||
| func createLogsToLogs( | ||
| _ context.Context, | ||
| set connector.Settings, | ||
| cfg component.Config, | ||
| logs consumer.Logs, | ||
| ) (connector.Logs, error) { | ||
| return newLogsConnector(set, cfg, logs) | ||
| } | ||
|
|
||
| func createMetricsToMetrics( | ||
| _ context.Context, | ||
| set connector.Settings, | ||
| cfg component.Config, | ||
| metrics consumer.Metrics, | ||
| ) (connector.Metrics, error) { | ||
| return newMetricsConnector(set, cfg, metrics) | ||
| } | ||
|
|
||
| func createDefaultConfig() component.Config { | ||
| return &Config{} | ||
| } |
123 changes: 123 additions & 0 deletions
123
connector/dynamicroutingconnector/generated_component_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
connector/dynamicroutingconnector/generated_package_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
| module github.com/elastic/opentelemetry-collector-components/connector/dynamicroutingconnector | ||
|
|
||
| go 1.24.0 | ||
|
|
||
| require ( | ||
| github.com/axiomhq/hyperloglog v0.2.5 | ||
| github.com/cespare/xxhash/v2 v2.3.0 | ||
| github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.141.0 | ||
| github.com/stretchr/testify v1.11.1 | ||
| go.opentelemetry.io/collector/client v1.47.0 | ||
| go.opentelemetry.io/collector/component v1.47.0 | ||
| go.opentelemetry.io/collector/component/componenttest v0.141.0 | ||
| go.opentelemetry.io/collector/confmap v1.47.0 | ||
| go.opentelemetry.io/collector/connector v0.141.0 | ||
| go.opentelemetry.io/collector/connector/connectortest v0.141.0 | ||
| go.opentelemetry.io/collector/consumer v1.47.0 | ||
| go.opentelemetry.io/collector/consumer/consumertest v0.141.0 | ||
| go.opentelemetry.io/collector/pdata v1.47.0 | ||
| go.opentelemetry.io/collector/pipeline v1.47.0 | ||
| go.uber.org/goleak v1.3.0 | ||
| go.uber.org/zap v1.27.1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/dgryski/go-metro v0.0.0-20180109044635-280f6062b5bc // indirect | ||
| github.com/go-logr/logr v1.4.3 // indirect | ||
| github.com/go-logr/stdr v1.2.2 // indirect | ||
| github.com/go-viper/mapstructure/v2 v2.4.0 // indirect | ||
| github.com/gobwas/glob v0.2.3 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/hashicorp/go-version v1.7.0 // indirect | ||
| github.com/json-iterator/go v1.1.12 // indirect | ||
| github.com/kamstrup/intmap v0.5.1 // indirect | ||
| github.com/knadh/koanf/maps v0.1.2 // indirect | ||
| github.com/knadh/koanf/providers/confmap v1.0.0 // indirect | ||
| github.com/knadh/koanf/v2 v2.3.0 // indirect | ||
| github.com/mitchellh/copystructure v1.2.0 // indirect | ||
| github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
| github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
| github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect | ||
| github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.141.0 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| go.opentelemetry.io/auto/sdk v1.1.0 // indirect | ||
| go.opentelemetry.io/collector/connector/xconnector v0.141.0 // indirect | ||
| go.opentelemetry.io/collector/consumer/xconsumer v0.141.0 // indirect | ||
| go.opentelemetry.io/collector/featuregate v1.47.0 // indirect | ||
| go.opentelemetry.io/collector/internal/fanoutconsumer v0.141.0 // indirect | ||
| go.opentelemetry.io/collector/pdata/pprofile v0.141.0 // indirect | ||
| go.opentelemetry.io/collector/pipeline/xpipeline v0.141.0 // indirect | ||
| go.opentelemetry.io/otel v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/metric v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/sdk v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect | ||
| go.opentelemetry.io/otel/trace v1.38.0 // indirect | ||
| go.uber.org/multierr v1.11.0 // indirect | ||
| go.yaml.in/yaml/v3 v3.0.4 // indirect | ||
| golang.org/x/sys v0.37.0 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| ) |
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.