@@ -33,6 +33,7 @@ import (
33
33
"github.com/gravitational/teleport/integrations/lib"
34
34
"github.com/gravitational/teleport/integrations/lib/logger"
35
35
pd "github.com/gravitational/teleport/integrations/lib/plugindata"
36
+ logutils "github.com/gravitational/teleport/lib/utils/log"
36
37
)
37
38
38
39
const (
@@ -118,7 +119,7 @@ func (a *App) run(ctx context.Context) error {
118
119
119
120
log := logger .Get (ctx )
120
121
121
- log .Info ( "Access list monitor is running" )
122
+ log .InfoContext ( ctx , "Access list monitor is running" )
122
123
123
124
a .job .SetReady (true )
124
125
@@ -134,7 +135,7 @@ func (a *App) run(ctx context.Context) error {
134
135
}
135
136
timer .Reset (jitter (reminderInterval ))
136
137
case <- ctx .Done ():
137
- log .Info ( "Access list monitor is finished" )
138
+ log .InfoContext ( ctx , "Access list monitor is finished" )
138
139
return nil
139
140
}
140
141
}
@@ -146,7 +147,7 @@ func (a *App) run(ctx context.Context) error {
146
147
func (a * App ) remindIfNecessary (ctx context.Context ) error {
147
148
log := logger .Get (ctx )
148
149
149
- log .Info ( "Looking for Access List Review reminders" )
150
+ log .InfoContext ( ctx , "Looking for Access List Review reminders" )
150
151
151
152
var nextToken string
152
153
var err error
@@ -156,21 +157,25 @@ func (a *App) remindIfNecessary(ctx context.Context) error {
156
157
accessLists , nextToken , err = a .apiClient .ListAccessLists (ctx , 0 /* default page size */ , nextToken )
157
158
if err != nil {
158
159
if trace .IsNotImplemented (err ) {
159
- log .Errorf ( "access list endpoint is not implemented on this auth server, so the access list app is ceasing to run. " )
160
+ log .ErrorContext ( ctx , "access list endpoint is not implemented on this auth server, so the access list app is ceasing to run" )
160
161
return trace .Wrap (err )
161
162
} else if trace .IsAccessDenied (err ) {
162
- log .Warnf ("Slack bot does not have permissions to list access lists. Please add access_list read and list permissions " +
163
- "to the role associated with the Slack bot." )
163
+ const msg = "Slack bot does not have permissions to list access lists. Please add access_list read and list permissions " +
164
+ "to the role associated with the Slack bot."
165
+ log .WarnContext (ctx , msg )
164
166
} else {
165
- log .Errorf ( "error listing access lists: %v " , err )
167
+ log .ErrorContext ( ctx , "error listing access lists" , "error " , err )
166
168
}
167
169
break
168
170
}
169
171
170
172
for _ , accessList := range accessLists {
171
173
recipients , err := a .getRecipientsRequiringReminders (ctx , accessList )
172
174
if err != nil {
173
- log .WithError (err ).Warnf ("Error getting recipients to notify for review due for access list %q" , accessList .Spec .Title )
175
+ log .WarnContext (ctx , "Error getting recipients to notify for review due for access list" ,
176
+ "error" , err ,
177
+ "access_list" , accessList .Spec .Title ,
178
+ )
174
179
continue
175
180
}
176
181
@@ -195,7 +200,7 @@ func (a *App) remindIfNecessary(ctx context.Context) error {
195
200
}
196
201
197
202
if len (errs ) > 0 {
198
- log .WithError ( trace . NewAggregate ( errs ... )). Warn ( "Error notifying for access list reviews" )
203
+ log .WarnContext ( ctx , "Error notifying for access list reviews" , "error" , trace . NewAggregate ( errs ... ) )
199
204
}
200
205
201
206
return nil
@@ -213,7 +218,10 @@ func (a *App) getRecipientsRequiringReminders(ctx context.Context, accessList *a
213
218
214
219
// If the current time before the notification start time, skip notifications.
215
220
if now .Before (notificationStart ) {
216
- log .Debugf ("Access list %s is not ready for notifications, notifications start at %s" , accessList .GetName (), notificationStart .Format (time .RFC3339 ))
221
+ log .DebugContext (ctx , "Access list is not ready for notifications" ,
222
+ "access_list" , accessList .GetName (),
223
+ "notification_start_time" , notificationStart .Format (time .RFC3339 ),
224
+ )
217
225
return nil , nil
218
226
}
219
227
@@ -255,12 +263,17 @@ func (a *App) fetchRecipients(ctx context.Context, accessList *accesslist.Access
255
263
if err != nil {
256
264
// TODO(kiosion): Remove in v18; protecting against server not having `GetAccessListOwners` func.
257
265
if trace .IsNotImplemented (err ) {
258
- log .WithError (err ).Warnf ("Error getting nested owners for access list '%v', continuing with only explicit owners" , accessList .GetName ())
266
+ log .WarnContext (ctx , "Error getting nested owners for access list, continuing with only explicit owners" ,
267
+ "error" , err ,
268
+ "access_list" , accessList .GetName (),
269
+ )
259
270
for _ , owner := range accessList .Spec .Owners {
260
271
allOwners = append (allOwners , & owner )
261
272
}
262
273
} else {
263
- log .WithError (err ).Errorf ("Error getting owners for access list '%v'" , accessList .GetName ())
274
+ log .ErrorContext (ctx , "Error getting owners for access list" ,
275
+ "error" , err ,
276
+ "access_list" , accessList .GetName ())
264
277
}
265
278
}
266
279
@@ -270,7 +283,7 @@ func (a *App) fetchRecipients(ctx context.Context, accessList *accesslist.Access
270
283
for _ , owner := range allOwners {
271
284
recipient , err := a .bot .FetchRecipient (ctx , owner .Name )
272
285
if err != nil {
273
- log .Debugf ( "error getting recipient %s " , owner .Name )
286
+ log .DebugContext ( ctx , "error getting recipient" , "recipient " , owner .Name )
274
287
continue
275
288
}
276
289
allRecipients [owner .Name ] = * recipient
@@ -293,7 +306,10 @@ func (a *App) updatePluginDataAndGetRecipientsRequiringReminders(ctx context.Con
293
306
// Calculate days from start.
294
307
daysFromStart := now .Sub (notificationStart ) / oneDay
295
308
windowStart = notificationStart .Add (daysFromStart * oneDay )
296
- log .Infof ("windowStart: %s, now: %s" , windowStart .String (), now .String ())
309
+ log .InfoContext (ctx , "calculating window start" ,
310
+ "window_start" , logutils .StringerAttr (windowStart ),
311
+ "now" , logutils .StringerAttr (now ),
312
+ )
297
313
}
298
314
299
315
recipients := []common.Recipient {}
@@ -304,7 +320,10 @@ func (a *App) updatePluginDataAndGetRecipientsRequiringReminders(ctx context.Con
304
320
305
321
// If the notification window is before the last notification date, then this user doesn't need a notification.
306
322
if ! windowStart .After (lastNotification ) {
307
- log .Debugf ("User %s has already been notified for access list %s" , recipient .Name , accessList .GetName ())
323
+ log .DebugContext (ctx , "User has already been notified for access list" ,
324
+ "user" , recipient .Name ,
325
+ "access_list" , accessList .GetName (),
326
+ )
308
327
userNotifications [recipient .Name ] = lastNotification
309
328
continue
310
329
}
0 commit comments