Documentation

HealthApi
in package

Public health probe for the TypeSense dependency.

TypeSense is not reachable from outside the server and must stay that way — the API key in play is an admin key, so publishing /health would publish the write API with it. This route is the proxy: an uptime monitor asks WordPress, and WordPress asks TypeSense.

It reports three things rather than a binary, because they fail independently:

  • node — TypeSense's own /health. This is the endpoint that says "Not Ready or Lagging", i.e. the literal cause of the outage this was built for.
  • breaker — what WordPress actually experienced. A direct probe of TypeSense could never see this, and it is the signal that distinguishes a node which is answering from one which is answering too slowly to be usable.
  • index — whether the aliases the frontend reads actually resolve. Wsc\Utils
    TsHealth deliberately treats a 404 as proof the node is alive, so a TypeSense that is up but has lost an index degrades to empty results and never trips the breaker. This is the check that catches that.

Separately, buffer says whether PIM webhooks still reach the collections. A stuck propagation run or a lost cron event leaves TypeSense healthy and every page serving stale data, with nothing logged — so it is judged here, where an outside poller asks, not from cron, which is exactly what stops in that failure.

Table of Contents

Constants

BUFFER_MAX_AGE  : mixed = 90 * 60
LOG_CHANNEL  : mixed = 'wsc'
NAMESPACE  : mixed = 'wsc/v1'
CACHE_KEY_PREFIX  : mixed = 'wsc_health_'
CACHE_TTL  : mixed = 30

Methods

__construct()  : mixed
bufferVerdict()  : string
handleHealth()  : WP_REST_Response
Always answers 200; the verdict is in the body.
registerRoutes()  : void
frontendCollections()  : array<string|int, Collection>
The collections a page render actually depends on.
missingAliases()  : array<string|int, string>|null
Names of the expected aliases that TypeSense does not currently know about.
probe()  : array<string|int, mixed>
shortClass()  : string

Constants

BUFFER_MAX_AGE

public mixed BUFFER_MAX_AGE = 90 * 60

LOG_CHANNEL

public mixed LOG_CHANNEL = 'wsc'

CACHE_KEY_PREFIX

private mixed CACHE_KEY_PREFIX = 'wsc_health_'

Methods

bufferVerdict()

public static bufferVerdict(int|false|null $oldestAge) : string
Parameters
$oldestAge : int|false|null

see BufferChecker::oldestPendingAge()

Return values
string

handleHealth()

Always answers 200; the verdict is in the body.

public handleHealth() : WP_REST_Response

The fleet's monitors are all keyword probes over 200-299, so the keyword is what decides up from down. Match on "typesense":"ok", and on "buffer":"ok" for the PIM sync.

Return values
WP_REST_Response

registerRoutes()

public registerRoutes() : void

frontendCollections()

The collections a page render actually depends on.

private frontendCollections(int $blogId) : array<string|int, Collection>
Parameters
$blogId : int
Return values
array<string|int, Collection>

missingAliases()

Names of the expected aliases that TypeSense does not currently know about.

private missingAliases(int $blogId) : array<string|int, string>|null

Uses one GET /aliases rather than one lookup per collection, so the whole check costs a single round-trip and cannot push the route past a monitor's timeout.

Parameters
$blogId : int
Return values
array<string|int, string>|null —

Null when the alias list could not be read at all.

probe()

private probe(int $blogId) : array<string|int, mixed>
Parameters
$blogId : int
Return values
array<string|int, mixed> —

The verdict payload.

shortClass()

private shortClass(Throwable $exception) : string
Parameters
$exception : Throwable
Return values
string
On this page

Search results