Skip to content

Commit 68cce89

Browse files
authored
Expose prometheus HELP information (#1107)
* expose prometheus HELP information * add help text as description for otel exporters
1 parent bd7b5f5 commit 68cce89

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

docs/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Following is the supported API format for prometheus encode:
1717
counter: monotonically increasing counter whose value can only increase
1818
histogram: counts samples in configurable buckets
1919
agg_histogram: counts samples in configurable buckets, pre-aggregated via an Aggregate stage
20+
help: the metric help text
2021
filters: a list of criteria to filter entries by
2122
key: the key to match and filter by
2223
value: the value to match and filter by
@@ -457,6 +458,7 @@ Following is the supported API format for writing metrics to an OpenTelemetry co
457458
counter: monotonically increasing counter whose value can only increase
458459
histogram: counts samples in configurable buckets
459460
agg_histogram: counts samples in configurable buckets, pre-aggregated via an Aggregate stage
461+
help: the metric help text
460462
filters: a list of criteria to filter entries by
461463
key: the key to match and filter by
462464
value: the value to match and filter by

pkg/api/encode_prom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type PromConnectionInfo struct {
4949
type MetricsItem struct {
5050
Name string `yaml:"name" json:"name" doc:"the metric name"`
5151
Type MetricEncodeOperationEnum `yaml:"type" json:"type" doc:"(enum) one of the following:"`
52+
Help string `yaml:"help,omitempty" json:"help,omitempty" doc:"the metric help text"`
5253
Filters []MetricsFilter `yaml:"filters" json:"filters" doc:"a list of criteria to filter entries by"`
5354
ValueKey string `yaml:"valueKey" json:"valueKey" doc:"entry key from which to resolve metric value"`
5455
Labels []string `yaml:"labels" json:"labels" doc:"labels to be associated with the metric"`

pkg/pipeline/encode/encode_prom.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,25 @@ func (e *Prometheus) Cleanup(cleanupFunc interface{}) {
116116
}
117117

118118
func (e *Prometheus) addCounter(fullMetricName string, mInfo *metrics.Preprocessed) prometheus.Collector {
119-
counter := prometheus.NewCounterVec(prometheus.CounterOpts{Name: fullMetricName, Help: ""}, mInfo.TargetLabels())
119+
counter := prometheus.NewCounterVec(prometheus.CounterOpts{Name: fullMetricName, Help: mInfo.Help}, mInfo.TargetLabels())
120120
e.metricCommon.AddCounter(fullMetricName, counter, mInfo)
121121
return counter
122122
}
123123

124124
func (e *Prometheus) addGauge(fullMetricName string, mInfo *metrics.Preprocessed) prometheus.Collector {
125-
gauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: fullMetricName, Help: ""}, mInfo.TargetLabels())
125+
gauge := prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: fullMetricName, Help: mInfo.Help}, mInfo.TargetLabels())
126126
e.metricCommon.AddGauge(fullMetricName, gauge, mInfo)
127127
return gauge
128128
}
129129

130130
func (e *Prometheus) addHistogram(fullMetricName string, mInfo *metrics.Preprocessed) prometheus.Collector {
131-
histogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{Name: fullMetricName, Help: ""}, mInfo.TargetLabels())
131+
histogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{Name: fullMetricName, Help: mInfo.Help}, mInfo.TargetLabels())
132132
e.metricCommon.AddHist(fullMetricName, histogram, mInfo)
133133
return histogram
134134
}
135135

136136
func (e *Prometheus) addAgghistogram(fullMetricName string, mInfo *metrics.Preprocessed) prometheus.Collector {
137-
agghistogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{Name: fullMetricName, Help: ""}, mInfo.TargetLabels())
137+
agghistogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{Name: fullMetricName, Help: mInfo.Help}, mInfo.TargetLabels())
138138
e.metricCommon.AddAggHist(fullMetricName, agghistogram, mInfo)
139139
return agghistogram
140140
}

pkg/pipeline/encode/opentelemetry/encode_otlpmetrics.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func newEncodeOtlpMetricsWithMeter(ctx context.Context, stageName string, opMetr
154154
mInfo := metrics.Preprocess(mCfg)
155155
switch mCfg.Type {
156156
case api.MetricCounter:
157-
counter, err := meter.Float64Counter(fullMetricName)
157+
counter, err := meter.Float64Counter(fullMetricName, metric.WithDescription(mCfg.Help))
158158
if err != nil {
159159
log.Errorf("error during counter creation: %v", err)
160160
return nil, err
@@ -165,6 +165,7 @@ func newEncodeOtlpMetricsWithMeter(ctx context.Context, stageName string, opMetr
165165
obs := Float64Gauge{observations: make(map[string]Float64GaugeEntry)}
166166
gauge, err := meterFactory.Float64ObservableGauge(
167167
fullMetricName,
168+
metric.WithDescription(mCfg.Help),
168169
metric.WithFloat64Callback(obs.Callback),
169170
)
170171
if err != nil {
@@ -176,12 +177,12 @@ func newEncodeOtlpMetricsWithMeter(ctx context.Context, stageName string, opMetr
176177
var histo metric.Float64Histogram
177178
var err error
178179
if len(mCfg.Buckets) == 0 {
179-
histo, err = meter.Float64Histogram(fullMetricName)
180+
histo, err = meter.Float64Histogram(fullMetricName, metric.WithDescription(mCfg.Help))
180181
} else {
181182
histo, err = meter.Float64Histogram(fullMetricName,
183+
metric.WithDescription(mCfg.Help),
182184
metric.WithExplicitBucketBoundaries(mCfg.Buckets...),
183185
)
184-
185186
}
186187
if err != nil {
187188
log.Errorf("error during histogram creation: %v", err)

0 commit comments

Comments
 (0)