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

Fix the vet linter errors for non-constant format strings in logging calls. #786

Merged
merged 1 commit into from
Feb 3, 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
2 changes: 1 addition & 1 deletion agentendpoint/agentendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (c *Client) WaitForTaskNotification(ctx context.Context) {

clog.Debugf(ctx, "Checking local state file for saved task.")
if err := c.loadTaskFromState(ctx); err != nil {
clog.Errorf(ctx, err.Error())
clog.Errorf(ctx, "%v", err.Error())
}

clog.Debugf(ctx, "Setting up ReceiveTaskNotification stream watcher.")
Expand Down
12 changes: 6 additions & 6 deletions agentendpoint/config_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *configTask) handleErrorState(ctx context.Context, msg string, err error
return c.reportCompletedState(ctx, errServerCancel.Error(), agentendpointpb.ApplyConfigTaskOutput_CANCELLED)
}
msg = fmt.Sprintf("%s: %v", msg, err)
clog.Errorf(ctx, msg)
clog.Errorf(ctx, "%v", msg)
return c.reportCompletedState(ctx, msg, agentendpointpb.ApplyConfigTaskOutput_FAILED)
}

Expand Down Expand Up @@ -153,14 +153,14 @@ func validateConfigResource(ctx context.Context, res *resource, policyMR *config
outcome = agentendpointpb.OSPolicyResourceConfigStep_FAILED
hasError = true
errMessage = truncateMessage(fmt.Sprintf("Validate: resource %q error: %v", configResource.GetId(), err), maxErrorMessage)
clog.Errorf(ctx, errMessage)
clog.Errorf(ctx, "%v", errMessage)
} else {
// Detect any resource conflicts within this policy.
if err := detectPolicyConflicts(res.ManagedResources(), policyMR); err != nil {
outcome = agentendpointpb.OSPolicyResourceConfigStep_FAILED
hasError = true
errMessage = truncateMessage(fmt.Sprintf("Validate: resource conflict in policy: %v", err), maxErrorMessage)
clog.Errorf(ctx, errMessage)
clog.Errorf(ctx, "%v", errMessage)
} else {
clog.Infof(ctx, "Validate: resource %q validation successful.", configResource.GetId())
}
Expand All @@ -187,7 +187,7 @@ func checkConfigResourceState(ctx context.Context, res *resource, rCompliance *a
outcome = agentendpointpb.OSPolicyResourceConfigStep_FAILED
hasError = true
errMessage = truncateMessage(fmt.Sprintf("Check state: resource %q error: %v", configResource.GetId(), err), maxErrorMessage)
clog.Errorf(ctx, errMessage)
clog.Errorf(ctx, "%v", errMessage)
} else if res.InDesiredState() {
state = agentendpointpb.OSPolicyComplianceState_COMPLIANT
} else {
Expand Down Expand Up @@ -220,7 +220,7 @@ func enforceConfigResourceState(ctx context.Context, res *resource, rCompliance
outcome = agentendpointpb.OSPolicyResourceConfigStep_FAILED
hasError = true
errMessage = truncateMessage(fmt.Sprintf("Enforce state: resource %q error: %v", configResource.GetId(), err), maxErrorMessage)
clog.Errorf(ctx, errMessage)
clog.Errorf(ctx, "%v", errMessage)
} else {
clog.Infof(ctx, "Enforce state: resource %q enforcement successful.", configResource.GetId())
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func postCheckConfigResourceState(ctx context.Context, res *resource, rComplianc
if err != nil {
outcome = agentendpointpb.OSPolicyResourceConfigStep_FAILED
errMessage = truncateMessage(fmt.Sprintf("Check state post enforcement: resource %q error: %v", configResource.GetId(), err), maxErrorMessage)
clog.Errorf(ctx, errMessage)
clog.Errorf(ctx, "%v", errMessage)
} else if res.InDesiredState() {
state = agentendpointpb.OSPolicyComplianceState_COMPLIANT
} else {
Expand Down
4 changes: 2 additions & 2 deletions agentendpoint/exec_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (e *execTask) run(ctx context.Context) error {
localPath, err = getGCSObject(ctx, gcsObject.GetBucket(), gcsObject.GetObject(), gcsObject.GetGenerationNumber())
if err != nil {
msg := fmt.Sprintf("Error downloading GCS object: %v", err)
clog.Errorf(ctx, msg)
clog.Errorf(ctx, "%v", msg)
return e.reportCompletedState(ctx, msg, &agentendpointpb.ReportTaskCompleteRequest_ExecStepTaskOutput{
ExecStepTaskOutput: &agentendpointpb.ExecStepTaskOutput{
State: agentendpointpb.ExecStepTaskOutput_COMPLETED,
Expand Down Expand Up @@ -207,7 +207,7 @@ func (e *execTask) run(ctx context.Context) error {
}
if err != nil {
msg := fmt.Sprintf("Error running ExecStepTask: %v", err)
clog.Errorf(ctx, msg)
clog.Errorf(ctx, "%v", msg)
return e.reportCompletedState(ctx, msg, &agentendpointpb.ReportTaskCompleteRequest_ExecStepTaskOutput{
ExecStepTaskOutput: &agentendpointpb.ExecStepTaskOutput{
State: agentendpointpb.ExecStepTaskOutput_COMPLETED,
Expand Down
2 changes: 1 addition & 1 deletion agentendpoint/patch_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *patchTask) handleErrorState(ctx context.Context, msg string, err error)
}

func (r *patchTask) reportFailed(ctx context.Context, msg string) error {
clog.Errorf(ctx, msg)
clog.Errorf(ctx, "%v", msg)
return r.reportCompletedState(ctx, msg, &agentendpointpb.ReportTaskCompleteRequest_ApplyPatchesTaskOutput{
ApplyPatchesTaskOutput: &agentendpointpb.ApplyPatchesTaskOutput{State: agentendpointpb.ApplyPatchesTaskOutput_FAILED},
})
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ var deferredFuncs []func()
func registerAgent(ctx context.Context) {
for {
if client, err := agentendpoint.NewClient(ctx); err != nil {
logger.Errorf(err.Error())
logger.Errorf("%v", err.Error())
} else if err := client.RegisterAgent(ctx); err != nil {
logger.Errorf(err.Error())
logger.Errorf("%v", err.Error())
client.Close()
} else {
// RegisterAgent completed successfully.
Expand Down Expand Up @@ -167,7 +167,7 @@ func run(ctx context.Context) {
case "inventory", "osinventory":
client, err := agentendpoint.NewClient(ctx)
if err != nil {
logger.Fatalf(err.Error())
logger.Fatalf("%v", err.Error())
}
tasker.Enqueue(ctx, "Report OSInventory", func() {
client.ReportInventory(ctx)
Expand All @@ -181,7 +181,7 @@ func run(ctx context.Context) {
case "w", "waitfortasknotification", "ospatch":
client, err := agentendpoint.NewClient(ctx)
if err != nil {
logger.Fatalf(err.Error())
logger.Fatalf("%v", err.Error())
}
client.WaitForTaskNotification(ctx)
select {
Expand All @@ -208,15 +208,15 @@ func runTaskLoop(ctx context.Context, c chan struct{}) {
// Start WaitForTaskNotification if we need to.
taskNotificationClient, err = agentendpoint.NewClient(ctx)
if err != nil {
clog.Errorf(ctx, err.Error())
clog.Errorf(ctx, "%v", err.Error())
} else {
taskNotificationClient.WaitForTaskNotification(ctx)
}
} else if !agentconfig.TaskNotificationEnabled() && taskNotificationClient != nil && !taskNotificationClient.Closed() {
// Cancel WaitForTaskNotification if we need to, this will block if there is
// an existing current task running.
if err := taskNotificationClient.Close(); err != nil {
clog.Errorf(ctx, err.Error())
clog.Errorf(ctx, "%v", err.Error())
}
}

Expand All @@ -228,7 +228,7 @@ func runTaskLoop(ctx context.Context, c chan struct{}) {

// Wait on any metadata config change.
if err := agentconfig.WatchConfig(ctx); err != nil {
clog.Errorf(ctx, err.Error())
clog.Errorf(ctx, "%v", err.Error())
}
select {
case <-ctx.Done():
Expand Down Expand Up @@ -302,7 +302,7 @@ func runServiceLoop(ctx context.Context) {
tasker.Enqueue(ctx, "Report OSInventory", func() {
client, err := agentendpoint.NewClient(ctx)
if err != nil {
logger.Errorf(err.Error())
logger.Errorf("%v", err.Error())
}
client.ReportInventory(ctx)
client.Close()
Expand Down
6 changes: 3 additions & 3 deletions ospatch/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func logOps(ctx context.Context, ops opsToReport) {
msg = msg + fmt.Sprintf("%sInstalling %d patches: %s", sep, len(ops.patches), formatPatches(ops.patches))
}

clog.Infof(clog.WithLabels(ctx, repLabels), msg)
clog.Infof(clog.WithLabels(ctx, repLabels), "%v", msg)
}

// logSuccess logs the success of patching the packages in pkgs
Expand All @@ -72,7 +72,7 @@ func logSuccess(ctx context.Context, ops opsToReport) {
msg = msg + fmt.Sprintf("%sApplied %d patches: %s", sep, len(patches), formatPatches(patches))
}
msg = fmt.Sprintf("Success. %s", msg)
clog.Infof(clog.WithLabels(ctx, repLabels), msg)
clog.Infof(clog.WithLabels(ctx, repLabels), "%v", msg)
}

// logFailure logs the failure of patching the packages in pkgs caused by err,
Expand All @@ -89,5 +89,5 @@ func logFailure(ctx context.Context, ops opsToReport, err error) {
msg = msg + fmt.Sprintf("%sTried to apply %d patches: %s", sep, len(patches), formatPatches(patches))
}
msg = fmt.Sprintf("Failure: %s. Error: %v", msg, err)
clog.Infof(clog.WithLabels(ctx, repLabels), msg)
clog.Infof(clog.WithLabels(ctx, repLabels), "%v", msg)
}
2 changes: 1 addition & 1 deletion ospatch/system_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func DisableAutoUpdates(ctx context.Context) {
if _, err := os.Stat("/usr/bin/unattended-upgrades"); err == nil {
clog.Debugf(ctx, "Removing unattended-upgrades package")
if err := packages.RemoveAptPackages(ctx, []string{"unattended-upgrades"}); err != nil {
clog.Errorf(ctx, err.Error())
clog.Errorf(ctx, "%v", err.Error())
}
}
}
4 changes: 2 additions & 2 deletions packages/zypper.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func parseZypperPatchInfo(out []byte) (map[string][]string, error) {
//zypper-needs-restarting < 1.14.64-150400.3.32.1
parts := strings.Split(string(lines[ctr]), "<")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid package info, can't parse line: " + string(lines[ctr]))
return nil, fmt.Errorf("invalid package info, can't parse line: %v", string(lines[ctr]))
}

nameArch := parts[0]
Expand All @@ -386,7 +386,7 @@ func parseZypperPatchInfo(out []byte) (map[string][]string, error) {
colonIdx := strings.Index(nameArch, ":")
pkgName = strings.Trim(nameArch[colonIdx+1:], " ")
if len(pkgName) == 0 {
return nil, fmt.Errorf("invalid package info, can't parse line: " + string(lines[ctr]))
return nil, fmt.Errorf("invalid package info, can't parse line: %v", string(lines[ctr]))
}
} else {
// Get the last index to handle the case if pkg has float version
Expand Down