MCPcopy Create free account
hub / github.com/coder/coder / NewMetricsAggregator

Function NewMetricsAggregator

coderd/prometheusmetrics/aggregator.go:155–218  ·  view source on GitHub ↗
(logger slog.Logger, registerer prometheus.Registerer, duration time.Duration, aggregateByLabels []string, options ...func(*MetricsAggregator))

Source from the content-addressed store, hash-verified

153}
154
155func NewMetricsAggregator(logger slog.Logger, registerer prometheus.Registerer, duration time.Duration, aggregateByLabels []string, options ...func(*MetricsAggregator)) (*MetricsAggregator, error) {
156 metricsCleanupInterval := defaultMetricsCleanupInterval
157 if duration > 0 {
158 metricsCleanupInterval = duration
159 }
160
161 storeSizeGauge := prometheus.NewGauge(prometheus.GaugeOpts{
162 Namespace: "coderd",
163 Subsystem: "prometheusmetrics",
164 Name: "metrics_aggregator_store_size",
165 Help: "The number of metrics stored in the aggregator",
166 })
167 err := registerer.Register(storeSizeGauge)
168 if err != nil {
169 return nil, err
170 }
171
172 updateHistogram := prometheus.NewHistogram(prometheus.HistogramOpts{
173 Namespace: "coderd",
174 Subsystem: "prometheusmetrics",
175 Name: "metrics_aggregator_execution_update_seconds",
176 Help: "Histogram for duration of metrics aggregator update in seconds.",
177 Buckets: []float64{0.001, 0.005, 0.010, 0.025, 0.050, 0.100, 0.500, 1, 5, 10, 30},
178 })
179 err = registerer.Register(updateHistogram)
180 if err != nil {
181 return nil, err
182 }
183
184 cleanupHistogram := prometheus.NewHistogram(prometheus.HistogramOpts{
185 Namespace: "coderd",
186 Subsystem: "prometheusmetrics",
187 Name: "metrics_aggregator_execution_cleanup_seconds",
188 Help: "Histogram for duration of metrics aggregator cleanup in seconds.",
189 Buckets: []float64{0.001, 0.005, 0.010, 0.025, 0.050, 0.100, 0.500, 1, 5, 10, 30},
190 })
191 err = registerer.Register(cleanupHistogram)
192 if err != nil {
193 return nil, err
194 }
195
196 ma := &MetricsAggregator{
197 log: logger.Named(loggerName),
198 metricsCleanupInterval: metricsCleanupInterval,
199 clock: quartz.NewReal(),
200
201 store: map[metricKey]annotatedMetric{},
202
203 collectCh: make(chan (chan []prometheus.Metric), sizeCollectCh),
204 updateCh: make(chan updateRequest, sizeUpdateCh),
205
206 storeSizeGauge: storeSizeGauge,
207 updateHistogram: updateHistogram,
208 cleanupHistogram: cleanupHistogram,
209
210 aggregateByLabels: aggregateByLabels,
211 }
212

Callers 7

TestLabelsAggregationFunction · 0.92
benchmarkRunnerFunction · 0.92
enablePrometheusFunction · 0.92
TestDescCache_DescExpireFunction · 0.85

Calls 2

NamedMethod · 0.80
RegisterMethod · 0.45

Tested by 6

TestLabelsAggregationFunction · 0.74
benchmarkRunnerFunction · 0.74
TestDescCache_DescExpireFunction · 0.68