-
Notifications
You must be signed in to change notification settings - Fork 214
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 k8sattributesprocessor to otlp pipeline with workload type detection #1524
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
58fa4a9
Add k8sattributesprocessor to k8s otlp pipeline with workload type de…
musa-asad e16963e
fix imports
musa-asad 74b183d
add debug exporter
musa-asad 4fd78fc
Revert "add debug exporter"
musa-asad 206b162
use const
musa-asad 6fa02f1
fix imports
musa-asad c8516be
revert cluster changes
musa-asad 18f1855
revert tls
musa-asad 0cbe47d
change pod name
musa-asad 7044cd9
fix lint
musa-asad 9911f4c
address comments
musa-asad 21d1211
fix import
musa-asad 84c829f
address comments
musa-asad c848f91
adjust logic for errors for workload type detection
musa-asad 6c7bda4
adjust log
musa-asad e817325
move get workload outside if
musa-asad 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
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
14 changes: 14 additions & 0 deletions
14
translator/translate/otel/processor/k8sattributesprocessor/k8sattributes.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,14 @@ | ||
pod_association: | ||
- sources: | ||
- from: connection | ||
extract: | ||
metadata: | ||
- k8s.namespace.name | ||
- k8s.pod.name | ||
- k8s.replicaset.name | ||
- k8s.deployment.name | ||
- k8s.daemonset.name | ||
- k8s.statefulset.name | ||
- k8s.cronjob.name | ||
- k8s.job.name | ||
- k8s.node.name |
16 changes: 16 additions & 0 deletions
16
translator/translate/otel/processor/k8sattributesprocessor/k8sattributes_nodefilter.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,16 @@ | ||
pod_association: | ||
- sources: | ||
- from: connection | ||
extract: | ||
metadata: | ||
- k8s.namespace.name | ||
- k8s.pod.name | ||
- k8s.replicaset.name | ||
- k8s.deployment.name | ||
- k8s.daemonset.name | ||
- k8s.statefulset.name | ||
- k8s.cronjob.name | ||
- k8s.job.name | ||
- k8s.node.name | ||
filter: | ||
node_from_env_var: K8S_NODE_NAME |
57 changes: 57 additions & 0 deletions
57
translator/translate/otel/processor/k8sattributesprocessor/translator.go
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,57 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package k8sattributesprocessor | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/confmap" | ||
"go.opentelemetry.io/collector/processor" | ||
|
||
"github.com/aws/amazon-cloudwatch-agent/translator/config" | ||
"github.com/aws/amazon-cloudwatch-agent/translator/context" | ||
"github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" | ||
) | ||
|
||
//go:embed k8sattributes_nodefilter.yaml | ||
var k8sAttributesNodeFilterConfig string | ||
|
||
//go:embed k8sattributes.yaml | ||
var k8sAttributesConfig string | ||
|
||
type translator struct { | ||
name string | ||
factory processor.Factory | ||
} | ||
|
||
var _ common.Translator[component.Config] = (*translator)(nil) | ||
|
||
func NewTranslatorWithName(name string) common.Translator[component.Config] { | ||
return &translator{name, k8sattributesprocessor.NewFactory()} | ||
} | ||
|
||
func (t *translator) ID() component.ID { | ||
return component.NewIDWithName(t.factory.Type(), t.name) | ||
} | ||
|
||
func (t *translator) Translate(_ *confmap.Conf) (component.Config, error) { | ||
cfg := t.factory.CreateDefaultConfig().(*k8sattributesprocessor.Config) | ||
currentContext := context.CurrentContext() | ||
|
||
if currentContext.KubernetesMode() == "" { | ||
return nil, fmt.Errorf("k8sattributesprocessor is only supported on kubernetes") | ||
} | ||
|
||
switch workloadType := currentContext.WorkloadType(); workloadType { | ||
case config.DaemonSet: | ||
return common.GetYamlFileToYamlConfig(cfg, k8sAttributesNodeFilterConfig) | ||
case config.Deployment, config.StatefulSet: | ||
return common.GetYamlFileToYamlConfig(cfg, k8sAttributesConfig) | ||
default: | ||
return nil, fmt.Errorf("k8sattributesprocessor is not supported for this workload type") | ||
} | ||
} |
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.
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 cumulativetodelta come after awsentity?
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.
From my understanding, the cumulativetodelta processor only touches numeric datapoint attributes, whereas awsentity only touches resource attributes, and sometimes string datapoint attributes to get service name information, which should be fine.
Albeit, my changes shouldn't have changed the position of the entity processor. I can move it after if you think it's safer. It looks like we do the same thing for the
"hostDeltaMetrics"
pipeline, so we may have to change that too. I am fine with either option, but let me know.