Skip to content

Commit c8bcd8b

Browse files
committed
Make sure metrics failures don't interrupt deploy operations
1 parent 70b0d1a commit c8bcd8b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

internal/metrics/db.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func SendMetrics(ctx context.Context, jsonData string) error {
7979
cfg := config.FromContext(ctx)
8080
metricsToken, err := GetMetricsToken(ctx)
8181
if err != nil {
82-
return fmt.Errorf("failed to get metrics token: %w", err)
82+
fmt.Fprintf(os.Stderr, "Warning: Metrics token unavailable: %v\n", err)
83+
return nil
8384
}
8485

8586
baseURL := cfg.MetricsBaseURL
@@ -90,7 +91,12 @@ func SendMetrics(ctx context.Context, jsonData string) error {
9091

9192
go sendMetricsRequest(endpoint, metricsToken, userAgent, []byte(jsonData), errChan)
9293

93-
return waitForCompletion(errChan)
94+
err = waitForCompletion(errChan)
95+
if err != nil {
96+
fmt.Fprintf(os.Stderr, "Warning: Metrics send issue: %v\n", err)
97+
}
98+
99+
return nil
94100
}
95101

96102
func sendMetricsRequest(endpoint, token, userAgent string, data []byte, errChan chan<- error) {
@@ -146,10 +152,7 @@ func createHTTPClient() *http.Client {
146152
func waitForCompletion(errChan <-chan error) error {
147153
select {
148154
case err := <-errChan:
149-
if err != nil {
150-
return err
151-
}
152-
return nil
155+
return err
153156
case <-time.After(15 * time.Second):
154157
return fmt.Errorf("metrics send timed out after 15 seconds")
155158
}

0 commit comments

Comments
 (0)