MCPcopy
hub / github.com/grafana/tempo / sendReport

Function sendReport

pkg/usagestats/stats.go:47–71  ·  view source on GitHub ↗

sendReport sends the report to the stats server

(ctx context.Context, seed *ClusterSeed, interval time.Time)

Source from the content-addressed store, hash-verified

45
46// sendReport sends the report to the stats server
47func 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.

Callers 1

reportUsageMethod · 0.85

Calls 5

buildReportFunction · 0.85
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ReadAllMethod · 0.65

Tested by

no test coverage detected