Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgraded expected/common "BootstrapPackage not found" server error to a debug message. #25266

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading