-
Notifications
You must be signed in to change notification settings - Fork 457
/
metadata_fetcher_metrics.go
73 lines (62 loc) · 2.5 KB
/
metadata_fetcher_metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/storegateway/metadata_fetcher_metrics.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.
package storegateway
import (
"github.com/go-kit/log"
dskit_metrics "github.com/grafana/dskit/metrics"
"github.com/prometheus/client_golang/prometheus"
)
// MetadataFetcherMetrics aggregates metrics exported by Thanos MetaFetcher
// and re-exports those aggregates as Mimir metrics.
type MetadataFetcherMetrics struct {
regs *dskit_metrics.TenantRegistries
// Exported metrics, gathered from Thanos MetaFetcher
syncs *prometheus.Desc
syncFailures *prometheus.Desc
syncDuration *prometheus.Desc
synced *prometheus.Desc
}
func NewMetadataFetcherMetrics(logger log.Logger) *MetadataFetcherMetrics {
return &MetadataFetcherMetrics{
regs: dskit_metrics.NewTenantRegistries(logger),
// When mapping new metadata fetcher metrics from Thanos, please remember to add these metrics
// to our internal fetcherMetrics implementation too.
syncs: prometheus.NewDesc(
"cortex_blocks_meta_syncs_total",
"Total blocks metadata synchronization attempts",
nil, nil),
syncFailures: prometheus.NewDesc(
"cortex_blocks_meta_sync_failures_total",
"Total blocks metadata synchronization failures",
nil, nil),
syncDuration: prometheus.NewDesc(
"cortex_blocks_meta_sync_duration_seconds",
"Duration of the blocks metadata synchronization in seconds",
nil, nil),
synced: prometheus.NewDesc(
"cortex_blocks_meta_synced",
"Reflects current state of synced blocks (over all tenants).",
[]string{"state"}, nil),
}
}
func (m *MetadataFetcherMetrics) AddUserRegistry(user string, reg *prometheus.Registry) {
m.regs.AddTenantRegistry(user, reg)
}
func (m *MetadataFetcherMetrics) RemoveUserRegistry(user string) {
m.regs.RemoveTenantRegistry(user, false)
}
func (m *MetadataFetcherMetrics) Describe(out chan<- *prometheus.Desc) {
out <- m.syncs
out <- m.syncFailures
out <- m.syncDuration
out <- m.synced
}
func (m *MetadataFetcherMetrics) Collect(out chan<- prometheus.Metric) {
data := m.regs.BuildMetricFamiliesPerTenant()
data.SendSumOfCounters(out, m.syncs, "blocks_meta_syncs_total")
data.SendSumOfCounters(out, m.syncFailures, "blocks_meta_sync_failures_total")
data.SendSumOfHistograms(out, m.syncDuration, "blocks_meta_sync_duration_seconds")
data.SendSumOfGaugesWithLabels(out, m.synced, "blocks_meta_synced", "state")
}