Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions processor/resourcedetectionprocessor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,53 @@ func TestE2EDynatraceDetector(t *testing.T) {
}, 3*time.Minute, 1*time.Second)
}

// TestE2EElasticBeanstalkDetector tests the Elastic Beanstalk detector by mounting a mock
// environment.conf file and verifying that the resource attributes are correctly detected
// and attached to metrics.
func TestE2EElasticBeanstalkDetector(t *testing.T) {
var expected pmetric.Metrics
expectedFile := filepath.Join("testdata", "e2e", "elasticbeanstalk", "expected.yaml")
expected, err := golden.ReadMetrics(expectedFile)
require.NoError(t, err)

k8sClient, err := k8stest.NewK8sClient(testKubeConfig)
require.NoError(t, err)

metricsConsumer := new(consumertest.MetricsSink)
shutdownSink := startUpSink(t, metricsConsumer)
defer shutdownSink()

testID := uuid.NewString()[:8]
collectorObjs := k8stest.CreateCollectorObjects(t, k8sClient, testID, filepath.Join(".", "testdata", "e2e", "elasticbeanstalk", "collector"), map[string]string{}, "")

defer func() {
for _, obj := range collectorObjs {
require.NoErrorf(t, k8stest.DeleteObject(k8sClient, obj), "failed to delete object %s", obj.GetName())
}
}()

wantEntries := 10
waitForData(t, wantEntries, metricsConsumer)

// Uncomment to regenerate golden file
// golden.WriteMetrics(t, expectedFile+".actual", metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1])

require.EventuallyWithT(t, func(tt *assert.CollectT) {
assert.NoError(tt, pmetrictest.CompareMetrics(expected, metricsConsumer.AllMetrics()[len(metricsConsumer.AllMetrics())-1],
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreSubsequentDataPoints("system.cpu.time"),
),
)
}, 3*time.Minute, 1*time.Second)
}

// TestE2EHetznerDetector tests the Hetzner detector by deploying a metadata-server
// sidecar that simulates the Hetzner IMDS and verifying that the resource attributes
// are correctly detected and attached to metrics.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Name }}-enrichment-config
namespace: default
data:
environment.conf: |
{
"deployment_id": 12345,
"environment_name": "test-elasticbeanstalk-env",
"version_label": "v1.0.0-test"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Name }}-config
namespace: default
data:
relay: |
exporters:
otlp:
endpoint: {{ .HostEndpoint }}:4317
tls:
insecure: true
extensions:
health_check:
endpoint: 0.0.0.0:13133
processors:
resourcedetection:
detectors: [elastic_beanstalk]
timeout: 2s
override: false
receivers:
hostmetrics:
collection_interval: 1s
scrapers:
cpu:
service:
telemetry:
logs:
level: "debug"
extensions:
- health_check
pipelines:
metrics:
receivers:
- hostmetrics
processors:
- resourcedetection
exporters:
- otlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Name }}-sa
namespace: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Name }}
namespace: default
spec:
selector:
app: {{ .Name }}
ports:
- name: health
port: 13133
targetPort: 13133
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Name }}
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Name }}
template:
metadata:
labels:
app: {{ .Name }}
spec:
serviceAccountName: {{ .Name }}-sa
containers:
- name: otelcol
image: otelcontribcol:latest
imagePullPolicy: Never
args:
- "--config=/conf/relay"
volumeMounts:
- name: config
mountPath: /conf
- name: enrichment
mountPath: /var/elasticbeanstalk/xray
volumes:
- name: config
configMap:
name: {{ .Name }}-config
items:
- key: relay
path: relay
- name: enrichment
configMap:
name: {{ .Name }}-enrichment-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
resourceMetrics:
- resource:
attributes:
- key: cloud.platform
value:
stringValue: aws_elastic_beanstalk
- key: cloud.provider
value:
stringValue: aws
- key: deployment.environment
value:
stringValue: test-elasticbeanstalk-env
- key: service.instance.id
value:
stringValue: "12345"
- key: service.version
value:
stringValue: v1.0.0-test
schemaUrl: https://opentelemetry.io/schemas/1.9.0
scopeMetrics:
- metrics:
- description: Total seconds each logical CPU spent on each mode.
name: system.cpu.time
sum:
aggregationTemporality: 2
dataPoints:
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: idle
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: interrupt
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: nice
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: softirq
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: steal
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: system
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: user
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
- asDouble: 1.0
attributes:
- key: cpu
value:
stringValue: cpu0
- key: state
value:
stringValue: wait
startTimeUnixNano: "1000000"
timeUnixNano: "2000000"
isMonotonic: true
unit: s
scope:
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper