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

Function PingPeerReplica

enterprise/replicasync/replicasync.go:370–392  ·  view source on GitHub ↗

PingPeerReplica pings a peer replica over it's internal relay address to ensure it's reachable and alive for health purposes.

(ctx context.Context, client http.Client, relayAddress string)

Source from the content-addressed store, hash-verified

368// PingPeerReplica pings a peer replica over it's internal relay address to
369// ensure it's reachable and alive for health purposes.
370func PingPeerReplica(ctx context.Context, client http.Client, relayAddress string) error {
371 ra, err := url.Parse(relayAddress)
372 if err != nil {
373 return xerrors.Errorf("parse relay address %q: %w", relayAddress, err)
374 }
375 target, err := ra.Parse("/derp/latency-check")
376 if err != nil {
377 return xerrors.Errorf("parse latency-check URL: %w", err)
378 }
379 req, err := http.NewRequestWithContext(ctx, http.MethodGet, target.String(), nil)
380 if err != nil {
381 return xerrors.Errorf("create request: %w", err)
382 }
383 res, err := client.Do(req)
384 if err != nil {
385 return xerrors.Errorf("do probe: %w", err)
386 }
387 _ = res.Body.Close()
388 if res.StatusCode != http.StatusOK {
389 return xerrors.Errorf("unexpected status code: %d", res.StatusCode)
390 }
391 return nil
392}
393
394// Self represents the current replica.
395func (m *Manager) Self() database.Replica {

Callers 2

pingReplicaFunction · 0.92
syncReplicasMethod · 0.85

Calls 5

ParseMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected