diff options
author | Ava Hahn <a.hahn@f5.com> | 2024-11-07 14:10:57 -0800 |
---|---|---|
committer | Ava Hahn <110854134+avahahn@users.noreply.github.com> | 2024-11-12 09:50:02 -0800 |
commit | 586c5b536683294981181e334b5af264a4615c74 (patch) | |
tree | 62bdfb4e87ec0925dc0d3118e874b8b1be00fc03 /src/nxt_router.c | |
parent | b9066210ac378a6255c1e3de5fc01ee29904a05c (diff) | |
download | unit-586c5b536683294981181e334b5af264a4615c74.tar.gz unit-586c5b536683294981181e334b5af264a4615c74.tar.bz2 |
otel: configuration items and their validation
Adds code responsible for users to apply the `telemetry` configuration
options.
configuration snippet as follows:
{
"settings": {
"telemetry": {
"batch_size": 20,
"endpoint": "http://lgtm:4318/v1/traces",
"protocol": "http",
"sampling_ratio": 1
}
},
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"match": {
"headers": {
"accept": "*text/html*"
}
},
"action": {
"share": "/usr/share/unit/welcome/welcome.html"
}
},
{
"action": {
"share": "/usr/share/unit/welcome/welcome.md"
}
}
]
}
Signed-off-by: Ava Hahn <a.hahn@f5.com>
Signed-off-by: Gabor Javorszky <g.javorszky@f5.com>
Diffstat (limited to 'src/nxt_router.c')
-rw-r--r-- | src/nxt_router.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c index 076cd134..44ea823b 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -24,6 +24,11 @@ #define NXT_SHARED_PORT_ID 0xFFFFu +#if (NXT_HAVE_OTEL) +#define NXT_OTEL_BATCH_DEFAULT 128 +#define NXT_OTEL_SAMPLING_DEFAULT 1 +#endif + typedef struct { nxt_str_t type; uint32_t processes; @@ -1636,6 +1641,12 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, #if (NXT_HAVE_NJS) nxt_conf_value_t *js_module; #endif +#if (NXT_HAVE_OTEL) + double telemetry_sample_fraction, telemetry_batching; + nxt_str_t telemetry_endpoint, telemetry_proto; + nxt_conf_value_t *otel, *otel_endpoint, *otel_sampling, + *otel_batching, *otel_proto; +#endif nxt_conf_value_t *root, *conf, *http, *value, *websocket; nxt_conf_value_t *applications, *application, *settings; nxt_conf_value_t *listeners, *listener; @@ -1671,6 +1682,17 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, nxt_string("/settings/http/websocket"); static const nxt_str_t forwarded_path = nxt_string("/forwarded"); static const nxt_str_t client_ip_path = nxt_string("/client_ip"); +#if (NXT_HAVE_OTEL) + static const nxt_str_t telemetry_path = nxt_string("/settings/telemetry"); + static const nxt_str_t telemetry_endpoint_path = + nxt_string("/settings/telemetry/endpoint"); + static const nxt_str_t telemetry_batch_path = + nxt_string("/settings/telemetry/batch_size"); + static const nxt_str_t telemetry_sample_path = + nxt_string("/settings/telemetry/sampling_ratio"); + static const nxt_str_t telemetry_proto_path = + nxt_string("/settings/telemetry/protocol"); +#endif root = nxt_conf_json_parse(tmcf->mem_pool, start, end, NULL); if (root == NULL) { @@ -2172,6 +2194,34 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, #endif +#if (NXT_HAVE_OTEL) + otel = nxt_conf_get_path(root, &telemetry_path); + + if (otel) { + otel_endpoint = nxt_conf_get_path(root, &telemetry_endpoint_path); + otel_batching = nxt_conf_get_path(root, &telemetry_batch_path); + otel_sampling = nxt_conf_get_path(root, &telemetry_sample_path); + otel_proto = nxt_conf_get_path(root, &telemetry_proto_path); + + nxt_conf_get_string(otel_endpoint, &telemetry_endpoint); + nxt_conf_get_string(otel_proto, &telemetry_proto); + + telemetry_batching = otel_batching + ? nxt_conf_get_number(otel_batching) + : NXT_OTEL_BATCH_DEFAULT; + + telemetry_sample_fraction = otel_sampling + ? nxt_conf_get_number(otel_sampling) + : NXT_OTEL_SAMPLING_DEFAULT; + + nxt_otel_rs_init(&nxt_otel_log_callback, &telemetry_endpoint, + &telemetry_proto, telemetry_sample_fraction, + telemetry_batching); + } else { + nxt_otel_rs_uninit(); + } +#endif + nxt_queue_add(&deleting_sockets, &router->sockets); nxt_queue_init(&router->sockets); |