Skip to content

Commit 5da4529

Browse files
authored
[chore] update golden tests and document the process (#1255)
1 parent 6d1d148 commit 5da4529

File tree

2 files changed

+127
-92
lines changed

2 files changed

+127
-92
lines changed

tests/golden/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Golden file tests
2+
3+
[Golden files](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/golden) are YAML representation
4+
of OpenTelemetry signals.
5+
6+
Golden files are used in conjunction with the [cmd/golden](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/golden) utility
7+
which can listen for OTLP traffic and compare it to incoming traffic. If the input matches the golden file, the program
8+
exits with code 0, and exits with code 1 otherwise.
9+
10+
## Update Golden files
11+
12+
Golden files are typically not managed by hand. We use a feature of the golden command to capture input and write it to file.
13+
14+
To do so, in the docker-compose.yaml file, uncomment the parameter `--write-expected` and delete the data/expected.yaml file.
15+
16+
Run the Docker compose setup with (replacing VERSION with the right version to test for):
17+
```shell
18+
MY_UID="$(id -u)" MY_GID="$(id -g)" IMG=ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:VERSION docker-compose up -d --wait
19+
```
20+
21+
Check in on your docker compose:
22+
23+
```shell
24+
$> docker ps -a
25+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26+
4716ece9c21e ghcr.io/open-telemetry/opentelemetry-collector-contrib/golden:latest "/golden --expected …" About a minute ago Exited (0) About a minute ago golden
27+
13e72a5f997d ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-contrib:0.139.0 "/otelcol-contrib --…" About a minute ago Up About a minute 4317-4318/tcp, 55679/tcp collector
28+
```
29+
30+
Note how golden exited with code 0, meaning it managed to perform its function.
31+
32+
The golden utility will write the file to disk, and you can add it via git to make a diff and understand the changes.
33+
34+
Make a PR with the changes ; CI runs the same steps and will check the match works.
35+

tests/golden/data/expected.yaml

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,38 @@ resourceMetrics:
66
stringValue: "8888"
77
- key: service.instance.id
88
value:
9-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
9+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
1010
- key: service.name
1111
value:
1212
stringValue: otelcol-contrib
1313
- key: service.version
1414
value:
15-
stringValue: 0.133.0
15+
stringValue: 0.139.0
1616
- key: url.scheme
1717
value:
1818
stringValue: http
1919
scopeMetrics:
2020
- metrics:
21-
- description: The scraping was successful
22-
gauge:
23-
dataPoints:
24-
- asDouble: 1
25-
timeUnixNano: "1000000"
26-
metadata:
27-
- key: prometheus.type
28-
value:
29-
stringValue: gauge
30-
name: up
31-
- description: Duration of the scrape
32-
gauge:
33-
dataPoints:
34-
- asDouble: 0.005323833
35-
timeUnixNano: "1000000"
36-
metadata:
37-
- key: prometheus.type
38-
value:
39-
stringValue: gauge
40-
name: scrape_duration_seconds
41-
unit: s
42-
- description: Total physical memory (resident set size) [alpha]
21+
- description: Bytes of allocated heap objects (see 'go doc runtime.MemStats.HeapAlloc') [Alpha]
4322
gauge:
4423
dataPoints:
45-
- asDouble: 1.74903296e+08
24+
- asDouble: 2.0731296e+07
4625
attributes:
4726
- key: service.instance.id
4827
value:
49-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
28+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
5029
- key: service.name
5130
value:
5231
stringValue: otelcol-contrib
5332
- key: service.version
5433
value:
55-
stringValue: 0.133.0
34+
stringValue: 0.139.0
5635
timeUnixNano: "1000000"
5736
metadata:
5837
- key: prometheus.type
5938
value:
6039
stringValue: gauge
61-
name: otelcol_process_memory_rss
40+
name: otelcol_process_runtime_heap_alloc_bytes
6241
- description: Total number of internal errors encountered by the promhttp metric handler.
6342
metadata:
6443
- key: prometheus.type
@@ -83,145 +62,166 @@ resourceMetrics:
8362
startTimeUnixNano: "1000000"
8463
timeUnixNano: "1000000"
8564
isMonotonic: true
86-
- description: The number of samples the target exposed
87-
gauge:
88-
dataPoints:
89-
- asDouble: 9
90-
timeUnixNano: "1000000"
91-
metadata:
92-
- key: prometheus.type
93-
value:
94-
stringValue: gauge
95-
name: scrape_samples_scraped
96-
- description: The number of samples remaining after metric relabeling was applied
97-
gauge:
98-
dataPoints:
99-
- asDouble: 9
100-
timeUnixNano: "1000000"
101-
metadata:
102-
- key: prometheus.type
103-
value:
104-
stringValue: gauge
105-
name: scrape_samples_post_metric_relabeling
106-
- description: The approximate number of new series in this scrape
107-
gauge:
108-
dataPoints:
109-
- asDouble: 9
110-
timeUnixNano: "1000000"
111-
metadata:
112-
- key: prometheus.type
113-
value:
114-
stringValue: gauge
115-
name: scrape_series_added
116-
- description: Total CPU user and system time in seconds [alpha]
65+
- description: Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalAlloc') [Alpha]
11766
metadata:
11867
- key: prometheus.type
11968
value:
12069
stringValue: counter
121-
name: otelcol_process_cpu_seconds
70+
name: otelcol_process_runtime_total_alloc_bytes
12271
sum:
12372
aggregationTemporality: 2
12473
dataPoints:
125-
- asDouble: 0.09
74+
- asDouble: 3.2133528e+07
12675
attributes:
12776
- key: service.instance.id
12877
value:
129-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
78+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
13079
- key: service.name
13180
value:
13281
stringValue: otelcol-contrib
13382
- key: service.version
13483
value:
135-
stringValue: 0.133.0
84+
stringValue: 0.139.0
13685
startTimeUnixNano: "1000000"
13786
timeUnixNano: "1000000"
13887
isMonotonic: true
139-
- description: Bytes of allocated heap objects (see 'go doc runtime.MemStats.HeapAlloc') [alpha]
88+
- description: Total bytes of memory obtained from the OS (see 'go doc runtime.MemStats.Sys') [Alpha]
14089
gauge:
14190
dataPoints:
142-
- asDouble: 1.7492368e+07
91+
- asDouble: 3.7312776e+07
14392
attributes:
14493
- key: service.instance.id
14594
value:
146-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
95+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
14796
- key: service.name
14897
value:
14998
stringValue: otelcol-contrib
15099
- key: service.version
151100
value:
152-
stringValue: 0.133.0
101+
stringValue: 0.139.0
153102
timeUnixNano: "1000000"
154103
metadata:
155104
- key: prometheus.type
156105
value:
157106
stringValue: gauge
158-
name: otelcol_process_runtime_heap_alloc_bytes
159-
- description: Cumulative bytes allocated for heap objects (see 'go doc runtime.MemStats.TotalAlloc') [alpha]
107+
name: otelcol_process_runtime_total_sys_memory_bytes
108+
- description: Uptime of the process [Alpha]
160109
metadata:
161110
- key: prometheus.type
162111
value:
163112
stringValue: counter
164-
name: otelcol_process_runtime_total_alloc_bytes
113+
name: otelcol_process_uptime
165114
sum:
166115
aggregationTemporality: 2
167116
dataPoints:
168-
- asDouble: 3.1338e+07
117+
- asDouble: 6.80132517
169118
attributes:
170119
- key: service.instance.id
171120
value:
172-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
121+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
173122
- key: service.name
174123
value:
175124
stringValue: otelcol-contrib
176125
- key: service.version
177126
value:
178-
stringValue: 0.133.0
127+
stringValue: 0.139.0
179128
startTimeUnixNano: "1000000"
180129
timeUnixNano: "1000000"
181130
isMonotonic: true
182-
- description: Total bytes of memory obtained from the OS (see 'go doc runtime.MemStats.Sys') [alpha]
131+
- description: The scraping was successful
183132
gauge:
184133
dataPoints:
185-
- asDouble: 3.6787464e+07
186-
attributes:
187-
- key: service.instance.id
188-
value:
189-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
190-
- key: service.name
191-
value:
192-
stringValue: otelcol-contrib
193-
- key: service.version
194-
value:
195-
stringValue: 0.133.0
134+
- asDouble: 1
196135
timeUnixNano: "1000000"
197136
metadata:
198137
- key: prometheus.type
199138
value:
200139
stringValue: gauge
201-
name: otelcol_process_runtime_total_sys_memory_bytes
202-
- description: Uptime of the process [alpha]
140+
name: up
141+
- description: Duration of the scrape
142+
gauge:
143+
dataPoints:
144+
- asDouble: 0.008631292
145+
timeUnixNano: "1000000"
146+
metadata:
147+
- key: prometheus.type
148+
value:
149+
stringValue: gauge
150+
name: scrape_duration_seconds
151+
unit: s
152+
- description: The number of samples the target exposed
153+
gauge:
154+
dataPoints:
155+
- asDouble: 9
156+
timeUnixNano: "1000000"
157+
metadata:
158+
- key: prometheus.type
159+
value:
160+
stringValue: gauge
161+
name: scrape_samples_scraped
162+
- description: The number of samples remaining after metric relabeling was applied
163+
gauge:
164+
dataPoints:
165+
- asDouble: 9
166+
timeUnixNano: "1000000"
167+
metadata:
168+
- key: prometheus.type
169+
value:
170+
stringValue: gauge
171+
name: scrape_samples_post_metric_relabeling
172+
- description: The approximate number of new series in this scrape
173+
gauge:
174+
dataPoints:
175+
- asDouble: 9
176+
timeUnixNano: "1000000"
177+
metadata:
178+
- key: prometheus.type
179+
value:
180+
stringValue: gauge
181+
name: scrape_series_added
182+
- description: Total CPU user and system time in seconds [Alpha]
203183
metadata:
204184
- key: prometheus.type
205185
value:
206186
stringValue: counter
207-
name: otelcol_process_uptime
187+
name: otelcol_process_cpu_seconds
208188
sum:
209189
aggregationTemporality: 2
210190
dataPoints:
211-
- asDouble: 6.868990629
191+
- asDouble: 0.2
212192
attributes:
213193
- key: service.instance.id
214194
value:
215-
stringValue: d23001b5-3ac2-46eb-85b6-3e434276b2b7
195+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
216196
- key: service.name
217197
value:
218198
stringValue: otelcol-contrib
219199
- key: service.version
220200
value:
221-
stringValue: 0.133.0
201+
stringValue: 0.139.0
222202
startTimeUnixNano: "1000000"
223203
timeUnixNano: "1000000"
224204
isMonotonic: true
205+
- description: Total physical memory (resident set size) [Alpha]
206+
gauge:
207+
dataPoints:
208+
- asDouble: 1.72855296e+08
209+
attributes:
210+
- key: service.instance.id
211+
value:
212+
stringValue: 5230d18c-f0dc-4ff3-9284-f273297bb543
213+
- key: service.name
214+
value:
215+
stringValue: otelcol-contrib
216+
- key: service.version
217+
value:
218+
stringValue: 0.139.0
219+
timeUnixNano: "1000000"
220+
metadata:
221+
- key: prometheus.type
222+
value:
223+
stringValue: gauge
224+
name: otelcol_process_memory_rss
225225
scope:
226226
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver
227-
version: 0.133.0
227+
version: 0.139.0

0 commit comments

Comments
 (0)