sendReport sends the report to the stats server
(ctx context.Context, seed *ClusterSeed, interval time.Time)
| 45 | |
| 46 | // sendReport sends the report to the stats server |
| 47 | func sendReport(ctx context.Context, seed *ClusterSeed, interval time.Time) error { |
| 48 | report := buildReport(seed, interval) |
| 49 | out, err := json.MarshalIndent(report, "", " ") |
| 50 | if err != nil { |
| 51 | return err |
| 52 | } |
| 53 | req, err := http.NewRequest(http.MethodPost, usageStatsURL, bytes.NewBuffer(out)) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | req.Header.Set("Content-Type", "application/json") |
| 58 | resp, err := httpClient.Do(req.WithContext(ctx)) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | defer resp.Body.Close() |
| 63 | if resp.StatusCode/100 != 2 { |
| 64 | data, err := io.ReadAll(resp.Body) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | return fmt.Errorf("failed to send usage stats: %s body: %s", resp.Status, string(data)) |
| 69 | } |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | // buildReport builds the report to be sent to the stats server, |
| 74 | // this report includes the cluster seed data. |
no test coverage detected