@@ -55,25 +55,25 @@ func NewInMemoryIndexCacheWithConfig(logger log.Logger, commonMetrics *storecach
55
55
Name : "thanos_store_index_cache_items_added_total" ,
56
56
Help : "Total number of items that were added to the index cache." ,
57
57
}, []string {"item_type" })
58
- c .added .WithLabelValues (cacheTypePostings )
59
- c .added .WithLabelValues (cacheTypeSeries )
60
- c .added .WithLabelValues (cacheTypeExpandedPostings )
58
+ c .added .WithLabelValues (storecache . CacheTypePostings )
59
+ c .added .WithLabelValues (storecache . CacheTypeSeries )
60
+ c .added .WithLabelValues (storecache . CacheTypeExpandedPostings )
61
61
62
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypePostings , tenancy .DefaultTenant )
63
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypeSeries , tenancy .DefaultTenant )
64
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypeExpandedPostings , tenancy .DefaultTenant )
62
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypePostings , tenancy .DefaultTenant )
63
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypeSeries , tenancy .DefaultTenant )
64
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypeExpandedPostings , tenancy .DefaultTenant )
65
65
66
66
c .overflow = promauto .With (reg ).NewCounterVec (prometheus.CounterOpts {
67
67
Name : "thanos_store_index_cache_items_overflowed_total" ,
68
68
Help : "Total number of items that could not be added to the cache due to being too big." ,
69
69
}, []string {"item_type" })
70
- c .overflow .WithLabelValues (cacheTypePostings )
71
- c .overflow .WithLabelValues (cacheTypeSeries )
72
- c .overflow .WithLabelValues (cacheTypeExpandedPostings )
70
+ c .overflow .WithLabelValues (storecache . CacheTypePostings )
71
+ c .overflow .WithLabelValues (storecache . CacheTypeSeries )
72
+ c .overflow .WithLabelValues (storecache . CacheTypeExpandedPostings )
73
73
74
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypePostings , tenancy .DefaultTenant )
75
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypeSeries , tenancy .DefaultTenant )
76
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypeExpandedPostings , tenancy .DefaultTenant )
74
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypePostings , tenancy .DefaultTenant )
75
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypeSeries , tenancy .DefaultTenant )
76
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypeExpandedPostings , tenancy .DefaultTenant )
77
77
78
78
c .cache = fastcache .New (int (config .MaxSize ))
79
79
level .Info (logger ).Log (
@@ -132,14 +132,14 @@ func copyToKey(l labels.Label) storecache.CacheKeyPostings {
132
132
// StorePostings sets the postings identified by the ulid and label to the value v,
133
133
// if the postings already exists in the cache it is not mutated.
134
134
func (c * InMemoryIndexCache ) StorePostings (blockID ulid.ULID , l labels.Label , v []byte , tenant string ) {
135
- c .commonMetrics .DataSizeBytes .WithLabelValues (cacheTypePostings , tenant ).Observe (float64 (len (v )))
136
- c .set (cacheTypePostings , storecache.CacheKey {Block : blockID .String (), Key : copyToKey (l )}, v )
135
+ c .commonMetrics .DataSizeBytes .WithLabelValues (storecache . CacheTypePostings , tenant ).Observe (float64 (len (v )))
136
+ c .set (storecache . CacheTypePostings , storecache.CacheKey {Block : blockID .String (), Key : copyToKey (l )}, v )
137
137
}
138
138
139
139
// FetchMultiPostings fetches multiple postings - each identified by a label -
140
140
// and returns a map containing cache hits, along with a list of missing keys.
141
141
func (c * InMemoryIndexCache ) FetchMultiPostings (ctx context.Context , blockID ulid.ULID , keys []labels.Label , tenant string ) (hits map [labels.Label ][]byte , misses []labels.Label ) {
142
- timer := prometheus .NewTimer (c .commonMetrics .FetchLatency .WithLabelValues (cacheTypePostings , tenant ))
142
+ timer := prometheus .NewTimer (c .commonMetrics .FetchLatency .WithLabelValues (storecache . CacheTypePostings , tenant ))
143
143
defer timer .ObserveDuration ()
144
144
145
145
hits = map [labels.Label ][]byte {}
@@ -149,8 +149,8 @@ func (c *InMemoryIndexCache) FetchMultiPostings(ctx context.Context, blockID uli
149
149
hit := 0
150
150
for _ , key := range keys {
151
151
if ctx .Err () != nil {
152
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypePostings , tenant ).Add (float64 (requests ))
153
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypePostings , tenant ).Add (float64 (hit ))
152
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypePostings , tenant ).Add (float64 (requests ))
153
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypePostings , tenant ).Add (float64 (hit ))
154
154
return hits , misses
155
155
}
156
156
requests ++
@@ -162,29 +162,29 @@ func (c *InMemoryIndexCache) FetchMultiPostings(ctx context.Context, blockID uli
162
162
163
163
misses = append (misses , key )
164
164
}
165
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypePostings , tenant ).Add (float64 (requests ))
166
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypePostings , tenant ).Add (float64 (hit ))
165
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypePostings , tenant ).Add (float64 (requests ))
166
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypePostings , tenant ).Add (float64 (hit ))
167
167
168
168
return hits , misses
169
169
}
170
170
171
171
// StoreExpandedPostings stores expanded postings for a set of label matchers.
172
172
func (c * InMemoryIndexCache ) StoreExpandedPostings (blockID ulid.ULID , matchers []* labels.Matcher , v []byte , tenant string ) {
173
- c .commonMetrics .DataSizeBytes .WithLabelValues (cacheTypeExpandedPostings , tenant ).Observe (float64 (len (v )))
174
- c .set (cacheTypeExpandedPostings , storecache.CacheKey {Block : blockID .String (), Key : storecache .CacheKeyExpandedPostings (storecache .LabelMatchersToString (matchers ))}, v )
173
+ c .commonMetrics .DataSizeBytes .WithLabelValues (storecache . CacheTypeExpandedPostings , tenant ).Observe (float64 (len (v )))
174
+ c .set (storecache . CacheTypeExpandedPostings , storecache.CacheKey {Block : blockID .String (), Key : storecache .CacheKeyExpandedPostings (storecache .LabelMatchersToString (matchers ))}, v )
175
175
}
176
176
177
177
// FetchExpandedPostings fetches expanded postings and returns cached data and a boolean value representing whether it is a cache hit or not.
178
178
func (c * InMemoryIndexCache ) FetchExpandedPostings (ctx context.Context , blockID ulid.ULID , matchers []* labels.Matcher , tenant string ) ([]byte , bool ) {
179
- timer := prometheus .NewTimer (c .commonMetrics .FetchLatency .WithLabelValues (cacheTypeExpandedPostings , tenant ))
179
+ timer := prometheus .NewTimer (c .commonMetrics .FetchLatency .WithLabelValues (storecache . CacheTypeExpandedPostings , tenant ))
180
180
defer timer .ObserveDuration ()
181
181
182
182
if ctx .Err () != nil {
183
183
return nil , false
184
184
}
185
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypeExpandedPostings , tenant ).Inc ()
185
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypeExpandedPostings , tenant ).Inc ()
186
186
if b , ok := c .get (storecache.CacheKey {Block : blockID .String (), Key : storecache .CacheKeyExpandedPostings (storecache .LabelMatchersToString (matchers ))}); ok {
187
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypeExpandedPostings , tenant ).Inc ()
187
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypeExpandedPostings , tenant ).Inc ()
188
188
return b , true
189
189
}
190
190
return nil , false
@@ -193,14 +193,14 @@ func (c *InMemoryIndexCache) FetchExpandedPostings(ctx context.Context, blockID
193
193
// StoreSeries sets the series identified by the ulid and id to the value v,
194
194
// if the series already exists in the cache it is not mutated.
195
195
func (c * InMemoryIndexCache ) StoreSeries (blockID ulid.ULID , id storage.SeriesRef , v []byte , tenant string ) {
196
- c .commonMetrics .DataSizeBytes .WithLabelValues (cacheTypeSeries , tenant ).Observe (float64 (len (v )))
197
- c .set (cacheTypeSeries , storecache.CacheKey {Block : blockID .String (), Key : storecache .CacheKeySeries (id )}, v )
196
+ c .commonMetrics .DataSizeBytes .WithLabelValues (storecache . CacheTypeSeries , tenant ).Observe (float64 (len (v )))
197
+ c .set (storecache . CacheTypeSeries , storecache.CacheKey {Block : blockID .String (), Key : storecache .CacheKeySeries (id )}, v )
198
198
}
199
199
200
200
// FetchMultiSeries fetches multiple series - each identified by ID - from the cache
201
201
// and returns a map containing cache hits, along with a list of missing IDs.
202
202
func (c * InMemoryIndexCache ) FetchMultiSeries (ctx context.Context , blockID ulid.ULID , ids []storage.SeriesRef , tenant string ) (hits map [storage.SeriesRef ][]byte , misses []storage.SeriesRef ) {
203
- timer := prometheus .NewTimer (c .commonMetrics .FetchLatency .WithLabelValues (cacheTypeSeries , tenant ))
203
+ timer := prometheus .NewTimer (c .commonMetrics .FetchLatency .WithLabelValues (storecache . CacheTypeSeries , tenant ))
204
204
defer timer .ObserveDuration ()
205
205
206
206
hits = map [storage.SeriesRef ][]byte {}
@@ -210,8 +210,8 @@ func (c *InMemoryIndexCache) FetchMultiSeries(ctx context.Context, blockID ulid.
210
210
hit := 0
211
211
for _ , id := range ids {
212
212
if ctx .Err () != nil {
213
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypeSeries , tenant ).Add (float64 (requests ))
214
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypeSeries , tenant ).Add (float64 (hit ))
213
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypeSeries , tenant ).Add (float64 (requests ))
214
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypeSeries , tenant ).Add (float64 (hit ))
215
215
return hits , misses
216
216
}
217
217
requests ++
@@ -223,8 +223,8 @@ func (c *InMemoryIndexCache) FetchMultiSeries(ctx context.Context, blockID ulid.
223
223
224
224
misses = append (misses , id )
225
225
}
226
- c .commonMetrics .RequestTotal .WithLabelValues (cacheTypeSeries , tenant ).Add (float64 (requests ))
227
- c .commonMetrics .HitsTotal .WithLabelValues (cacheTypeSeries , tenant ).Add (float64 (hit ))
226
+ c .commonMetrics .RequestTotal .WithLabelValues (storecache . CacheTypeSeries , tenant ).Add (float64 (requests ))
227
+ c .commonMetrics .HitsTotal .WithLabelValues (storecache . CacheTypeSeries , tenant ).Add (float64 (hit ))
228
228
229
229
return hits , misses
230
230
}
0 commit comments