health-check

Health check types, runner, and JSON output for Kit cloud deployments

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
examples/basic-health.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
LICENSEMIT license file
README.mdThis file
src/main.kitkit-health-check: Health Check Types and Runner
src/runner.kitHealth check runner, JSON output, and HTTP status codes
src/types.kitCore types: HealthStatus, CheckResult, HealthReport, Probe
tests/runner.test.kitTests for runner, JSON output, status helpers

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-health-check.git

Usage

import Kit.HealthCheck

main = fn(-env) =>
  # Define health check probes
  db-probe = HealthCheck.Probe {
    label: "database",
    checker: fn(-n) => HealthCheck.Healthy
  }

  cache-probe = HealthCheck.Probe {
    label: "cache",
    checker: fn(-n) => HealthCheck.Degraded "high latency"
  }

  worker-probe = HealthCheck.Probe {
    label: "worker",
    checker: fn(-n) => HealthCheck.Healthy
  }

  # Run all probes and get aggregate report
  report = HealthCheck.check [db-probe, cache-probe, worker-probe]

  # Output results
  println "Status:      ${HealthCheck.status-to-string report.status}"
  println "HTTP code:   ${to-string (HealthCheck.status-code report)}"
  println "Check count: ${to-string (List.length report.checks)}"
  println (HealthCheck.to-json report)

main

Types

TypeDescription
HealthStatusHealthy, Degraded String, or Unhealthy String
CheckResultCheckResult {label: String, status: HealthStatus}
HealthReportHealthReport {status: HealthStatus, checks: [CheckResult]}
ProbeProbe {label: String, checker: Int -> HealthStatus}

Functions

FunctionSignatureDescription
check[Probe] -> HealthReportRun probes and aggregate into a report (worst-of status)
to-jsonHealthReport -> StringConvert report to JSON string
status-codeHealthReport -> IntMap report to HTTP status (200 or 503)
status-to-stringHealthStatus -> StringConvert status to "healthy", "degraded", or "unhealthy"
is-healthy?HealthStatus -> BoolCheck if status is Healthy
is-degraded?HealthStatus -> BoolCheck if status is Degraded
is-unhealthy?HealthStatus -> BoolCheck if status is Unhealthy

JSON Output

to-json produces output in the following format:

{"status":"degraded","checks":[{"name":"database","status":"healthy"},{"name":"cache","status":"degraded","reason":"high latency"}]}

A "reason" field is included for Degraded and Unhealthy checks.

Status Code Mapping

StatusHTTP Code
Healthy200
Degraded200
Unhealthy503

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic-health.kit

Compile examples to a native binary:

kit build examples/basic-health.kit && ./basic-health

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/health-check/, making it available for import as Kit.HealthCheck in other projects.

License

This package is released under the MIT License - see LICENSE for details.

Exported Functions & Types

check

Run all probes and produce an aggregate HealthReport.

[Probe] -> HealthReport

to-json

Convert a HealthReport to a JSON string.

HealthReport -> String

status-code

Map a HealthReport to an HTTP status code.

HealthReport -> Int

HealthStatus

The health status of a component or service.

- Healthy: Component is operating normally - Degraded: Component is functional but impaired (with reason) - Unhealthy: Component is not functional (with reason)

Variants

Healthy
Degraded {String}
Unhealthy {String}

CheckResult

The result of a single health check.

Contains the label of the check and its status.

Variants

CheckResult {label, status}

HealthReport

An aggregate health report containing overall status and individual checks.

The overall status is the worst-of all check statuses: any Unhealthy -> Unhealthy, any Degraded -> Degraded, else Healthy.

Variants

HealthReport {status, checks}

Probe

A named health check probe.

The checker function takes a dummy Int argument (pass 0) and returns a HealthStatus.

Variants

Probe {label, checker}

status-to-string

Convert a HealthStatus to its string label.

HealthStatus -> String

is-healthy?

Check if a HealthStatus is Healthy.

HealthStatus -> Bool

is-degraded?

Check if a HealthStatus is Degraded.

HealthStatus -> Bool

is-unhealthy?

Check if a HealthStatus is Unhealthy.

HealthStatus -> Bool

check

Run all probes and produce an aggregate HealthReport.

Each probe's checker is called with 0 as the dummy argument. The aggregate status is the worst-of all individual statuses: any Unhealthy -> Unhealthy, any Degraded -> Degraded, else Healthy.

[Probe] -> HealthReport

to-json

Convert a HealthReport to a JSON string.

Format: {"status":"healthy","checks":[{"name":"db","status":"healthy"},...]} Includes "reason" field for Degraded and Unhealthy checks.

HealthReport -> String

status-code

Map a HealthReport to an HTTP status code.

Healthy or Degraded -> 200, Unhealthy -> 503.

HealthReport -> Int