Skip to content

Commit deff5b5

Browse files
prometheusremotewriteexpoter: add WAL bytes read/write metrics. (open-telemetry#40586)
partly fixes open-telemetry#39556. ```zsh # HELP otelcol_exporter_prometheusremotewrite_wal_bytes_read Total number of bytes read from the WAL # TYPE otelcol_exporter_prometheusremotewrite_wal_bytes_read counter otelcol_exporter_prometheusremotewrite_wal_bytes_read{service_instance_id="ee4cd5c5-5773-404b-a573-df85413a9adc",service_name="otelcontribcol",service_version="0.128.0-dev"} 224 # HELP otelcol_exporter_prometheusremotewrite_wal_bytes_written Total number of bytes written to the WAL # TYPE otelcol_exporter_prometheusremotewrite_wal_bytes_written counter otelcol_exporter_prometheusremotewrite_wal_bytes_written{service_instance_id="ee4cd5c5-5773-404b-a573-df85413a9adc",service_name="otelcontribcol",service_version="0.128.0-dev"} 112 ```
1 parent 263f2ed commit deff5b5

File tree

9 files changed

+135
-3
lines changed

9 files changed

+135
-3
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: prometheusremotewriteexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: |
11+
Adds WAL bytes read/write metrics to the Prometheus Remote Write Exporter. The new metrics are:
12+
- `otelcol_exporter_prometheusremotewrite_wal_bytes_written`: The total number of bytes written to the WAL.
13+
- `otelcol_exporter_prometheusremotewrite_wal_bytes_read`: The total number of bytes reads from the WAL.
14+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
15+
issues: [39556]
16+
17+
# (Optional) One or more lines of additional information to render under the primary note.
18+
# These lines will be padded with 2 spaces and then inserted directly into the document.
19+
# Use pipe (|) for multiline entries.
20+
subtext:
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [user]

exporter/prometheusremotewriteexporter/documentation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ Number of Prometheus time series that were translated from OTel metrics
3838
| ---- | ----------- | ---------- | --------- |
3939
| 1 | Sum | Int | true |
4040

41+
### otelcol_exporter_prometheusremotewrite_wal_bytes_read
42+
43+
Total number of bytes read from the WAL
44+
45+
| Unit | Metric Type | Value Type | Monotonic |
46+
| ---- | ----------- | ---------- | --------- |
47+
| By | Sum | Int | true |
48+
49+
### otelcol_exporter_prometheusremotewrite_wal_bytes_written
50+
51+
Total number of bytes written to the WAL
52+
53+
| Unit | Metric Type | Value Type | Monotonic |
54+
| ---- | ----------- | ---------- | --------- |
55+
| By | Sum | Int | true |
56+
4157
### otelcol_exporter_prometheusremotewrite_wal_read_latency
4258

4359
Response latency in ms for the WAL reads.

exporter/prometheusremotewriteexporter/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (prwe *prwExporter) handleExport(ctx context.Context, tsMap map[string]*pro
293293
// Otherwise the WAL is enabled, and just persist the requests to the WAL
294294
prwe.wal.telemetry.recordWALWrites(ctx)
295295
start := time.Now()
296-
err = prwe.wal.persistToWAL(requests)
296+
err = prwe.wal.persistToWAL(ctx, requests)
297297
duration := time.Since(start)
298298
prwe.wal.telemetry.recordWALWriteLatency(ctx, duration.Milliseconds())
299299
if err != nil {

exporter/prometheusremotewriteexporter/internal/metadata/generated_telemetry.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/prometheusremotewriteexporter/internal/metadatatest/generated_telemetrytest.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/prometheusremotewriteexporter/internal/metadatatest/generated_telemetrytest_test.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/prometheusremotewriteexporter/metadata.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,18 @@ telemetry:
8888
histogram:
8989
value_type: int
9090
bucket_boundaries: [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]
91+
exporter_prometheusremotewrite_wal_bytes_written:
92+
enabled: true
93+
description: Total number of bytes written to the WAL
94+
unit: "By"
95+
sum:
96+
value_type: int
97+
monotonic: true
98+
99+
exporter_prometheusremotewrite_wal_bytes_read:
100+
enabled: true
101+
description: Total number of bytes read from the WAL
102+
unit: "By"
103+
sum:
104+
value_type: int
105+
monotonic: true

exporter/prometheusremotewriteexporter/wal.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type prwWalTelemetry interface {
3131
recordWALReadLatency(ctx context.Context, durationMs int64)
3232
recordWALReads(ctx context.Context)
3333
recordWALReadsFailures(ctx context.Context)
34+
recordWALBytesWritten(ctx context.Context, bytes int)
35+
recordWALBytesRead(ctx context.Context, bytes int)
3436
}
3537

3638
type prwWalTelemetryOTel struct {
@@ -62,6 +64,14 @@ func (p *prwWalTelemetryOTel) recordWALReadsFailures(ctx context.Context) {
6264
p.telemetryBuilder.ExporterPrometheusremotewriteWalReadsFailures.Add(ctx, 1, metric.WithAttributes(p.otelAttrs...))
6365
}
6466

67+
func (p *prwWalTelemetryOTel) recordWALBytesWritten(ctx context.Context, bytes int) {
68+
p.telemetryBuilder.ExporterPrometheusremotewriteWalBytesWritten.Add(ctx, int64(bytes), metric.WithAttributes(p.otelAttrs...))
69+
}
70+
71+
func (p *prwWalTelemetryOTel) recordWALBytesRead(ctx context.Context, bytes int) {
72+
p.telemetryBuilder.ExporterPrometheusremotewriteWalBytesRead.Add(ctx, int64(bytes), metric.WithAttributes(p.otelAttrs...))
73+
}
74+
6575
func newPRWWalTelemetry(set exporter.Settings) (prwWalTelemetry, error) {
6676
telemetryBuilder, err := metadata.NewTelemetryBuilder(set.TelemetrySettings)
6777
if err != nil {
@@ -365,7 +375,7 @@ func (prweWAL *prweWAL) exportThenFrontTruncateWAL(ctx context.Context, reqL []*
365375
// persistToWAL is the routine that'll be hooked into the exporter's receiving side and it'll
366376
// write them to the Write-Ahead-Log so that shutdowns won't lose data, and that the routine that
367377
// reads from the WAL can then process the previously serialized requests.
368-
func (prweWAL *prweWAL) persistToWAL(requests []*prompb.WriteRequest) error {
378+
func (prweWAL *prweWAL) persistToWAL(ctx context.Context, requests []*prompb.WriteRequest) error {
369379
prweWAL.mu.Lock()
370380
defer prweWAL.mu.Unlock()
371381

@@ -376,6 +386,7 @@ func (prweWAL *prweWAL) persistToWAL(requests []*prompb.WriteRequest) error {
376386
if err != nil {
377387
return err
378388
}
389+
prweWAL.telemetry.recordWALBytesWritten(ctx, len(protoBlob))
379390
wIndex := prweWAL.wWALIndex.Add(1)
380391
batch.Write(wIndex, protoBlob)
381392
}
@@ -414,6 +425,7 @@ func (prweWAL *prweWAL) readPrompbFromWAL(ctx context.Context, index uint64) (wr
414425
protoBlob, err = prweWAL.wal.Read(index)
415426
duration := time.Since(start)
416427
prweWAL.telemetry.recordWALReadLatency(ctx, duration.Milliseconds())
428+
prweWAL.telemetry.recordWALBytesRead(ctx, len(protoBlob))
417429
if err == nil { // The read succeeded.
418430
req := new(prompb.WriteRequest)
419431
if err = proto.Unmarshal(protoBlob, req); err != nil {

exporter/prometheusremotewriteexporter/wal_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func TestWAL_persist(t *testing.T) {
151151
assert.NoError(t, pwal.stop())
152152
})
153153

154-
require.NoError(t, pwal.persistToWAL(reqL))
154+
require.NoError(t, pwal.persistToWAL(ctx, reqL))
155155

156156
// 2. Read all the entries from the WAL itself, guided by the indices available,
157157
// and ensure that they are exactly in order as we'd expect them.
@@ -295,6 +295,9 @@ func TestWALWrite_Telemetry(t *testing.T) {
295295

296296
_, err = tel.GetMetric("otelcol_exporter_prometheusremotewrite_wal_write_latency")
297297
require.NoError(t, err)
298+
299+
_, err = tel.GetMetric("otelcol_exporter_prometheusremotewrite_wal_bytes_written")
300+
require.NoError(t, err)
298301
}
299302

300303
func TestWALRead_Telemetry(t *testing.T) {
@@ -373,4 +376,7 @@ func TestWALRead_Telemetry(t *testing.T) {
373376

374377
_, err = tel.GetMetric("otelcol_exporter_prometheusremotewrite_wal_read_latency")
375378
require.NoError(t, err)
379+
380+
_, err = tel.GetMetric("otelcol_exporter_prometheusremotewrite_wal_bytes_read")
381+
require.NoError(t, err)
376382
}

0 commit comments

Comments
 (0)