Skip to content

Commit d2ceb54

Browse files
author
James Westby
committed
Some simple cleanups to log messages
* Log a more informative error message when giving up on uploading readings to the server. This would be the last message before the pod exits, so if the pod ends up in CrashLoopBackoff it's important to highlight this as the reason. * Remove the "Running Agent" log message, it's not clear what it means * Put [] around the body as if the body is empty the log message can read like the following message is the body. ``` 2024/05/10 16:33:43 retrying in 25.555756126s after error: received response with status code 404. Body: W0510 16:33:43.832278 10875 reflector.go:535] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:229: failed to list route.openshift.io/v1, Resource=routes: the server could not find the requested resource ``` * Remove "using parent stop channel" from a log message as it's not clear what it means. It used to be conditional, and now it isn't, so it's not providing any information, and it's confusing as to what it might be trying to tell you if you aren't familiar with that code.
1 parent 47b26b5 commit d2ceb54

File tree

6 files changed

+9
-10
lines changed

6 files changed

+9
-10
lines changed

pkg/agent/run.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func gatherAndOutputData(config Config, preflightClient client.Client, dataGathe
351351
log.Printf("retrying in %v after error: %s", t, err)
352352
})
353353
if err != nil {
354-
log.Fatalf("%v", err)
354+
log.Fatalf("Exiting due to fatal error uploading: %v", err)
355355
}
356356

357357
}
@@ -401,7 +401,6 @@ func gatherData(config Config, dataGatherers map[string]datagatherer.DataGathere
401401
func postData(config Config, preflightClient client.Client, readings []*api.DataReading) error {
402402
baseURL := config.Server
403403

404-
log.Println("Running Agent...")
405404
log.Println("Posting data to:", baseURL)
406405

407406
if VenafiCloudMode {
@@ -447,7 +446,7 @@ func postData(config Config, preflightClient client.Client, readings []*api.Data
447446
}
448447
defer res.Body.Close()
449448

450-
return fmt.Errorf("received response with status code %d. Body: %s", code, errorContent)
449+
return fmt.Errorf("received response with status code %d. Body: [%s]", code, errorContent)
451450
}
452451
log.Println("Data sent successfully.")
453452
return err

pkg/client/client_api_token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (c *APITokenClient) PostDataReadings(orgID, clusterID string, readings []*a
7171
errorContent = string(body)
7272
}
7373

74-
return fmt.Errorf("received response with status code %d. Body: %s", code, errorContent)
74+
return fmt.Errorf("received response with status code %d. Body: [%s]", code, errorContent)
7575
}
7676

7777
return nil

pkg/client/client_oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (c *OAuthClient) PostDataReadings(orgID, clusterID string, readings []*api.
125125
errorContent = string(body)
126126
}
127127

128-
return fmt.Errorf("received response with status code %d. Body: %s", code, errorContent)
128+
return fmt.Errorf("received response with status code %d. Body: [%s]", code, errorContent)
129129
}
130130

131131
return nil

pkg/client/client_unauthenticated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *UnauthenticatedClient) PostDataReadings(orgID, clusterID string, readin
6767
errorContent = string(body)
6868
}
6969

70-
return fmt.Errorf("received response with status code %d. Body: %s", code, errorContent)
70+
return fmt.Errorf("received response with status code %d. Body: [%s]", code, errorContent)
7171
}
7272

7373
return nil

pkg/client/client_venafi_cloud.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (c *VenafiCloudClient) PostDataReadingsWithOptions(readings []*api.DataRead
199199
if err == nil {
200200
errorContent = string(body)
201201
}
202-
return fmt.Errorf("received response with status code %d. Body: %s", code, errorContent)
202+
return fmt.Errorf("received response with status code %d. Body: [%s]", code, errorContent)
203203
}
204204

205205
return nil
@@ -235,7 +235,7 @@ func (c *VenafiCloudClient) PostDataReadings(_ string, _ string, readings []*api
235235
if err == nil {
236236
errorContent = string(body)
237237
}
238-
return fmt.Errorf("received response with status code %d. Body: %s", code, errorContent)
238+
return fmt.Errorf("received response with status code %d. Body: [%s]", code, errorContent)
239239
}
240240

241241
return nil
@@ -327,7 +327,7 @@ func (c *VenafiCloudClient) sendHTTPRequest(request *http.Request, responseObjec
327327

328328
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated {
329329
body, _ := io.ReadAll(response.Body)
330-
return fmt.Errorf("failed to execute http request to VaaS. Request %s, status code: %d, body: %s", request.URL, response.StatusCode, body)
330+
return fmt.Errorf("failed to execute http request to Venafi Control Plane. Request %s, status code: %d, body: [%s]", request.URL, response.StatusCode, body)
331331
}
332332

333333
body, err := io.ReadAll(response.Body)

pkg/datagatherer/k8s/dynamic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func (g *DataGathererDynamic) Run(stopCh <-chan struct{}) error {
302302
// before collecting the resources.
303303
func (g *DataGathererDynamic) WaitForCacheSync(stopCh <-chan struct{}) error {
304304
if !k8scache.WaitForCacheSync(stopCh, g.informer.HasSynced) {
305-
return fmt.Errorf("timed out waiting for caches to sync, using parent stop channel")
305+
return fmt.Errorf("timed out waiting for Kubernetes caches to sync")
306306
}
307307

308308
return nil

0 commit comments

Comments
 (0)