-
Notifications
You must be signed in to change notification settings - Fork 206
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
Resource Attributes - refactor and add missing attributes #2111
Open
edeNFed
wants to merge
7
commits into
odigos-io:main
Choose a base branch
from
edeNFed:add-missing-kube-resource-attributes
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b6db9af
share resource attribute logic, migrate webhook
edeNFed bb457eb
opamp: remove device id, use AfterPodStart for res attributes
edeNFed 011d5e8
rollback removal of device id processor
edeNFed dbf312c
add k8sattributes processor
edeNFed e335563
fix e2e tests
edeNFed e7105c9
fix traffic metrics
edeNFed 1dd9702
rebase main
edeNFed 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package resourceattributes | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0" | ||
) | ||
|
||
type Attributes []attribute.KeyValue | ||
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. This type definition introduces a breaking change to the |
||
|
||
// ToEnvVarString converts the attributes to a string that can be used as OTEL_RESOURCE_ATTRIBUTES env var | ||
func (a Attributes) ToEnvVarString() string { | ||
var attrs []string | ||
for _, attr := range a { | ||
attrs = append(attrs, fmt.Sprintf("%s=%s", attr.Key, attr.Value.AsString())) | ||
} | ||
return strings.Join(attrs, ",") | ||
} | ||
|
||
// IncludeServiceName adds the service name to the attributes | ||
// OpAMP clients expect the service name to be set in the resource attributes | ||
func (a Attributes) IncludeServiceName(serviceName string) Attributes { | ||
return append(a, semconv.ServiceName(serviceName)) | ||
} |
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,58 @@ | ||
// Package resourceattributes provides a set of functions to create resource attributes for a container. | ||
// Resource attributes in Odigos are injected in two phases: | ||
// 1. Before the container starts, the attributes are set to identify the container. | ||
// 2. After the container starts, additional attributes may be added to the container. | ||
// Notice that the second phase is not always called, see AfterPodStart for more details. | ||
// | ||
// Use the following guidelines when adding new resource attribute: | ||
// - If the attribute is fast to calculate and is needed by all clients, add it to BeforePodStart. | ||
// - If the attribute is slow to calculate or is only needed for OpAMP/eBPF clients, add it to AfterPodStart. | ||
// An example of slow to calculate attribute is the cloud provider metadata that requires a network call. | ||
package resourceattributes | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/attribute" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0" | ||
) | ||
|
||
type ContainerIdentifier struct { | ||
PodName string | ||
Namespace string | ||
ContainerName string | ||
} | ||
|
||
// BeforePodStart returns the resource attributes that should be set before the container starts. | ||
// This function is called by the PodWebhook before the container starts. | ||
// Currently, the attributes returned are the minimal set of attributes that should be set to identify the container. | ||
// Other attributes (k8s related, cloud provider, etc) are set later by a dedicated processor in odigos-data-collector. | ||
// Notice that clients that calls AfterPodStart will overwrite the attributes set by this function. | ||
func BeforePodStart(identifier *ContainerIdentifier) Attributes { | ||
if identifier == nil { | ||
return nil | ||
} | ||
|
||
return identifyingResourceAttributes(identifier) | ||
} | ||
|
||
// AfterPodStart returns the resource attributes that should be set after the container starts. | ||
// This function is called by the eBPF director or by the OpAMP server after the container starts. | ||
// Currently, the attributes returned are the minimal set of attributes that should be set to identify the container. | ||
// Other attributes (k8s related, cloud provider, etc) are set later by a dedicated processor in odigos-data-collector. | ||
// Notice that this function is not always called, only OpAMP clients or eBPF-based clients will call this function. | ||
// Vanilla OpenTelemetry clients will only call BeforePodStart. | ||
// OpAMP/eBPF clients WILL OVERWRITE the attributes set by BeforePodStart with the attributes returned by this function. | ||
func AfterPodStart(identifier *ContainerIdentifier) Attributes { | ||
edeNFed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if identifier == nil { | ||
return nil | ||
} | ||
|
||
return identifyingResourceAttributes(identifier) | ||
} | ||
|
||
func identifyingResourceAttributes(identifier *ContainerIdentifier) Attributes { | ||
return []attribute.KeyValue{ | ||
semconv.K8SContainerName(identifier.ContainerName), | ||
semconv.K8SPodName(identifier.PodName), | ||
semconv.K8SNamespaceName(identifier.Namespace), | ||
} | ||
} |
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
Oops, something went wrong.
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.
Does this make the
add cluster info
action obsolete?