MCPcopy Index your code
hub / github.com/coder/coder / reportSync

Method reportSync

coderd/telemetry/telemetry.go:140–166  ·  view source on GitHub ↗
(snapshot *Snapshot)

Source from the content-addressed store, hash-verified

138}
139
140func (r *remoteReporter) reportSync(snapshot *Snapshot) {
141 snapshot.DeploymentID = r.options.DeploymentID
142 data, err := json.Marshal(snapshot)
143 if err != nil {
144 r.options.Logger.Error(r.ctx, "marshal snapshot: %w", slog.Error(err))
145 return
146 }
147 req, err := http.NewRequestWithContext(r.ctx, "POST", r.snapshotURL.String(), bytes.NewReader(data))
148 if err != nil {
149 r.options.Logger.Error(r.ctx, "unable to create snapshot request", slog.Error(err))
150 return
151 }
152 req.Header.Set(VersionHeader, buildinfo.Version())
153 resp, err := r.client.Do(req)
154 if err != nil {
155 // If the request fails it's not necessarily an error.
156 // In an airgapped environment, it's fine if this fails!
157 r.options.Logger.Debug(r.ctx, "submit", slog.Error(err))
158 return
159 }
160 defer resp.Body.Close()
161 if resp.StatusCode != http.StatusAccepted {
162 r.options.Logger.Debug(r.ctx, "bad response from telemetry server", slog.F("status", resp.StatusCode))
163 return
164 }
165 r.options.Logger.Debug(r.ctx, "submitted snapshot")
166}
167
168func (r *remoteReporter) Close() {
169 r.closeMutex.Lock()

Callers 3

ReportMethod · 0.95
runSnapshotterMethod · 0.95
reportWithDeploymentMethod · 0.95

Calls 7

VersionFunction · 0.92
SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
MarshalMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected