Skip to content

Commit b64980a

Browse files
committed
address comments and update changelog
Signed-off-by: Ben Ye <[email protected]>
1 parent 9214545 commit b64980a

File tree

6 files changed

+108
-94
lines changed

6 files changed

+108
-94
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [CHANGE] Experimental TSDB: compact head when opening TSDB. This should only affect ingester startup after it was unable to compact head in previous run. #2870
2121
* [CHANGE] Metric `cortex_overrides_last_reload_successful` has been renamed to `cortex_runtime_config_last_reload_successful`. #2874
2222
* [CHANGE] HipChat support has been removed from the alertmanager (because removed from the Prometheus upstream too). #2902
23+
* [CHANGE] Add constant label `name` to metric `cortex_cache_request_duration_seconds`. #2903
2324
* [FEATURE] Introduced `ruler.for-outage-tolerance`, Max time to tolerate outage for restoring "for" state of alert. #2783
2425
* [FEATURE] Introduced `ruler.for-grace-period`, Minimum duration between alert and restored "for" state. This is maintained only for alerts with configured "for" time greater than grace period. #2783
2526
* [FEATURE] Introduced `ruler.resend-delay`, Minimum amount of time to wait before resending an alert to Alertmanager. #2783

pkg/chunk/cache/background.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ func NewBackground(name string, cfg BackgroundConfig, cache Cache, reg prometheu
4747
quit: make(chan struct{}),
4848
bgWrites: make(chan backgroundWrite, cfg.WriteBackBuffer),
4949
name: name,
50-
droppedWriteBack: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
51-
Namespace: "cortex",
52-
Name: "cache_dropped_background_writes_total",
53-
Help: "Total count of dropped write backs to cache.",
54-
}, []string{"name"}).WithLabelValues(name),
55-
56-
queueLength: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
57-
Namespace: "cortex",
58-
Name: "cache_background_queue_length",
59-
Help: "Length of the cache background write queue.",
60-
}, []string{"name"}).WithLabelValues(name),
50+
droppedWriteBack: promauto.With(reg).NewCounter(prometheus.CounterOpts{
51+
Namespace: "cortex",
52+
Name: "cache_dropped_background_writes_total",
53+
Help: "Total count of dropped write backs to cache.",
54+
ConstLabels: prometheus.Labels{"name": name},
55+
}),
56+
57+
queueLength: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
58+
Namespace: "cortex",
59+
Name: "cache_background_queue_length",
60+
Help: "Length of the cache background write queue.",
61+
ConstLabels: prometheus.Labels{"name": name},
62+
}),
6163
}
6264

6365
c.wg.Add(cfg.WriteBackGoroutines)

pkg/chunk/cache/fifo_cache.go

Lines changed: 63 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -114,62 +114,69 @@ func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, l
114114
entries: make(map[string]*list.Element),
115115
lru: list.New(),
116116

117-
// TODO(bwplotka): There might be simple cache.Cache wrapper for those.
118-
entriesAdded: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
119-
Namespace: "querier",
120-
Subsystem: "cache",
121-
Name: "added_total",
122-
Help: "The total number of Put calls on the cache",
123-
}, []string{"cache"}).WithLabelValues(name),
124-
125-
entriesAddedNew: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
126-
Namespace: "querier",
127-
Subsystem: "cache",
128-
Name: "added_new_total",
129-
Help: "The total number of new entries added to the cache",
130-
}, []string{"cache"}).WithLabelValues(name),
131-
132-
entriesEvicted: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
133-
Namespace: "querier",
134-
Subsystem: "cache",
135-
Name: "evicted_total",
136-
Help: "The total number of evicted entries",
137-
}, []string{"cache"}).WithLabelValues(name),
138-
139-
entriesCurrent: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
140-
Namespace: "querier",
141-
Subsystem: "cache",
142-
Name: "entries",
143-
Help: "The total number of entries",
144-
}, []string{"cache"}).WithLabelValues(name),
145-
146-
totalGets: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
147-
Namespace: "querier",
148-
Subsystem: "cache",
149-
Name: "gets_total",
150-
Help: "The total number of Get calls",
151-
}, []string{"cache"}).WithLabelValues(name),
152-
153-
totalMisses: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
154-
Namespace: "querier",
155-
Subsystem: "cache",
156-
Name: "misses_total",
157-
Help: "The total number of Get calls that had no valid entry",
158-
}, []string{"cache"}).WithLabelValues(name),
159-
160-
staleGets: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
161-
Namespace: "querier",
162-
Subsystem: "cache",
163-
Name: "stale_gets_total",
164-
Help: "The total number of Get calls that had an entry which expired",
165-
}, []string{"cache"}).WithLabelValues(name),
166-
167-
memoryBytes: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
168-
Namespace: "querier",
169-
Subsystem: "cache",
170-
Name: "memory_bytes",
171-
Help: "The current cache size in bytes",
172-
}, []string{"cache"}).WithLabelValues(name),
117+
entriesAdded: promauto.With(reg).NewCounter(prometheus.CounterOpts{
118+
Namespace: "querier",
119+
Subsystem: "cache",
120+
Name: "added_total",
121+
Help: "The total number of Put calls on the cache",
122+
ConstLabels: prometheus.Labels{"cache": name},
123+
}),
124+
125+
entriesAddedNew: promauto.With(reg).NewCounter(prometheus.CounterOpts{
126+
Namespace: "querier",
127+
Subsystem: "cache",
128+
Name: "added_new_total",
129+
Help: "The total number of new entries added to the cache",
130+
ConstLabels: prometheus.Labels{"cache": name},
131+
}),
132+
133+
entriesEvicted: promauto.With(reg).NewCounter(prometheus.CounterOpts{
134+
Namespace: "querier",
135+
Subsystem: "cache",
136+
Name: "evicted_total",
137+
Help: "The total number of evicted entries",
138+
ConstLabels: prometheus.Labels{"cache": name},
139+
}),
140+
141+
entriesCurrent: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
142+
Namespace: "querier",
143+
Subsystem: "cache",
144+
Name: "entries",
145+
Help: "The total number of entries",
146+
ConstLabels: prometheus.Labels{"cache": name},
147+
}),
148+
149+
totalGets: promauto.With(reg).NewCounter(prometheus.CounterOpts{
150+
Namespace: "querier",
151+
Subsystem: "cache",
152+
Name: "gets_total",
153+
Help: "The total number of Get calls",
154+
ConstLabels: prometheus.Labels{"cache": name},
155+
}),
156+
157+
totalMisses: promauto.With(reg).NewCounter(prometheus.CounterOpts{
158+
Namespace: "querier",
159+
Subsystem: "cache",
160+
Name: "misses_total",
161+
Help: "The total number of Get calls that had no valid entry",
162+
ConstLabels: prometheus.Labels{"cache": name},
163+
}),
164+
165+
staleGets: promauto.With(reg).NewCounter(prometheus.CounterOpts{
166+
Namespace: "querier",
167+
Subsystem: "cache",
168+
Name: "stale_gets_total",
169+
Help: "The total number of Get calls that had an entry which expired",
170+
ConstLabels: prometheus.Labels{"cache": name},
171+
}),
172+
173+
memoryBytes: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
174+
Namespace: "querier",
175+
Subsystem: "cache",
176+
Name: "memory_bytes",
177+
Help: "The current cache size in bytes",
178+
ConstLabels: prometheus.Labels{"cache": name},
179+
}),
173180
}
174181
}
175182

pkg/chunk/cache/instrumented.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ func Instrument(name string, cache Cache, reg prometheus.Registerer) Cache {
1919
// Cached chunks are generally in the KBs, but cached index can
2020
// get big. Histogram goes from 1KB to 4MB.
2121
// 1024 * 4^(7-1) = 4MB
22-
Buckets: prometheus.ExponentialBuckets(1024, 4, 7),
23-
}, []string{"name", "method"})
22+
Buckets: prometheus.ExponentialBuckets(1024, 4, 7),
23+
ConstLabels: prometheus.Labels{"name": name},
24+
}, []string{"method"})
2425

2526
requestDuration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
2627
Namespace: "cortex",
2728
Name: "cache_request_duration_seconds",
2829
Help: "Total time spent in seconds doing cache requests.",
2930
// Cache requests are very quick: smallest bucket is 16us, biggest is 1s.
30-
Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8),
31+
Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8),
32+
ConstLabels: prometheus.Labels{"name": name},
3133
}, []string{"method", "status_code"})
3234

3335
return &instrumentedCache{
@@ -36,20 +38,22 @@ func Instrument(name string, cache Cache, reg prometheus.Registerer) Cache {
3638

3739
requestDuration: instr.NewHistogramCollector(requestDuration),
3840

39-
fetchedKeys: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
40-
Namespace: "cortex",
41-
Name: "cache_fetched_keys",
42-
Help: "Total count of keys requested from cache.",
43-
}, []string{"name"}).WithLabelValues(name),
44-
45-
hits: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
46-
Namespace: "cortex",
47-
Name: "cache_hits",
48-
Help: "Total count of keys found in cache.",
49-
}, []string{"name"}).WithLabelValues(name),
50-
51-
storedValueSize: valueSize.WithLabelValues(name, "store"),
52-
fetchedValueSize: valueSize.WithLabelValues(name, "fetch"),
41+
fetchedKeys: promauto.With(reg).NewCounter(prometheus.CounterOpts{
42+
Namespace: "cortex",
43+
Name: "cache_fetched_keys",
44+
Help: "Total count of keys requested from cache.",
45+
ConstLabels: prometheus.Labels{"name": name},
46+
}),
47+
48+
hits: promauto.With(reg).NewCounter(prometheus.CounterOpts{
49+
Namespace: "cortex",
50+
Name: "cache_hits",
51+
Help: "Total count of keys found in cache.",
52+
ConstLabels: prometheus.Labels{"name": name},
53+
}),
54+
55+
storedValueSize: valueSize.WithLabelValues("store"),
56+
fetchedValueSize: valueSize.WithLabelValues("fetch"),
5357
}
5458
}
5559

pkg/chunk/cache/memcached.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,17 @@ func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string, reg
6666
Name: "memcache_request_duration_seconds",
6767
Help: "Total time spent in seconds doing memcache requests.",
6868
// Memecache requests are very quick: smallest bucket is 16us, biggest is 1s
69-
Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8),
70-
}, []string{"method", "status_code", "name"})
69+
Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8),
70+
ConstLabels: prometheus.Labels{"name": name},
71+
}, []string{"method", "status_code"})
7172

7273
c := &Memcached{
7374
cfg: cfg,
7475
memcache: client,
7576
name: name,
7677
logger: logger,
7778
requestDuration: observableVecCollector{
78-
v: memcacheRequestDuration.MustCurryWith(prometheus.Labels{
79-
"name": name,
80-
}),
79+
v: memcacheRequestDuration,
8180
},
8281
}
8382

pkg/chunk/cache/memcached_client.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg
101101
provider: dns.NewProvider(logger, dnsProviderRegisterer, dns.GolangResolverType),
102102
quit: make(chan struct{}),
103103

104-
numServers: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
105-
Namespace: "cortex",
106-
Name: "memcache_client_servers",
107-
Help: "The number of memcache servers discovered.",
108-
}, []string{"name"}).WithLabelValues(name),
104+
numServers: promauto.With(r).NewGauge(prometheus.GaugeOpts{
105+
Namespace: "cortex",
106+
Name: "memcache_client_servers",
107+
Help: "The number of memcache servers discovered.",
108+
ConstLabels: prometheus.Labels{"name": name},
109+
}),
109110
}
110111

111112
if len(cfg.Addresses) > 0 {

0 commit comments

Comments
 (0)