Skip to content

Commit 4c1d8af

Browse files
authored
[resourcedetection] Add api provider to eks detector (#40205)
#### Description This is a replacement for this PR #39981 - Expanded the resource attributes to be on par with the EC2 detector (the new attributes are set to false by default) #40061 - The EKS detector now uses the newly introduced EKS metadata provider when the IMDS service is not available - If IMDS Service is available, we use the EC2 metadata provider This is needed for EKS clusters that don't have access to IMDS server and causing the EC2 detector and the accountID/ClusterName attributes in the EKS detector to fail. #### Link to tracking issue Fixes #39503 <!--Describe what testing was performed and which tests were added.--> #### Testing Unit tests coverage Manual deployment on EKS automode cluster #### Documentation In addition to the auto generated doc, I added new content to the reamdme Signed-off-by: Dani Louca <[email protected]>
1 parent f9b8ff4 commit 4c1d8af

File tree

13 files changed

+781
-215
lines changed

13 files changed

+781
-215
lines changed

.chloggen/EKSAutoMode.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: resourcedetectionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add the option to retrieve resource attributes from the K8s API server and EC2 api when the IMDS service is not available.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [39503]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/resourcedetectionprocessor/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ processors:
319319

320320
### Amazon EKS
321321

322+
This detector reads resource information from the [EC2 instance metadata service](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) to retrieve related resource attributes.
323+
If IMDS is not available, (example: EKS-AutoMode and POD not on the hostnetwork), it falls back to a combination of [Kubernetes API](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#-strong-kubernetes-api-v1-25-strong-)
324+
and [EC2 API](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html) to retrieve related resource attributes.
325+
326+
EC2 API requires the `EC2:DescribeInstances` permission to be granted to the IAM role. If IMDS is not accessible, ex: EKS-AutoMode, you can use [POD Identity](https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html).
327+
322328
The list of the populated resource attributes can be found at [EKS Detector Resource Attributes](./internal/aws/eks/documentation.md).
323329

324330
Example:
@@ -351,6 +357,46 @@ processors:
351357
Note: The kubernetes cluster name is only available when running on EC2 instances, and requires permission to run the `EC2:DescribeInstances` [action](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html).
352358
If you see an error with the message `context deadline exceeded`, please increase the timeout setting in your config.
353359

360+
#### Node Name Env Variable
361+
When using the EC2 API and the Kubernetes API to retrieve resource attributes, the node name is needed. The node name is extracted from the env variable you define on the pod.
362+
The node name env variable that contains the node name value can be set using the `node_from_env_var` option:
363+
364+
```yaml
365+
processors:
366+
resourcedetection/eks:
367+
detectors: [eks]
368+
timeout: 15s
369+
override: false
370+
eks:
371+
node_from_env_var: K8S_NODE_NAME
372+
```
373+
In this example, the env variable `K8S_NODE_NAME` will hold the actual node name and can be set in the pod spec using the downward API.
374+
375+
```yaml
376+
env:
377+
- name: K8S_NODE_NAME
378+
valueFrom:
379+
fieldRef:
380+
fieldPath: spec.nodeName
381+
```
382+
383+
#### IMDS client
384+
These options are available to configure the IMDS client:
385+
386+
- `max_attempts`: The maximum number of attempts to make when calling the IMDS endpoint. The default is 3.
387+
- `max_backoff`: The maximum backoff time to use when retrying a request. The default is 20 seconds.
388+
389+
```yaml
390+
processors:
391+
resourcedetection/eks:
392+
detectors: [eks]
393+
timeout: 15s
394+
override: false
395+
eks:
396+
max_attempts: 10
397+
max_backoff: 5m
398+
```
399+
354400
### AWS Lambda
355401

356402
Uses the AWS Lambda [runtime environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime)

processor/resourcedetectionprocessor/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ require (
4040
go.uber.org/goleak v1.3.0
4141
go.uber.org/multierr v1.11.0
4242
go.uber.org/zap v1.27.0
43-
k8s.io/client-go v0.32.3
4443
)
4544

4645
require (
@@ -170,6 +169,7 @@ require (
170169
gopkg.in/yaml.v3 v3.0.1 // indirect
171170
k8s.io/api v0.32.3 // indirect
172171
k8s.io/apimachinery v0.32.3 // indirect
172+
k8s.io/client-go v0.32.3 // indirect
173173
k8s.io/klog/v2 v2.130.1 // indirect
174174
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
175175
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect

processor/resourcedetectionprocessor/internal/aws/eks/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44
package eks // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/eks"
55

66
import (
7+
"time"
8+
9+
"github.com/aws/aws-sdk-go-v2/aws/retry"
10+
711
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/eks/internal/metadata"
812
)
913

1014
type Config struct {
1115
ResourceAttributes metadata.ResourceAttributesConfig `mapstructure:"resource_attributes"`
16+
NodeFromEnvVar string `mapstructure:"node_from_env_var"`
17+
MaxAttempts int `mapstructure:"max_attempts"`
18+
MaxBackoff time.Duration `mapstructure:"max_backoff"`
1219
}
1320

1421
func CreateDefaultConfig() Config {
1522
return Config{
1623
ResourceAttributes: metadata.DefaultResourceAttributesConfig(),
24+
MaxBackoff: retry.DefaultMaxBackoff,
25+
MaxAttempts: retry.DefaultMaxAttempts,
1726
}
1827
}

0 commit comments

Comments
 (0)