17#define CWIST_HEALTHZ_MAX_PROBES 16
19typedef struct cwist_healthz_entry {
27static int g_entry_count = 0;
46 if (!name || !fn)
return false;
49 for (
int i = 0;
i < g_entry_count; ++
i) {
50 if (g_entries[
i].active) {
51 if (
strcmp(g_entries[
i].name, name) == 0) {
53 g_entries[
i].ctx = ctx;
71 g_entries[g_entry_count].name = name;
72 g_entries[g_entry_count].fn = fn;
73 g_entries[g_entry_count].ctx = ctx;
74 g_entries[g_entry_count].active =
true;
90 for (
int i = 0;
i < g_entry_count; ++
i) {
91 if (g_entries[
i].active &&
strcmp(g_entries[
i].name, name) == 0) {
92 g_entries[
i].active =
false;
112 default:
return "unknown";
135 for (
int i = 0;
i < g_entry_count; ++
i) {
136 if (!g_entries[
i].active)
continue;
180 for (
size_t i = 0;
i <
count; ++
i) {
Memory allocation wrappers backed by libttak.
Safe string type with helper methods.
cwist_error_t cwist_sstring_assign(cwist_sstring *str, const char *data)
Assign a C string.
Simple JSON string builder utility.
const char * cwist_json_get_raw(cwist_json_builder *b)
Returns the raw string buffer. Invalidated on destroy.
void cwist_json_add_string(cwist_json_builder *b, const char *key, const char *value)
Add a string value.
void cwist_json_begin_object(cwist_json_builder *b)
Begin a JSON object.
void cwist_json_end_object(cwist_json_builder *b)
End a JSON object.
void cwist_json_builder_destroy(cwist_json_builder *b)
Destroy a JSON builder.
cwist_json_builder * cwist_json_builder_create(void)
Create a new JSON builder.
void cwist_json_begin_array(cwist_json_builder *b, const char *key)
Begin a JSON array.
void cwist_json_end_array(cwist_json_builder *b)
End a JSON array.
void cwist_healthz_unregister(const char *name)
Deactivate a registered health probe.
#define CWIST_HEALTHZ_MAX_PROBES
struct cwist_healthz_entry cwist_healthz_entry_t
bool cwist_healthz_register(const char *name, cwist_health_probe_fn fn, void *ctx)
Register or update a health probe.
void cwist_healthz_run(cwist_health_probe_t *out_probes, size_t max_probes, size_t *out_count, cwist_health_status_t *out_overall)
Run all active probes and aggregate their results.
void cwist_app_healthz(cwist_http_response *res)
Serve the /healthz HTTP endpoint as a JSON response.
Standardised readiness and liveness probing for CWIST.
cwist_health_probe_t(* cwist_health_probe_fn)(void *ctx)
User-provided probe callback.
enum cwist_health_status cwist_health_status_t
Classification of a subsystem health check.
cwist_error_t cwist_http_header_add(cwist_http_header_node **head, const char *key, const char *value)
Add a header to the list.
@ CWIST_HTTP_SERVICE_UNAVAILABLE
Result of a single probe.
cwist_health_status_t status
HTTP Response Object. Supports standard string body or Zero-Copy pointer body.
cwist_http_status_t status_code
cwist_http_header_node * headers
Simple JSON string builder utility.