Platform Health Providers are extensions to the platform-health server. They enable the server to report on the health and status of a variety of external systems. This extensibility allows the platform-health server to be a versatile tool for monitoring and maintaining the health of your entire platform.
To create a new provider, there are a few requirements:
- Implement the
provider.Instanceinterface:
type Instance interface {
GetType() string
GetName() string
SetName(string)
GetTimeout() time.Duration
SetTimeout(time.Duration)
GetHealth(context.Context) *ph.HealthCheckResponse
Setup() error
}Methods:
GetType(): Returns provider type (e.g., "tcp", "http", "system", etc.)GetName(): Returns instance name (from config key)SetName(): Sets the instance nameGetTimeout(): Returns the per-instance timeout override (0 means use parent context deadline)SetTimeout(): Sets the per-instance timeout overrideGetOrder(): Returns execution order group (default 0); lower values run firstSetOrder(): Sets execution order groupGetAlways(): Returns whether the instance always executes, even after fail-fast cancellationSetAlways(): Sets the always-execute flagGetHealth(): Performs the actual health checkSetup(): Sets default configuration and initializes the instance
-
Register with the internal registry: Providers must register themselves with the platform-health server's internal registry. This is done with a call to
provider.Registerin aninit()function. Theinit()function is automatically called when the program starts, registering the provider before the server begins handling requests. -
Include via blank import: To include the provider in the server, it must be imported using a blank import statement (i.e.,
_ path/to/module) in the main command.
By following these guidelines, you can extend the platform-health server to interact with any external system, making it a powerful tool for platform health monitoring.
Providers can implement the InstanceWithChecks interface to support CEL (Common Expression Language) expressions for health checks:
type InstanceWithChecks interface {
GetCheckConfig() *checks.CEL
GetCheckContext(ctx context.Context) (map[string]any, error)
GetChecks() []checks.Expression
SetChecks([]checks.Expression) error
}Methods:
GetCheckConfig(): Returns CEL configuration for the providerGetCheckContext(): Returns evaluation context map for CEL expressionsGetChecks(): Returns configured CEL expressionsSetChecks(): Sets and compiles CEL expressions; returns an error if any expression is invalid
This enables:
- Custom validation logic via CEL expressions
- Context inspection via
ph contextcommand - Rich evaluation contexts with provider-specific data
The BaseWithChecks struct provides reusable CEL handling that can be embedded by providers:
type BaseWithChecks struct {
checks []checks.Expression
compiled []*checks.Check
}Embed this in your provider to get default implementations of GetChecks(), HasChecks(), EvaluateChecks(), and EvaluateChecksByMode(). In your provider's SetChecks() method, call SetChecksAndCompile(exprs, celConfig) to compile the CEL expressions against your provider's CEL configuration.
Providers that group related child health checks implement the Container interface:
type Container interface {
SetComponents(config map[string]any)
GetComponents() []Instance
ComponentErrors() []error
}Methods:
SetComponents(): Stores raw component configuration (called by factory before Setup)GetComponents(): Returns resolved child instances (available after Setup)ComponentErrors(): Returns validation errors from component resolution
The BaseContainer struct provides a default implementation. Call ResolveComponents() from your provider's Setup() method to resolve child instances from stored config.