@@ -10,6 +10,7 @@ import (
10
10
"github.com/moby/buildkit/identity"
11
11
"github.com/moby/buildkit/util/bklog"
12
12
digest "github.com/opencontainers/go-digest"
13
+ "github.com/sirupsen/logrus"
13
14
)
14
15
15
16
// NewInMemoryCacheManager creates a new in-memory cache manager
@@ -55,7 +56,28 @@ func (c *cacheManager) ID() string {
55
56
return c .id
56
57
}
57
58
58
- func (c * cacheManager ) Query (deps []CacheKeyWithSelector , input Index , dgst digest.Digest , output Index ) ([]* CacheKey , error ) {
59
+ func (c * cacheManager ) Query (deps []CacheKeyWithSelector , input Index , dgst digest.Digest , output Index ) (rcks []* CacheKey , rerr error ) {
60
+ depsField := make ([]map [string ]any , len (deps ))
61
+ for i , dep := range deps {
62
+ depsField [i ] = dep .TraceFields ()
63
+ }
64
+ lg := bklog .G (context .TODO ()).WithFields (logrus.Fields {
65
+ "cache_manager" : c .id ,
66
+ "op" : "query" ,
67
+ "deps" : depsField ,
68
+ "input" : input ,
69
+ "digest" : dgst ,
70
+ "output" : output ,
71
+ "stack" : bklog .TraceLevelOnlyStack (),
72
+ })
73
+ defer func () {
74
+ rcksField := make ([]map [string ]any , len (rcks ))
75
+ for i , rck := range rcks {
76
+ rcksField [i ] = rck .TraceFields ()
77
+ }
78
+ lg .WithError (rerr ).WithField ("return_cachekeys" , rcksField ).Trace ("cache manager" )
79
+ }()
80
+
59
81
c .mu .RLock ()
60
82
defer c .mu .RUnlock ()
61
83
@@ -112,7 +134,21 @@ func (c *cacheManager) Query(deps []CacheKeyWithSelector, input Index, dgst dige
112
134
return keys , nil
113
135
}
114
136
115
- func (c * cacheManager ) Records (ctx context.Context , ck * CacheKey ) ([]* CacheRecord , error ) {
137
+ func (c * cacheManager ) Records (ctx context.Context , ck * CacheKey ) (rrecs []* CacheRecord , rerr error ) {
138
+ lg := bklog .G (context .TODO ()).WithFields (logrus.Fields {
139
+ "cache_manager" : c .id ,
140
+ "op" : "records" ,
141
+ "cachekey" : ck .TraceFields (),
142
+ "stack" : bklog .TraceLevelOnlyStack (),
143
+ })
144
+ defer func () {
145
+ rrercsField := make ([]map [string ]any , len (rrecs ))
146
+ for i , rrec := range rrecs {
147
+ rrercsField [i ] = rrec .TraceFields ()
148
+ }
149
+ lg .WithError (rerr ).WithField ("return_records" , rrercsField ).Trace ("cache manager" )
150
+ }()
151
+
116
152
outs := make ([]* CacheRecord , 0 )
117
153
if err := c .backend .WalkResults (c .getID (ck ), func (r CacheResult ) error {
118
154
if c .results .Exists (ctx , r .ID ) {
@@ -132,7 +168,17 @@ func (c *cacheManager) Records(ctx context.Context, ck *CacheKey) ([]*CacheRecor
132
168
return outs , nil
133
169
}
134
170
135
- func (c * cacheManager ) Load (ctx context.Context , rec * CacheRecord ) (Result , error ) {
171
+ func (c * cacheManager ) Load (ctx context.Context , rec * CacheRecord ) (rres Result , rerr error ) {
172
+ lg := bklog .G (context .TODO ()).WithFields (logrus.Fields {
173
+ "cache_manager" : c .id ,
174
+ "op" : "load" ,
175
+ "record" : rec .TraceFields (),
176
+ "stack" : bklog .TraceLevelOnlyStack (),
177
+ })
178
+ defer func () {
179
+ lg .WithError (rerr ).WithField ("return_result" , rres .ID ()).Trace ("cache manager" )
180
+ }()
181
+
136
182
c .mu .RLock ()
137
183
defer c .mu .RUnlock ()
138
184
@@ -150,6 +196,14 @@ type LoadedResult struct {
150
196
CacheKey * CacheKey
151
197
}
152
198
199
+ func (r * LoadedResult ) TraceFields () map [string ]any {
200
+ return map [string ]any {
201
+ "result" : r .Result .ID (),
202
+ "cache_result" : r .CacheResult .ID ,
203
+ "cache_key" : r .CacheKey .TraceFields (),
204
+ }
205
+ }
206
+
153
207
func (c * cacheManager ) filterResults (m map [string ]Result , ck * CacheKey , visited map [string ]struct {}) (results []LoadedResult , err error ) {
154
208
id := c .getID (ck )
155
209
if _ , ok := visited [id ]; ok {
@@ -187,7 +241,21 @@ func (c *cacheManager) filterResults(m map[string]Result, ck *CacheKey, visited
187
241
return
188
242
}
189
243
190
- func (c * cacheManager ) LoadWithParents (ctx context.Context , rec * CacheRecord ) ([]LoadedResult , error ) {
244
+ func (c * cacheManager ) LoadWithParents (ctx context.Context , rec * CacheRecord ) (rres []LoadedResult , rerr error ) {
245
+ lg := bklog .G (context .TODO ()).WithFields (logrus.Fields {
246
+ "cache_manager" : c .id ,
247
+ "op" : "load_with_parents" ,
248
+ "record" : rec .TraceFields (),
249
+ "stack" : bklog .TraceLevelOnlyStack (),
250
+ })
251
+ defer func () {
252
+ rresField := make ([]map [string ]any , len (rres ))
253
+ for i , rres := range rres {
254
+ rresField [i ] = rres .TraceFields ()
255
+ }
256
+ lg .WithError (rerr ).WithField ("return_results" , rresField ).Trace ("cache manager" )
257
+ }()
258
+
191
259
lwp , ok := c .results .(interface {
192
260
LoadWithParents (context.Context , CacheResult ) (map [string ]Result , error )
193
261
})
@@ -226,7 +294,17 @@ func (c *cacheManager) LoadWithParents(ctx context.Context, rec *CacheRecord) ([
226
294
return results , nil
227
295
}
228
296
229
- func (c * cacheManager ) Save (k * CacheKey , r Result , createdAt time.Time ) (* ExportableCacheKey , error ) {
297
+ func (c * cacheManager ) Save (k * CacheKey , r Result , createdAt time.Time ) (rck * ExportableCacheKey , rerr error ) {
298
+ lg := bklog .G (context .TODO ()).WithFields (logrus.Fields {
299
+ "cache_manager" : c .id ,
300
+ "op" : "save" ,
301
+ "result" : r .ID (),
302
+ "stack" : bklog .TraceLevelOnlyStack (),
303
+ })
304
+ defer func () {
305
+ lg .WithError (rerr ).WithField ("return_cachekey" , rck .TraceFields ()).Trace ("cache manager" )
306
+ }()
307
+
230
308
c .mu .Lock ()
231
309
defer c .mu .Unlock ()
232
310
0 commit comments