Skip to content

Commit 684a70c

Browse files
committed
chore: refactor integration tests and introduce metrics integration
tests
1 parent ce550e3 commit 684a70c

22 files changed

+990
-395
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lcov.info

opentelemetry-otlp/tests/integration_test/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ version = "0.1.0"
44
edition = "2021"
55
publish = false
66

7-
87
[dependencies]
9-
opentelemetry = { path = "../../../opentelemetry", features = ["metrics", "logs"] }
10-
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "logs", "testing"] }
11-
opentelemetry-proto = { path = "../../../opentelemetry-proto", features = ["gen-tonic-messages", "trace", "logs", "with-serde"] }
8+
opentelemetry = { path = "../../../opentelemetry", features = [] }
9+
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "testing"] }
10+
opentelemetry-proto = { path = "../../../opentelemetry-proto", features = ["gen-tonic-messages", "trace", "logs", "metrics", "with-serde"] }
1211
log = { workspace = true }
1312
tokio = { version = "1.0", features = ["full"] }
1413
serde_json = "1"
1514
testcontainers = "0.15.0"
15+
once_cell.workspace = true
16+
anyhow = "1.0.94"
17+
ctor = "0.2.9"
1618

1719
[target.'cfg(unix)'.dependencies]
1820
opentelemetry-appender-log = { path = "../../../opentelemetry-appender-log", default-features = false}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OTLP - Integration Tests
2+
This directory contains integration tests for `opentelemetry-otlp`. It uses
3+
[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.
4+
5+
The tests connect directly to the collector on `localhost:4317` and `localhost:4318`, push data through, and then check that what they expect
6+
has popped back out into the files output by the collector.
7+
8+
For this to work, you need a couple of things:
9+
10+
* Docker, for the test container
11+
* 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
12+
13+
14+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Output from the otel-collector goes here.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"resourceMetrics": [
3+
{
4+
"resource": {
5+
"attributes": [
6+
{
7+
"key": "service.name",
8+
"value": {
9+
"stringValue": "metrics-integration-test"
10+
}
11+
}
12+
]
13+
},
14+
"scopeMetrics": [
15+
{
16+
"scope": {
17+
"name": "meter"
18+
},
19+
"metrics": [
20+
{
21+
"name": "counter_u64",
22+
"sum": {
23+
"dataPoints": [
24+
{
25+
"attributes": [
26+
{
27+
"key": "mykey1",
28+
"value": {
29+
"stringValue": "mydifferentval"
30+
}
31+
},
32+
{
33+
"key": "mykey2",
34+
"value": {
35+
"stringValue": "myvalue2"
36+
}
37+
}
38+
],
39+
"startTimeUnixNano": "1734094309366798000",
40+
"timeUnixNano": "1734094317871514000",
41+
"asInt": "15"
42+
}
43+
],
44+
"aggregationTemporality": 2,
45+
"isMonotonic": true
46+
}
47+
},
48+
{
49+
"name": "example_histogram",
50+
"histogram": {
51+
"dataPoints": [
52+
{
53+
"attributes": [
54+
{
55+
"key": "mykey3",
56+
"value": {
57+
"stringValue": "myvalue4"
58+
}
59+
}
60+
],
61+
"startTimeUnixNano": "1734094309366875000",
62+
"timeUnixNano": "1734094317871537000",
63+
"count": "1",
64+
"sum": 42,
65+
"bucketCounts": [
66+
"0",
67+
"0",
68+
"0",
69+
"0",
70+
"1",
71+
"0",
72+
"0",
73+
"0",
74+
"0",
75+
"0",
76+
"0",
77+
"0",
78+
"0",
79+
"0",
80+
"0",
81+
"0"
82+
],
83+
"explicitBounds": [
84+
0,
85+
5,
86+
10,
87+
25,
88+
50,
89+
75,
90+
100,
91+
250,
92+
500,
93+
750,
94+
1000,
95+
2500,
96+
5000,
97+
7500,
98+
10000
99+
],
100+
"min": 42,
101+
"max": 42
102+
}
103+
],
104+
"aggregationTemporality": 2
105+
}
106+
},
107+
{
108+
"name": "example_up_down_counter",
109+
"sum": {
110+
"dataPoints": [
111+
{
112+
"attributes": [
113+
{
114+
"key": "mykey5",
115+
"value": {
116+
"stringValue": "myvalue5"
117+
}
118+
}
119+
],
120+
"startTimeUnixNano": "1734094309366941000",
121+
"timeUnixNano": "1734094317871548000",
122+
"asInt": "-1"
123+
}
124+
],
125+
"aggregationTemporality": 2
126+
}
127+
}
128+
]
129+
}
130+
]
131+
}
132+
]
133+
}

opentelemetry-otlp/tests/integration_test/expected/metrics.json

Lines changed: 76 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,114 +6,128 @@
66
{
77
"key": "service.name",
88
"value": {
9-
"stringValue": "my.service"
9+
"stringValue": "metrics-integration-test"
1010
}
1111
}
1212
]
1313
},
1414
"scopeMetrics": [
1515
{
1616
"scope": {
17-
"name": "my.library",
18-
"version": "1.0.0",
19-
"attributes": [
20-
{
21-
"key": "my.scope.attribute",
22-
"value": {
23-
"stringValue": "some scope attribute"
24-
}
25-
}
26-
]
17+
"name": "meter"
2718
},
2819
"metrics": [
2920
{
30-
"name": "my.counter",
31-
"unit": "1",
32-
"description": "I am a Counter",
33-
"metadata": [],
21+
"name": "counter_u64",
3422
"sum": {
35-
"aggregationTemporality": 1,
36-
"isMonotonic": true,
3723
"dataPoints": [
3824
{
39-
"asDouble": 5,
40-
"startTimeUnixNano": "1544712660300000000",
41-
"timeUnixNano": "1544712660300000000",
4225
"attributes": [
4326
{
44-
"key": "my.counter.attr",
27+
"key": "mykey1",
4528
"value": {
46-
"stringValue": "some value"
29+
"stringValue": "myvalue1"
30+
}
31+
},
32+
{
33+
"key": "mykey2",
34+
"value": {
35+
"stringValue": "myvalue2"
4736
}
4837
}
4938
],
50-
"exemplars": [],
51-
"flags": 0
39+
"startTimeUnixNano": "1734094309366798000",
40+
"timeUnixNano": "1734094317871514000",
41+
"asInt": "10"
5242
}
53-
]
43+
],
44+
"aggregationTemporality": 2,
45+
"isMonotonic": true
5446
}
5547
},
5648
{
57-
"name": "my.gauge",
58-
"unit": "1",
59-
"description": "I am a Gauge",
60-
"metadata": [],
61-
"gauge": {
49+
"name": "example_histogram",
50+
"histogram": {
6251
"dataPoints": [
6352
{
64-
"asDouble": 10,
65-
"startTimeUnixNano": "1544712660300000000",
66-
"timeUnixNano": "1544712660300000000",
6753
"attributes": [
6854
{
69-
"key": "my.gauge.attr",
55+
"key": "mykey3",
7056
"value": {
71-
"stringValue": "some value"
57+
"stringValue": "myvalue4"
7258
}
7359
}
7460
],
75-
"exemplars": [],
76-
"flags": 0
61+
"startTimeUnixNano": "1734094309366875000",
62+
"timeUnixNano": "1734094317871537000",
63+
"count": "1",
64+
"sum": 42,
65+
"bucketCounts": [
66+
"0",
67+
"0",
68+
"0",
69+
"0",
70+
"1",
71+
"0",
72+
"0",
73+
"0",
74+
"0",
75+
"0",
76+
"0",
77+
"0",
78+
"0",
79+
"0",
80+
"0",
81+
"0"
82+
],
83+
"explicitBounds": [
84+
0,
85+
5,
86+
10,
87+
25,
88+
50,
89+
75,
90+
100,
91+
250,
92+
500,
93+
750,
94+
1000,
95+
2500,
96+
5000,
97+
7500,
98+
10000
99+
],
100+
"min": 42,
101+
"max": 42
77102
}
78-
]
103+
],
104+
"aggregationTemporality": 2
79105
}
80106
},
81107
{
82-
"name": "my.histogram",
83-
"unit": "1",
84-
"description": "I am a Histogram",
85-
"metadata": [],
86-
"histogram": {
87-
"aggregationTemporality": 1,
108+
"name": "example_up_down_counter",
109+
"sum": {
88110
"dataPoints": [
89111
{
90-
"startTimeUnixNano": "1544712660300000000",
91-
"timeUnixNano": "1544712660300000000",
92-
"count": 2,
93-
"sum": 2,
94-
"bucketCounts": [1,1],
95-
"explicitBounds": [1],
96-
"min": 0,
97-
"max": 2,
98112
"attributes": [
99113
{
100-
"key": "my.histogram.attr",
114+
"key": "mykey5",
101115
"value": {
102-
"stringValue": "some value"
116+
"stringValue": "myvalue5"
103117
}
104118
}
105119
],
106-
"exemplars": [],
107-
"flags": 0
120+
"startTimeUnixNano": "1734094309366941000",
121+
"timeUnixNano": "1734094317871548000",
122+
"asInt": "-1"
108123
}
109-
]
124+
],
125+
"aggregationTemporality": 2
110126
}
111127
}
112-
],
113-
"schemaUrl": "whatever"
128+
]
114129
}
115-
],
116-
"schemaUrl": "whatever"
130+
]
117131
}
118132
]
119-
}
133+
}

0 commit comments

Comments
 (0)