Skip to content

Commit 4b49400

Browse files
committed
Convert integrations to use slog
1 parent 5eee08d commit 4b49400

File tree

65 files changed

+651
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+651
-650
lines changed

integrations/access/accesslist/app.go

+34-15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/gravitational/teleport/integrations/lib"
3434
"github.com/gravitational/teleport/integrations/lib/logger"
3535
pd "github.com/gravitational/teleport/integrations/lib/plugindata"
36+
logutils "github.com/gravitational/teleport/lib/utils/log"
3637
)
3738

3839
const (
@@ -118,7 +119,7 @@ func (a *App) run(ctx context.Context) error {
118119

119120
log := logger.Get(ctx)
120121

121-
log.Info("Access list monitor is running")
122+
log.InfoContext(ctx, "Access list monitor is running")
122123

123124
a.job.SetReady(true)
124125

@@ -134,7 +135,7 @@ func (a *App) run(ctx context.Context) error {
134135
}
135136
timer.Reset(jitter(reminderInterval))
136137
case <-ctx.Done():
137-
log.Info("Access list monitor is finished")
138+
log.InfoContext(ctx, "Access list monitor is finished")
138139
return nil
139140
}
140141
}
@@ -146,7 +147,7 @@ func (a *App) run(ctx context.Context) error {
146147
func (a *App) remindIfNecessary(ctx context.Context) error {
147148
log := logger.Get(ctx)
148149

149-
log.Info("Looking for Access List Review reminders")
150+
log.InfoContext(ctx, "Looking for Access List Review reminders")
150151

151152
var nextToken string
152153
var err error
@@ -156,21 +157,25 @@ func (a *App) remindIfNecessary(ctx context.Context) error {
156157
accessLists, nextToken, err = a.apiClient.ListAccessLists(ctx, 0 /* default page size */, nextToken)
157158
if err != nil {
158159
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")
160161
return trace.Wrap(err)
161162
} 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)
164166
} else {
165-
log.Errorf("error listing access lists: %v", err)
167+
log.ErrorContext(ctx, "error listing access lists", "error", err)
166168
}
167169
break
168170
}
169171

170172
for _, accessList := range accessLists {
171173
recipients, err := a.getRecipientsRequiringReminders(ctx, accessList)
172174
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+
)
174179
continue
175180
}
176181

@@ -195,7 +200,7 @@ func (a *App) remindIfNecessary(ctx context.Context) error {
195200
}
196201

197202
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...))
199204
}
200205

201206
return nil
@@ -213,7 +218,10 @@ func (a *App) getRecipientsRequiringReminders(ctx context.Context, accessList *a
213218

214219
// If the current time before the notification start time, skip notifications.
215220
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+
)
217225
return nil, nil
218226
}
219227

@@ -255,12 +263,17 @@ func (a *App) fetchRecipients(ctx context.Context, accessList *accesslist.Access
255263
if err != nil {
256264
// TODO(kiosion): Remove in v18; protecting against server not having `GetAccessListOwners` func.
257265
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+
)
259270
for _, owner := range accessList.Spec.Owners {
260271
allOwners = append(allOwners, &owner)
261272
}
262273
} 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())
264277
}
265278
}
266279

@@ -270,7 +283,7 @@ func (a *App) fetchRecipients(ctx context.Context, accessList *accesslist.Access
270283
for _, owner := range allOwners {
271284
recipient, err := a.bot.FetchRecipient(ctx, owner.Name)
272285
if err != nil {
273-
log.Debugf("error getting recipient %s", owner.Name)
286+
log.DebugContext(ctx, "error getting recipient", "recipient", owner.Name)
274287
continue
275288
}
276289
allRecipients[owner.Name] = *recipient
@@ -293,7 +306,10 @@ func (a *App) updatePluginDataAndGetRecipientsRequiringReminders(ctx context.Con
293306
// Calculate days from start.
294307
daysFromStart := now.Sub(notificationStart) / oneDay
295308
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+
)
297313
}
298314

299315
recipients := []common.Recipient{}
@@ -304,7 +320,10 @@ func (a *App) updatePluginDataAndGetRecipientsRequiringReminders(ctx context.Con
304320

305321
// If the notification window is before the last notification date, then this user doesn't need a notification.
306322
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+
)
308327
userNotifications[recipient.Name] = lastNotification
309328
continue
310329
}

integrations/access/accessmonitoring/access_monitoring_rules.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,18 @@ func (amrh *RuleHandler) RecipientsFromAccessMonitoringRules(ctx context.Context
151151
for _, rule := range amrh.getAccessMonitoringRules() {
152152
match, err := MatchAccessRequest(rule.Spec.Condition, req)
153153
if err != nil {
154-
log.WithError(err).WithField("rule", rule.Metadata.Name).
155-
Warn("Failed to parse access monitoring notification rule")
154+
log.WarnContext(ctx, "Failed to parse access monitoring notification rule",
155+
"error", err,
156+
"rule", rule.Metadata.Name,
157+
)
156158
}
157159
if !match {
158160
continue
159161
}
160162
for _, recipient := range rule.Spec.Notification.Recipients {
161163
rec, err := amrh.fetchRecipientCallback(ctx, recipient)
162164
if err != nil {
163-
log.WithError(err).Warn("Failed to fetch plugin recipients based on Access monitoring rule recipients")
165+
log.WarnContext(ctx, "Failed to fetch plugin recipients based on Access monitoring rule recipients", "error", err)
164166
continue
165167
}
166168
recipientSet.Add(*rec)
@@ -176,8 +178,10 @@ func (amrh *RuleHandler) RawRecipientsFromAccessMonitoringRules(ctx context.Cont
176178
for _, rule := range amrh.getAccessMonitoringRules() {
177179
match, err := MatchAccessRequest(rule.Spec.Condition, req)
178180
if err != nil {
179-
log.WithError(err).WithField("rule", rule.Metadata.Name).
180-
Warn("Failed to parse access monitoring notification rule")
181+
log.WarnContext(ctx, "Failed to parse access monitoring notification rule",
182+
"error", err,
183+
"rule", rule.Metadata.Name,
184+
)
181185
}
182186
if !match {
183187
continue

0 commit comments

Comments
 (0)