Skip to content

Commit

Permalink
Downgraded expected/common "BootstrapPackage not found" server error …
Browse files Browse the repository at this point in the history
…to a debug message. (#25266)

For #25265
Downgraded expected/common "BootstrapPackage not found" server error to
a debug message. Occurs when UI/API checks if bootstrap package exists.

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
- [x] Manual QA for all new/changed functionality
  • Loading branch information
getvictor authored Jan 8, 2025
1 parent 679019e commit 992144b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/25265-boostrap-package-not-found
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Downgraded expected/common "BootstrapPackage not found" server error to a debug message. Occurs when UI/API checks if bootstrap package exists.
3 changes: 2 additions & 1 deletion ee/server/service/software_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ func (svc *Service) getSoftwareInstallerBinary(ctx context.Context, storageID st
return nil, ctxerr.Wrap(ctx, err, "checking if installer exists")
}
if !exists {
return nil, ctxerr.Wrap(ctx, notFoundError{}, "does not exist in software installer store")
return nil, ctxerr.Wrapf(ctx, notFoundError{}, "%s with filename %s does not exist in software installer store", storageID,
filename)
}

// get the installer from the store
Expand Down
19 changes: 18 additions & 1 deletion server/contexts/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func WithNoUser(ctx context.Context) context.Context {
return ctx
}

// WithNoError returns a context with logging.SkipError set to true so error won't be logged at level=error
func WithNoError(ctx context.Context) context.Context {
if logCtx, ok := FromContext(ctx); ok {
logCtx.SetSkipError()
}
return ctx
}

// WithExtras returns a context with logging.Extras set as the values provided
func WithExtras(ctx context.Context, extras ...interface{}) context.Context {
if logCtx, ok := FromContext(ctx); ok {
Expand All @@ -61,6 +69,8 @@ func WithExtras(ctx context.Context, extras ...interface{}) context.Context {
return ctx
}

// WithLevel forces a log level for the current request/context.
// Level may still be upgraded to Error if an error is present.
func WithLevel(ctx context.Context, level func(kitlog.Logger) kitlog.Logger) context.Context {
if logCtx, ok := FromContext(ctx); ok {
logCtx.SetForceLevel(level)
Expand All @@ -77,6 +87,7 @@ type LoggingContext struct {
Extras []interface{}
SkipUser bool
ForceLevel func(kitlog.Logger) kitlog.Logger
SkipError bool
}

func (l *LoggingContext) SetForceLevel(level func(kitlog.Logger) kitlog.Logger) {
Expand All @@ -97,6 +108,12 @@ func (l *LoggingContext) SetSkipUser() {
l.SkipUser = true
}

func (l *LoggingContext) SetSkipError() {
l.l.Lock()
defer l.l.Unlock()
l.SkipError = true
}

func (l *LoggingContext) SetStartTime() {
l.l.Lock()
defer l.l.Unlock()
Expand All @@ -115,7 +132,7 @@ func (l *LoggingContext) Log(ctx context.Context, logger kitlog.Logger) {
defer l.l.Unlock()

switch {
case len(l.Errs) > 0:
case len(l.Errs) > 0 && !l.SkipError:
logger = level.Error(logger)
case l.ForceLevel != nil:
logger = l.ForceLevel(logger)
Expand Down
8 changes: 7 additions & 1 deletion server/service/apple_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,13 @@ func (r bootstrapPackageMetadataResponse) error() error { return r.Err }
func bootstrapPackageMetadataEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (errorer, error) {
req := request.(*bootstrapPackageMetadataRequest)
meta, err := svc.GetMDMAppleBootstrapPackageMetadata(ctx, req.TeamID, req.ForUpdate)
if err != nil {
switch {
case fleet.IsNotFound(err):
// Don't log this response as error -- it's expected to happen when the bootstrap package is missing, which is a common case.
logging.WithNoError(ctx)
return bootstrapPackageMetadataResponse{Err: fleet.NewInvalidArgumentError("team_id",
"bootstrap package for this team does not exist").WithStatus(http.StatusNotFound)}, nil
case err != nil:
return bootstrapPackageMetadataResponse{Err: err}, nil
}
return bootstrapPackageMetadataResponse{MDMAppleBootstrapPackage: meta}, nil
Expand Down
2 changes: 1 addition & 1 deletion server/service/integration_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *integrationLoggerTestSuite) TestLoggerLogin() {
require.NotContains(t, logData, "user") // logger context is set to skip user

for _, e := range tt.expectedLogs {
assert.Equal(t, logData[e.key], e.val)
assert.Equal(t, e.val, logData[e.key], fmt.Sprintf("%+v", tt.expectedLogs))
}
s.buf.Reset()
}
Expand Down

0 comments on commit 992144b

Please sign in to comment.