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)
| 368 | // PingPeerReplica pings a peer replica over it's internal relay address to |
| 369 | // ensure it's reachable and alive for health purposes. |
| 370 | func 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. |
| 395 | func (m *Manager) Self() database.Replica { |
no test coverage detected