Skip to content

Commit

Permalink
Add metrics for WriteRequest calls (#2988)
Browse files Browse the repository at this point in the history
  • Loading branch information
umanwizard authored Oct 7, 2024
1 parent 95e5ded commit bacf584
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions reporter/parca_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ type ParcaReporter struct {

// Metrics that we have seen via ReportMetrics
otelLibraryMetrics map[string]prometheus.Metric

// Our own metrics
sampleWriteRequestBytes prometheus.Counter
stacktraceWriteRequestBytes prometheus.Counter
}

// hashString is a helper function for LRUs that use string as a key.
Expand Down Expand Up @@ -354,7 +358,7 @@ func (r *ParcaReporter) ReportMetrics(_ uint32, ids []uint32, values []int64) {
Help: field.Desc,
})
r.reg.MustRegister(g)
m = g
m = g
case metrics.MetricTypeCounter:
c := prometheus.NewCounter(prometheus.CounterOpts{
Name: f,
Expand All @@ -367,7 +371,7 @@ func (r *ParcaReporter) ReportMetrics(_ uint32, ids []uint32, values []int64) {
log.Warnf("Unknown metric type: %d", field.Type)
continue
}
r.otelLibraryMetrics[f] = m
r.otelLibraryMetrics[f] = m
}
if counter, ok := m.(prometheus.Counter); ok {
counter.Add(float64(val))
Expand Down Expand Up @@ -465,6 +469,18 @@ func New(
return nil, err
}

sampleWriteRequestBytes := prometheus.NewCounter(prometheus.CounterOpts{
Name: "sample_write_request_bytes",
Help: "the total number of bytes written in WriteRequest calls for sample records",
})
stacktraceWriteRequestBytes := prometheus.NewCounter(prometheus.CounterOpts{
Name: "stacktrace_write_request_bytes",
Help: "the total number of bytes written in WriteRequest calls for stacktrace records",
})

reg.MustRegister(sampleWriteRequestBytes)
reg.MustRegister(stacktraceWriteRequestBytes)

r := &ParcaReporter{
stopSignal: make(chan libpf.Void),
client: nil,
Expand All @@ -488,8 +504,10 @@ func New(
cmp,
sysMeta,
},
reg: reg,
otelLibraryMetrics: make(map[string]prometheus.Metric),
reg: reg,
otelLibraryMetrics: make(map[string]prometheus.Metric),
sampleWriteRequestBytes: sampleWriteRequestBytes,
stacktraceWriteRequestBytes: stacktraceWriteRequestBytes,
}

r.client = client
Expand Down Expand Up @@ -588,6 +606,7 @@ func (r *ParcaReporter) reportDataToBackend(ctx context.Context, buf *bytes.Buff
}); err != nil {
return err
}
r.sampleWriteRequestBytes.Add(float64(buf.Len()))

log.Debugf("Sent profile with %d samples", record.NumRows())

Expand Down Expand Up @@ -662,6 +681,7 @@ func (r *ParcaReporter) reportDataToBackend(ctx context.Context, buf *bytes.Buff
}); err != nil {
return err
}
r.stacktraceWriteRequestBytes.Add(float64(buf.Len()))

return client.CloseSend()
}
Expand Down

0 comments on commit bacf584

Please sign in to comment.