Skip to content

Commit d9a2f41

Browse files
authored
[chore][processor/resourcedetection] Add E2E tests for elasticbeanstalk detector (#45624)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add E2E tests for elasticbeanstalk detector <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Relates to #24671 Signed-off-by: Paulo Dias <[email protected]>
1 parent da499b5 commit d9a2f41

File tree

7 files changed

+262
-0
lines changed

7 files changed

+262
-0
lines changed

processor/resourcedetectionprocessor/e2e_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,53 @@ func TestE2EDynatraceDetector(t *testing.T) {
712712
}, 3*time.Minute, 1*time.Second)
713713
}
714714

715+
// TestE2EElasticBeanstalkDetector tests the Elastic Beanstalk detector by mounting a mock
716+
// environment.conf file and verifying that the resource attributes are correctly detected
717+
// and attached to metrics.
718+
func TestE2EElasticBeanstalkDetector(t *testing.T) {
719+
var expected pmetric.Metrics
720+
expectedFile := filepath.Join("testdata", "e2e", "elasticbeanstalk", "expected.yaml")
721+
expected, err := golden.ReadMetrics(expectedFile)
722+
require.NoError(t, err)
723+
724+
k8sClient, err := k8stest.NewK8sClient(testKubeConfig)
725+
require.NoError(t, err)
726+
727+
metricsConsumer := new(consumertest.MetricsSink)
728+
shutdownSink := startUpSink(t, metricsConsumer)
729+
defer shutdownSink()
730+
731+
testID := uuid.NewString()[:8]
732+
collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "elasticbeanstalk", "collector"), map[string]string{}, "")
733+
734+
defer func() {
735+
for _, obj := range collectorObjs {
736+
require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName())
737+
}
738+
}()
739+
740+
wantEntries := 10
741+
waitForData(t, wantEntries, metricsConsumer)
742+
743+
// Uncomment to regenerate golden file
744+
// golden.WriteMetrics(t, expectedFile+".actual", metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1])
745+
746+
require.EventuallyWithT(t, func(tt *assert.CollectT) {
747+
assert.NoError(tt, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1],
748+
pmetrictest.IgnoreTimestamp(),
749+
pmetrictest.IgnoreStartTimestamp(),
750+
pmetrictest.IgnoreScopeVersion(),
751+
pmetrictest.IgnoreResourceMetricsOrder(),
752+
pmetrictest.IgnoreMetricsOrder(),
753+
pmetrictest.IgnoreScopeMetricsOrder(),
754+
pmetrictest.IgnoreMetricDataPointsOrder(),
755+
pmetrictest.IgnoreMetricValues(),
756+
pmetrictest.IgnoreSubsequentDataPoints("system.cpu.time"),
757+
),
758+
)
759+
}, 3*time.Minute, 1*time.Second)
760+
}
761+
715762
// TestE2EHetznerDetector tests the Hetzner detector by deploying a metadata-server
716763
// sidecar that simulates the Hetzner IMDS and verifying that the resource attributes
717764
// are correctly detected and attached to metrics.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Name }}-enrichment-config
5+
namespace: default
6+
data:
7+
environment.conf: |
8+
{
9+
"deployment_id": 12345,
10+
"environment_name": "test-elasticbeanstalk-env",
11+
"version_label": "v1.0.0-test"
12+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ .Name }}-config
5+
namespace: default
6+
data:
7+
relay: |
8+
exporters:
9+
otlp:
10+
endpoint: {{ .HostEndpoint }}:4317
11+
tls:
12+
insecure: true
13+
extensions:
14+
health_check:
15+
endpoint: 0.0.0.0:13133
16+
processors:
17+
resourcedetection:
18+
detectors: [elastic_beanstalk]
19+
timeout: 2s
20+
override: false
21+
receivers:
22+
hostmetrics:
23+
collection_interval: 1s
24+
scrapers:
25+
cpu:
26+
service:
27+
telemetry:
28+
logs:
29+
level: "debug"
30+
extensions:
31+
- health_check
32+
pipelines:
33+
metrics:
34+
receivers:
35+
- hostmetrics
36+
processors:
37+
- resourcedetection
38+
exporters:
39+
- otlp
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ .Name }}-sa
5+
namespace: default
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ .Name }}
5+
namespace: default
6+
spec:
7+
selector:
8+
app: {{ .Name }}
9+
ports:
10+
- name: health
11+
port: 13133
12+
targetPort: 13133
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Name }}
5+
namespace: default
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
app: {{ .Name }}
11+
template:
12+
metadata:
13+
labels:
14+
app: {{ .Name }}
15+
spec:
16+
serviceAccountName: {{ .Name }}-sa
17+
containers:
18+
- name: otelcol
19+
image: otelcontribcol:latest
20+
imagePullPolicy: Never
21+
args:
22+
- "--config=/conf/relay"
23+
volumeMounts:
24+
- name: config
25+
mountPath: /conf
26+
- name: enrichment
27+
mountPath: /var/elasticbeanstalk/xray
28+
volumes:
29+
- name: config
30+
configMap:
31+
name: {{ .Name }}-config
32+
items:
33+
- key: relay
34+
path: relay
35+
- name: enrichment
36+
configMap:
37+
name: {{ .Name }}-enrichment-config
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
resourceMetrics:
2+
- resource:
3+
attributes:
4+
- key: cloud.platform
5+
value:
6+
stringValue: aws_elastic_beanstalk
7+
- key: cloud.provider
8+
value:
9+
stringValue: aws
10+
- key: deployment.environment
11+
value:
12+
stringValue: test-elasticbeanstalk-env
13+
- key: service.instance.id
14+
value:
15+
stringValue: "12345"
16+
- key: service.version
17+
value:
18+
stringValue: v1.0.0-test
19+
schemaUrl: https://opentelemetry.io/schemas/1.9.0
20+
scopeMetrics:
21+
- metrics:
22+
- description: Total seconds each logical CPU spent on each mode.
23+
name: system.cpu.time
24+
sum:
25+
aggregationTemporality: 2
26+
dataPoints:
27+
- asDouble: 1.0
28+
attributes:
29+
- key: cpu
30+
value:
31+
stringValue: cpu0
32+
- key: state
33+
value:
34+
stringValue: idle
35+
startTimeUnixNano: "1000000"
36+
timeUnixNano: "2000000"
37+
- asDouble: 1.0
38+
attributes:
39+
- key: cpu
40+
value:
41+
stringValue: cpu0
42+
- key: state
43+
value:
44+
stringValue: interrupt
45+
startTimeUnixNano: "1000000"
46+
timeUnixNano: "2000000"
47+
- asDouble: 1.0
48+
attributes:
49+
- key: cpu
50+
value:
51+
stringValue: cpu0
52+
- key: state
53+
value:
54+
stringValue: nice
55+
startTimeUnixNano: "1000000"
56+
timeUnixNano: "2000000"
57+
- asDouble: 1.0
58+
attributes:
59+
- key: cpu
60+
value:
61+
stringValue: cpu0
62+
- key: state
63+
value:
64+
stringValue: softirq
65+
startTimeUnixNano: "1000000"
66+
timeUnixNano: "2000000"
67+
- asDouble: 1.0
68+
attributes:
69+
- key: cpu
70+
value:
71+
stringValue: cpu0
72+
- key: state
73+
value:
74+
stringValue: steal
75+
startTimeUnixNano: "1000000"
76+
timeUnixNano: "2000000"
77+
- asDouble: 1.0
78+
attributes:
79+
- key: cpu
80+
value:
81+
stringValue: cpu0
82+
- key: state
83+
value:
84+
stringValue: system
85+
startTimeUnixNano: "1000000"
86+
timeUnixNano: "2000000"
87+
- asDouble: 1.0
88+
attributes:
89+
- key: cpu
90+
value:
91+
stringValue: cpu0
92+
- key: state
93+
value:
94+
stringValue: user
95+
startTimeUnixNano: "1000000"
96+
timeUnixNano: "2000000"
97+
- asDouble: 1.0
98+
attributes:
99+
- key: cpu
100+
value:
101+
stringValue: cpu0
102+
- key: state
103+
value:
104+
stringValue: wait
105+
startTimeUnixNano: "1000000"
106+
timeUnixNano: "2000000"
107+
isMonotonic: true
108+
unit: s
109+
scope:
110+
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper

0 commit comments

Comments
 (0)