Skip to content

Commit 4e54972

Browse files
thaJeztahaustinvazquez
authored andcommittedNov 2, 2024
services/snapshots: include name of snapshotter in debug logs
- combine consecutive "WithField" calls to "WithFields", as multiple calls is known to be expensive. - include a "snapshotter" field in logs to allow correlating actions with specific snapshotters. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 4594f5c) Signed-off-by: Austin Vazquez <macedonv@amazon.com>
1 parent 2903cc5 commit 4e54972

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
 

‎services/snapshots/service.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (s *service) Register(gs *grpc.Server) error {
9595
}
9696

9797
func (s *service) Prepare(ctx context.Context, pr *snapshotsapi.PrepareSnapshotRequest) (*snapshotsapi.PrepareSnapshotResponse, error) {
98-
log.G(ctx).WithField("parent", pr.Parent).WithField("key", pr.Key).Debugf("prepare snapshot")
98+
log.G(ctx).WithFields(log.Fields{"parent": pr.Parent, "key": pr.Key, "snapshotter": pr.Snapshotter}).Debugf("prepare snapshot")
9999
sn, err := s.getSnapshotter(pr.Snapshotter)
100100
if err != nil {
101101
return nil, err
@@ -116,7 +116,7 @@ func (s *service) Prepare(ctx context.Context, pr *snapshotsapi.PrepareSnapshotR
116116
}
117117

118118
func (s *service) View(ctx context.Context, pr *snapshotsapi.ViewSnapshotRequest) (*snapshotsapi.ViewSnapshotResponse, error) {
119-
log.G(ctx).WithField("parent", pr.Parent).WithField("key", pr.Key).Debugf("prepare view snapshot")
119+
log.G(ctx).WithFields(log.Fields{"parent": pr.Parent, "key": pr.Key, "snapshotter": pr.Snapshotter}).Debugf("prepare view snapshot")
120120
sn, err := s.getSnapshotter(pr.Snapshotter)
121121
if err != nil {
122122
return nil, err
@@ -135,7 +135,7 @@ func (s *service) View(ctx context.Context, pr *snapshotsapi.ViewSnapshotRequest
135135
}
136136

137137
func (s *service) Mounts(ctx context.Context, mr *snapshotsapi.MountsRequest) (*snapshotsapi.MountsResponse, error) {
138-
log.G(ctx).WithField("key", mr.Key).Debugf("get snapshot mounts")
138+
log.G(ctx).WithFields(log.Fields{"key": mr.Key, "snapshotter": mr.Snapshotter}).Debugf("get snapshot mounts")
139139
sn, err := s.getSnapshotter(mr.Snapshotter)
140140
if err != nil {
141141
return nil, err
@@ -151,7 +151,7 @@ func (s *service) Mounts(ctx context.Context, mr *snapshotsapi.MountsRequest) (*
151151
}
152152

153153
func (s *service) Commit(ctx context.Context, cr *snapshotsapi.CommitSnapshotRequest) (*ptypes.Empty, error) {
154-
log.G(ctx).WithField("key", cr.Key).WithField("name", cr.Name).Debugf("commit snapshot")
154+
log.G(ctx).WithFields(log.Fields{"key": cr.Key, "snapshotter": cr.Snapshotter, "name": cr.Name}).Debugf("commit snapshot")
155155
sn, err := s.getSnapshotter(cr.Snapshotter)
156156
if err != nil {
157157
return nil, err
@@ -170,7 +170,7 @@ func (s *service) Commit(ctx context.Context, cr *snapshotsapi.CommitSnapshotReq
170170
}
171171

172172
func (s *service) Remove(ctx context.Context, rr *snapshotsapi.RemoveSnapshotRequest) (*ptypes.Empty, error) {
173-
log.G(ctx).WithField("key", rr.Key).Debugf("remove snapshot")
173+
log.G(ctx).WithFields(log.Fields{"key": rr.Key, "snapshotter": rr.Snapshotter}).Debugf("remove snapshot")
174174
sn, err := s.getSnapshotter(rr.Snapshotter)
175175
if err != nil {
176176
return nil, err
@@ -184,7 +184,7 @@ func (s *service) Remove(ctx context.Context, rr *snapshotsapi.RemoveSnapshotReq
184184
}
185185

186186
func (s *service) Stat(ctx context.Context, sr *snapshotsapi.StatSnapshotRequest) (*snapshotsapi.StatSnapshotResponse, error) {
187-
log.G(ctx).WithField("key", sr.Key).Debugf("stat snapshot")
187+
log.G(ctx).WithFields(log.Fields{"key": sr.Key, "snapshotter": sr.Snapshotter}).Debugf("stat snapshot")
188188
sn, err := s.getSnapshotter(sr.Snapshotter)
189189
if err != nil {
190190
return nil, err
@@ -199,7 +199,7 @@ func (s *service) Stat(ctx context.Context, sr *snapshotsapi.StatSnapshotRequest
199199
}
200200

201201
func (s *service) Update(ctx context.Context, sr *snapshotsapi.UpdateSnapshotRequest) (*snapshotsapi.UpdateSnapshotResponse, error) {
202-
log.G(ctx).WithField("key", sr.Info.Name).Debugf("update snapshot")
202+
log.G(ctx).WithFields(log.Fields{"key": sr.Info.Name, "snapshotter": sr.Snapshotter}).Debugf("update snapshot")
203203
sn, err := s.getSnapshotter(sr.Snapshotter)
204204
if err != nil {
205205
return nil, err

0 commit comments

Comments
 (0)