Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pkg/metrics/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/storage/remote"

pyroscopemodel "github.com/grafana/pyroscope/pkg/model"
"github.com/grafana/pyroscope/pkg/tenant"
)

Expand Down Expand Up @@ -67,7 +68,20 @@ func (e *StaticExporter) Send(tenantId string, data []prompb.TimeSeries) error {
level.Error(e.logger).Log("msg", "unable to store prompb.WriteRequest", "err", err)
return
}
e.metrics.seriesSent.WithLabelValues(tenantId).Add(float64(len(data)))
seriesByRuleID := make(map[string]int)
for _, ts := range data {
ruleID := "unknown"
for _, l := range ts.Labels {
if l.Name == pyroscopemodel.RuleIDLabel {
ruleID = l.Value
break
}
}
seriesByRuleID[ruleID]++
}
for ruleID, count := range seriesByRuleID {
e.metrics.seriesSent.WithLabelValues(tenantId, ruleID).Add(float64(count))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you estimate the extra cardinality that this will add?

Copy link
Contributor Author

@alsoba13 alsoba13 Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cardinality could be described as "total number of tenants using recording rules times the number of instances of compaction workers in that cell". After the change, we would describe as "total number of rules defined by all the tenants times the number of instances of compaction workers in that cell".

So it's safe to talk about a x10-x50 increase in cardinality. In the case of ops we would go from 32 to 320 series

}
}(data)
return nil
}
Expand Down Expand Up @@ -124,7 +138,7 @@ func newMetrics(reg prometheus.Registerer, remoteUrl string) *clientMetrics {
Subsystem: "metrics_exporter",
Name: "series_sent_total",
Help: "Number of series sent on remote_write.",
}, []string{"tenant"}),
}, []string{"tenant", "rule_id"}),
}
if reg != nil {
remoteUrlReg := prometheus.WrapRegistererWith(prometheus.Labels{"url": remoteUrl}, reg)
Expand Down
6 changes: 3 additions & 3 deletions pkg/model/recording_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type RecordingRule struct {

const (
metricNamePrefix = "profiles_recorded_"
ruleIdLabel = "profiles_rule_id"
RuleIDLabel = "profiles_rule_id"
)

var uniqueLabels = map[string]bool{
ruleIdLabel: true,
RuleIDLabel: true,
prometheusmodel.MetricNameLabel: true,
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func newRecordingRuleWithBuilder(rule *settingsv1.RecordingRule, sb *labels.Scra
// trust rule.MetricName
sb.Add(prometheusmodel.MetricNameLabel, rule.MetricName)
// Inject recording rule Id
sb.Add(ruleIdLabel, rule.Id)
sb.Add(RuleIDLabel, rule.Id)

sb.Sort()

Expand Down