@@ -49,6 +49,10 @@ var inRepoConfigCacheMetrics = struct {
49
49
// How many times have we tried to remove a cached key because its value
50
50
// construction failed?
51
51
evictionsManual * prometheus.CounterVec
52
+ // How many entries are in the cache?
53
+ cacheUsageSize * prometheus.GaugeVec
54
+ // How long does it take for GetProwYAML() to run?
55
+ getProwYAMLDuration * prometheus.HistogramVec
52
56
}{
53
57
lookups : prometheus .NewCounterVec (prometheus.CounterOpts {
54
58
Name : "inRepoConfigCache_lookups" ,
@@ -88,6 +92,21 @@ var inRepoConfigCacheMetrics = struct {
88
92
"org" ,
89
93
"repo" ,
90
94
}),
95
+ cacheUsageSize : prometheus .NewGaugeVec (prometheus.GaugeOpts {
96
+ Name : "inRepoConfigCache_cache_usage_size" ,
97
+ Help : "Size of the cache (how many entries it is holding) by org and repo." ,
98
+ }, []string {
99
+ "org" ,
100
+ "repo" ,
101
+ }),
102
+ getProwYAMLDuration : prometheus .NewHistogramVec (prometheus.HistogramOpts {
103
+ Name : "inRepoConfigCache_GetProwYAML_duration" ,
104
+ Help : "Histogram of seconds spent retrieving the ProwYAML (inrepoconfig), by org and repo." ,
105
+ Buckets : []float64 {0.5 , 1 , 2 , 5 , 10 , 20 , 30 , 60 , 120 , 180 , 300 , 600 },
106
+ }, []string {
107
+ "org" ,
108
+ "repo" ,
109
+ }),
91
110
}
92
111
93
112
func init () {
@@ -96,6 +115,8 @@ func init() {
96
115
prometheus .MustRegister (inRepoConfigCacheMetrics .misses )
97
116
prometheus .MustRegister (inRepoConfigCacheMetrics .evictionsForced )
98
117
prometheus .MustRegister (inRepoConfigCacheMetrics .evictionsManual )
118
+ prometheus .MustRegister (inRepoConfigCacheMetrics .cacheUsageSize )
119
+ prometheus .MustRegister (inRepoConfigCacheMetrics .getProwYAMLDuration )
99
120
}
100
121
101
122
func mkCacheEventCallback (counterVec * prometheus.CounterVec ) cache.EventCallback {
@@ -167,6 +188,47 @@ func NewInRepoConfigCache(
167
188
return nil , err
168
189
}
169
190
191
+ // This records all OrgRepos we've seen so far during the lifetime of the
192
+ // process. The main purpose is to allow reporting of 0 counts for OrgRepos
193
+ // whose keys have been evicted by the lruCache.
194
+ seenOrgRepos := make (map [OrgRepo ]int )
195
+
196
+ cacheSizeMetrics := func () {
197
+ // Record all unique orgRepo combinations we've seen so far.
198
+ for _ , key := range lruCache .Keys () {
199
+ org , repo , err := keyToOrgRepo (key )
200
+ if err != nil {
201
+ // This should only happen if we are deliberately using things
202
+ // other than a CacheKey as the key.
203
+ logrus .Warnf ("programmer error: could not report cache size metrics for a key entry: %v" , err )
204
+ continue
205
+ }
206
+ orgRepo := OrgRepo {org , repo }
207
+ if count , ok := seenOrgRepos [orgRepo ]; ok {
208
+ seenOrgRepos [orgRepo ] = count + 1
209
+ } else {
210
+ seenOrgRepos [orgRepo ] = 1
211
+ }
212
+ }
213
+ // For every single org and repo in the cache, report how many key
214
+ // entries there are.
215
+ for orgRepo , count := range seenOrgRepos {
216
+ inRepoConfigCacheMetrics .cacheUsageSize .WithLabelValues (
217
+ orgRepo .Org , orgRepo .Repo ).Set (float64 (count ))
218
+ // Reset the counter back down to 0 because it may be that by the
219
+ // time of the next interval, the last key for this orgRepo will be
220
+ // evicted. At that point we still want to report a count of 0.
221
+ seenOrgRepos [orgRepo ] = 0
222
+ }
223
+ }
224
+
225
+ go func () {
226
+ for {
227
+ cacheSizeMetrics ()
228
+ time .Sleep (30 * time .Second )
229
+ }
230
+ }()
231
+
170
232
cache := & InRepoConfigCache {
171
233
lruCache ,
172
234
// Know how to default the retrieved ProwYAML values against the latest Config.
@@ -265,6 +327,12 @@ func (cache *InRepoConfigCache) GetPostsubmits(identifier string, baseSHAGetter
265
327
266
328
// GetProwYAML returns the ProwYAML value stored in the InRepoConfigCache.
267
329
func (cache * InRepoConfigCache ) GetProwYAML (identifier string , baseSHAGetter RefGetter , headSHAGetters ... RefGetter ) (* ProwYAML , error ) {
330
+ timeGetProwYAML := time .Now ()
331
+ defer func () {
332
+ orgRepo := NewOrgRepo (identifier )
333
+ inRepoConfigCacheMetrics .getProwYAMLDuration .WithLabelValues (orgRepo .Org , orgRepo .Repo ).Observe ((float64 (time .Since (timeGetProwYAML ).Seconds ())))
334
+ }()
335
+
268
336
c := cache .configAgent .Config ()
269
337
270
338
prowYAML , err := cache .getProwYAML (c .getProwYAML , identifier , baseSHAGetter , headSHAGetters ... )
0 commit comments