cloudflare

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

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

func WithEndpoint(u string) Option

WithEndpoint overrides the GraphQL endpoint (testing / gateways).

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets the HTTP client.

func WithToken

func WithToken(t string) Option

WithToken sets the default API token.

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 New

func New(opts ...Option) *WorkersProvider

New builds a WorkersProvider from options.

func (*WorkersProvider) Check

func (p *WorkersProvider) Check(ctx context.Context, comp core.Component) core.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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL