14
14
15
15
package prometheus // import "go.opentelemetry.io/otel/exporters/metric/prometheus"
16
16
17
+ // Note that this package does not support a way to export Prometheus
18
+ // Summary data points, removed in PR#1412.
19
+
17
20
import (
18
21
"context"
19
22
"fmt"
@@ -50,10 +53,13 @@ type Exporter struct {
50
53
lock sync.RWMutex
51
54
controller * pull.Controller
52
55
53
- defaultSummaryQuantiles []float64
54
56
defaultHistogramBoundaries []float64
55
57
}
56
58
59
+ // ErrUnsupportedAggregator is returned for unrepresentable aggregator
60
+ // types (e.g., exact).
61
+ var ErrUnsupportedAggregator = fmt .Errorf ("unsupported aggregator type" )
62
+
57
63
var _ http.Handler = & Exporter {}
58
64
59
65
// Config is a set of configs for the tally reporter.
@@ -76,10 +82,6 @@ type Config struct {
76
82
// If not specified the Registry will be used as default.
77
83
Gatherer prometheus.Gatherer
78
84
79
- // DefaultSummaryQuantiles is the default summary quantiles
80
- // to use. Use nil to specify the system-default summary quantiles.
81
- DefaultSummaryQuantiles []float64
82
-
83
85
// DefaultHistogramBoundaries defines the default histogram bucket
84
86
// boundaries.
85
87
DefaultHistogramBoundaries []float64
@@ -104,7 +106,6 @@ func NewExportPipeline(config Config, options ...pull.Option) (*Exporter, error)
104
106
handler : promhttp .HandlerFor (config .Gatherer , promhttp.HandlerOpts {}),
105
107
registerer : config .Registerer ,
106
108
gatherer : config .Gatherer ,
107
- defaultSummaryQuantiles : config .DefaultSummaryQuantiles ,
108
109
defaultHistogramBoundaries : config .DefaultHistogramBoundaries ,
109
110
}
110
111
@@ -167,15 +168,12 @@ func (e *Exporter) Controller() *pull.Controller {
167
168
return e .controller
168
169
}
169
170
171
+ // ExportKindFor implements ExportKindSelector.
170
172
func (e * Exporter ) ExportKindFor (desc * metric.Descriptor , kind aggregation.Kind ) export.ExportKind {
171
- // NOTE: Summary values should use Delta aggregation, then be
172
- // combined into a sliding window, see the TODO below.
173
- // NOTE: Prometheus also supports a "GaugeDelta" exposition format,
174
- // which is expressed as a delta histogram. Need to understand if this
175
- // should be a default behavior for ValueRecorder/ValueObserver.
176
173
return export .CumulativeExportKindSelector ().ExportKindFor (desc , kind )
177
174
}
178
175
176
+ // ServeHTTP implements http.Handler.
179
177
func (e * Exporter ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
180
178
e .handler .ServeHTTP (w , r )
181
179
}
@@ -187,6 +185,7 @@ type collector struct {
187
185
188
186
var _ prometheus.Collector = (* collector )(nil )
189
187
188
+ // Describe implements prometheus.Collector.
190
189
func (c * collector ) Describe (ch chan <- * prometheus.Desc ) {
191
190
c .exp .lock .RLock ()
192
191
defer c .exp .lock .RUnlock ()
@@ -226,18 +225,6 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
226
225
if err := c .exportHistogram (ch , hist , numberKind , desc , labels ); err != nil {
227
226
return fmt .Errorf ("exporting histogram: %w" , err )
228
227
}
229
- } else if dist , ok := agg .(aggregation.Distribution ); ok {
230
- // TODO: summaries values are never being resetted.
231
- // As measurements are recorded, new records starts to have less impact on these summaries.
232
- // We should implement an solution that is similar to the Prometheus Clients
233
- // using a rolling window for summaries could be a solution.
234
- //
235
- // References:
236
- // https://www.robustperception.io/how-does-a-prometheus-summary-work
237
- // https://github.com/prometheus/client_golang/blob/fa4aa9000d2863904891d193dea354d23f3d712a/prometheus/summary.go#L135
238
- if err := c .exportSummary (ch , dist , numberKind , desc , labels ); err != nil {
239
- return fmt .Errorf ("exporting summary: %w" , err )
240
- }
241
228
} else if sum , ok := agg .(aggregation.Sum ); ok && instrumentKind .Monotonic () {
242
229
if err := c .exportMonotonicCounter (ch , sum , numberKind , desc , labels ); err != nil {
243
230
return fmt .Errorf ("exporting monotonic counter: %w" , err )
@@ -250,6 +237,8 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
250
237
if err := c .exportLastValue (ch , lastValue , numberKind , desc , labels ); err != nil {
251
238
return fmt .Errorf ("exporting last value: %w" , err )
252
239
}
240
+ } else {
241
+ return fmt .Errorf ("%w: %s" , ErrUnsupportedAggregator , agg .Kind ())
253
242
}
254
243
return nil
255
244
})
@@ -303,33 +292,6 @@ func (c *collector) exportMonotonicCounter(ch chan<- prometheus.Metric, sum aggr
303
292
return nil
304
293
}
305
294
306
- func (c * collector ) exportSummary (ch chan <- prometheus.Metric , dist aggregation.Distribution , kind number.Kind , desc * prometheus.Desc , labels []string ) error {
307
- count , err := dist .Count ()
308
- if err != nil {
309
- return fmt .Errorf ("error retrieving count: %w" , err )
310
- }
311
-
312
- var sum number.Number
313
- sum , err = dist .Sum ()
314
- if err != nil {
315
- return fmt .Errorf ("error retrieving distribution sum: %w" , err )
316
- }
317
-
318
- quantiles := make (map [float64 ]float64 )
319
- for _ , quantile := range c .exp .defaultSummaryQuantiles {
320
- q , _ := dist .Quantile (quantile )
321
- quantiles [quantile ] = q .CoerceToFloat64 (kind )
322
- }
323
-
324
- m , err := prometheus .NewConstSummary (desc , uint64 (count ), sum .CoerceToFloat64 (kind ), quantiles , labels ... )
325
- if err != nil {
326
- return fmt .Errorf ("error creating constant summary: %w" , err )
327
- }
328
-
329
- ch <- m
330
- return nil
331
- }
332
-
333
295
func (c * collector ) exportHistogram (ch chan <- prometheus.Metric , hist aggregation.Histogram , kind number.Kind , desc * prometheus.Desc , labels []string ) error {
334
296
buckets , err := hist .Histogram ()
335
297
if err != nil {
0 commit comments