Documentation
¶
Overview ¶
Package cloudflare provides Console status providers backed by Cloudflare's APIs. WorkersProvider reports the health of a Cloudflare Worker from its recent invocation analytics (request and error counts) via the Cloudflare GraphQL Analytics API.
It satisfies the status.Provider interface structurally (Name + Check), so it does not import the status package and adds no coupling beyond core.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*WorkersProvider)
Option configures a WorkersProvider.
func WithEndpoint ¶
WithEndpoint overrides the GraphQL endpoint (testing / gateways).
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client.
type WorkersProvider ¶
type WorkersProvider struct {
// Token is the default Cloudflare API token, used when a component does not
// set "api_token". Typically sourced from the CLOUDFLARE_API_TOKEN env var.
Token string
// Endpoint is the GraphQL API URL; defaults to Cloudflare's. Overridable for
// testing or a self-hosted gateway.
Endpoint string
// HTTP issues the API request. If nil, a client with a sane timeout is used.
HTTP *http.Client
}
WorkersProvider checks a Cloudflare Worker's health from its invocation analytics. The error rate over a trailing window maps to a health state.
It reads its target from core.Component.Config:
account_id required; the Cloudflare account tag worker required; the Worker script name (alias: "script") api_token optional; overrides the provider's default token window optional; trailing window as a Go duration, default "15m" degraded_pct optional; error-rate %% at/above which state is degraded (default 1) down_pct optional; error-rate %% at/above which state is down (default 5) timeout optional; API call timeout as a Go duration, default "10s"
State mapping (error rate = errors / requests over the window):
rate < degraded_pct -> StateOperational degraded_pct <= rate < down_pct -> StateDegraded rate >= down_pct -> StateDown API/network failure or GraphQL error -> StateDown no token / account_id / worker -> StateUnknown (configuration gap) zero invocations in the window -> StateUnknown (idle, not unhealthy)
func (*WorkersProvider) Check ¶
Check queries the Worker's analytics and maps the error rate to a health state.
func (*WorkersProvider) Name ¶
func (p *WorkersProvider) Name() string
Name identifies the provider.