Skip to content

Commit

Permalink
chore: refactor integration tests and add some for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgerring committed Dec 16, 2024
1 parent 967dc93 commit 55dfbfa
Show file tree
Hide file tree
Showing 22 changed files with 977 additions and 395 deletions.
1 change: 1 addition & 0 deletions opentelemetry-otlp/tests/integration_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lcov.info
10 changes: 6 additions & 4 deletions opentelemetry-otlp/tests/integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ version = "0.1.0"
edition = "2021"
publish = false


[dependencies]
opentelemetry = { path = "../../../opentelemetry", features = ["metrics", "logs"] }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "logs", "testing"] }
opentelemetry-proto = { path = "../../../opentelemetry-proto", features = ["gen-tonic-messages", "trace", "logs", "with-serde"] }
opentelemetry = { path = "../../../opentelemetry", features = [] }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "testing"] }
opentelemetry-proto = { path = "../../../opentelemetry-proto", features = ["gen-tonic-messages", "trace", "logs", "metrics", "with-serde"] }
log = { workspace = true }
tokio = { version = "1.0", features = ["full"] }
serde_json = "1"
testcontainers = "0.15.0"
once_cell.workspace = true
anyhow = "1.0.94"
ctor = "0.2.9"

[target.'cfg(unix)'.dependencies]
opentelemetry-appender-log = { path = "../../../opentelemetry-appender-log", default-features = false}
Expand Down
14 changes: 14 additions & 0 deletions opentelemetry-otlp/tests/integration_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# OTLP - Integration Tests
This directory contains integration tests for `opentelemetry-otlp`. It uses
[testcontainers](https://testcontainers.com/) to start an instance of the OTEL collector using [otel-collector-config.yaml](otel-collector-config.yaml), which then uses a file exporter per signal to write the output it receives back to the host machine.

The tests connect directly to the collector on `localhost:4317` and `localhost:4318`, push data through, and then check that what they expect
has popped back out into the files output by the collector.

For this to work, you need a couple of things:

* Docker, for the test container
* TCP/4317 and TCP/4318 free on your local machine. If you are running another collector, you'll need to stop it for the tests to run



Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
1 change: 1 addition & 0 deletions opentelemetry-otlp/tests/integration_test/actual/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Output from the otel-collector goes here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"resourceMetrics": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "metrics-integration-test"
}
}
]
},
"scopeMetrics": [
{
"scope": {
"name": "meter"
},
"metrics": [
{
"name": "counter_u64",
"sum": {
"dataPoints": [
{
"attributes": [
{
"key": "mykey1",
"value": {
"stringValue": "mydifferentval"
}
},
{
"key": "mykey2",
"value": {
"stringValue": "myvalue2"
}
}
],
"startTimeUnixNano": "1734094309366798000",
"timeUnixNano": "1734094317871514000",
"asInt": "15"
}
],
"aggregationTemporality": 2,
"isMonotonic": true
}
},
{
"name": "example_histogram",
"histogram": {
"dataPoints": [
{
"attributes": [
{
"key": "mykey3",
"value": {
"stringValue": "myvalue4"
}
}
],
"startTimeUnixNano": "1734094309366875000",
"timeUnixNano": "1734094317871537000",
"count": "1",
"sum": 42,
"bucketCounts": [
"0",
"0",
"0",
"0",
"1",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0"
],
"explicitBounds": [
0,
5,
10,
25,
50,
75,
100,
250,
500,
750,
1000,
2500,
5000,
7500,
10000
],
"min": 42,
"max": 42
}
],
"aggregationTemporality": 2
}
},
{
"name": "example_up_down_counter",
"sum": {
"dataPoints": [
{
"attributes": [
{
"key": "mykey5",
"value": {
"stringValue": "myvalue5"
}
}
],
"startTimeUnixNano": "1734094309366941000",
"timeUnixNano": "1734094317871548000",
"asInt": "-1"
}
],
"aggregationTemporality": 2
}
}
]
}
]
}
]
}
138 changes: 76 additions & 62 deletions opentelemetry-otlp/tests/integration_test/expected/metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,114 +6,128 @@
{
"key": "service.name",
"value": {
"stringValue": "my.service"
"stringValue": "metrics-integration-test"
}
}
]
},
"scopeMetrics": [
{
"scope": {
"name": "my.library",
"version": "1.0.0",
"attributes": [
{
"key": "my.scope.attribute",
"value": {
"stringValue": "some scope attribute"
}
}
]
"name": "meter"
},
"metrics": [
{
"name": "my.counter",
"unit": "1",
"description": "I am a Counter",
"metadata": [],
"name": "counter_u64",
"sum": {
"aggregationTemporality": 1,
"isMonotonic": true,
"dataPoints": [
{
"asDouble": 5,
"startTimeUnixNano": "1544712660300000000",
"timeUnixNano": "1544712660300000000",
"attributes": [
{
"key": "my.counter.attr",
"key": "mykey1",
"value": {
"stringValue": "some value"
"stringValue": "myvalue1"
}
},
{
"key": "mykey2",
"value": {
"stringValue": "myvalue2"
}
}
],
"exemplars": [],
"flags": 0
"startTimeUnixNano": "1734094309366798000",
"timeUnixNano": "1734094317871514000",
"asInt": "10"
}
]
],
"aggregationTemporality": 2,
"isMonotonic": true
}
},
{
"name": "my.gauge",
"unit": "1",
"description": "I am a Gauge",
"metadata": [],
"gauge": {
"name": "example_histogram",
"histogram": {
"dataPoints": [
{
"asDouble": 10,
"startTimeUnixNano": "1544712660300000000",
"timeUnixNano": "1544712660300000000",
"attributes": [
{
"key": "my.gauge.attr",
"key": "mykey3",
"value": {
"stringValue": "some value"
"stringValue": "myvalue4"
}
}
],
"exemplars": [],
"flags": 0
"startTimeUnixNano": "1734094309366875000",
"timeUnixNano": "1734094317871537000",
"count": "1",
"sum": 42,
"bucketCounts": [
"0",
"0",
"0",
"0",
"1",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0"
],
"explicitBounds": [
0,
5,
10,
25,
50,
75,
100,
250,
500,
750,
1000,
2500,
5000,
7500,
10000
],
"min": 42,
"max": 42
}
]
],
"aggregationTemporality": 2
}
},
{
"name": "my.histogram",
"unit": "1",
"description": "I am a Histogram",
"metadata": [],
"histogram": {
"aggregationTemporality": 1,
"name": "example_up_down_counter",
"sum": {
"dataPoints": [
{
"startTimeUnixNano": "1544712660300000000",
"timeUnixNano": "1544712660300000000",
"count": 2,
"sum": 2,
"bucketCounts": [1,1],
"explicitBounds": [1],
"min": 0,
"max": 2,
"attributes": [
{
"key": "my.histogram.attr",
"key": "mykey5",
"value": {
"stringValue": "some value"
"stringValue": "myvalue5"
}
}
],
"exemplars": [],
"flags": 0
"startTimeUnixNano": "1734094309366941000",
"timeUnixNano": "1734094317871548000",
"asInt": "-1"
}
]
],
"aggregationTemporality": 2
}
}
],
"schemaUrl": "whatever"
]
}
],
"schemaUrl": "whatever"
]
}
]
}
}
Loading

0 comments on commit 55dfbfa

Please sign in to comment.