summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
authorAva Hahn <a.hahn@f5.com>2024-11-07 14:10:57 -0800
committerAva Hahn <110854134+avahahn@users.noreply.github.com>2024-11-12 09:50:02 -0800
commit586c5b536683294981181e334b5af264a4615c74 (patch)
tree62bdfb4e87ec0925dc0d3118e874b8b1be00fc03 /src/nxt_conf_validation.c
parentb9066210ac378a6255c1e3de5fc01ee29904a05c (diff)
downloadunit-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_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 5d7f7c52..0dde39ff 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -241,9 +241,21 @@ static nxt_int_t nxt_conf_vldt_js_module_element(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value);
#endif
+#if (NXT_HAVE_OTEL)
+static nxt_int_t nxt_otel_validate_batch_size(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_otel_validate_sample_ratio(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_otel_validate_protocol(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+#endif
+
static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[];
static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[];
+#if (NXT_HAVE_OTEL)
+static nxt_conf_vldt_object_t nxt_conf_vldt_otel_members[];
+#endif
static nxt_conf_vldt_object_t nxt_conf_vldt_websocket_members[];
static nxt_conf_vldt_object_t nxt_conf_vldt_static_members[];
static nxt_conf_vldt_object_t nxt_conf_vldt_forwarded_members[];
@@ -317,6 +329,13 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[] = {
.type = NXT_CONF_VLDT_OBJECT,
.validator = nxt_conf_vldt_object,
.u.members = nxt_conf_vldt_http_members,
+#if (NXT_HAVE_OTEL)
+ }, {
+ .name = nxt_string("telemetry"),
+ .type = NXT_CONF_VLDT_OBJECT,
+ .validator = nxt_conf_vldt_object,
+ .u.members = nxt_conf_vldt_otel_members,
+#endif
#if (NXT_HAVE_NJS)
}, {
.name = nxt_string("js_module"),
@@ -385,6 +404,34 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[] = {
};
+#if (NXT_HAVE_OTEL)
+
+static nxt_conf_vldt_object_t nxt_conf_vldt_otel_members[] = {
+ {
+ .name = nxt_string("endpoint"),
+ .type = NXT_CONF_VLDT_STRING,
+ .flags = NXT_CONF_VLDT_REQUIRED
+ }, {
+ .name = nxt_string("batch_size"),
+ .type = NXT_CONF_VLDT_INTEGER,
+ .validator = nxt_otel_validate_batch_size,
+ }, {
+ .name = nxt_string("protocol"),
+ .type = NXT_CONF_VLDT_STRING,
+ .validator = nxt_otel_validate_protocol,
+ .flags = NXT_CONF_VLDT_REQUIRED
+ }, {
+ .name = nxt_string("sampling_ratio"),
+ .type = NXT_CONF_VLDT_NUMBER,
+ .validator = nxt_otel_validate_sample_ratio,
+ },
+
+ NXT_CONF_VLDT_END
+};
+
+#endif
+
+
static nxt_conf_vldt_object_t nxt_conf_vldt_websocket_members[] = {
{
.name = nxt_string("read_timeout"),
@@ -1465,6 +1512,60 @@ nxt_conf_validate(nxt_conf_validation_t *vldt)
"a number, a string, an array, or an object"
+#if (NXT_HAVE_OTEL)
+
+nxt_int_t
+nxt_otel_validate_batch_size(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data)
+{
+ double batch_size;
+
+ batch_size = nxt_conf_get_number(value);
+ if (batch_size <= 0) {
+ return NXT_ERROR;
+ }
+
+ return NXT_OK;
+}
+
+
+nxt_int_t
+nxt_otel_validate_sample_ratio(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data)
+{
+ double sample_ratio;
+
+ sample_ratio = nxt_conf_get_number(value);
+ if (sample_ratio < 0 || sample_ratio > 1) {
+ return NXT_ERROR;
+ }
+
+ return NXT_OK;
+}
+
+
+nxt_int_t
+nxt_otel_validate_protocol(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data)
+{
+ nxt_str_t proto;
+
+ nxt_conf_get_string(value, &proto);
+
+ if (nxt_str_eq(&proto, "HTTP", 4) || nxt_str_eq(&proto, "http", 4)) {
+ return NXT_OK;
+ }
+
+ if (nxt_str_eq(&proto, "GRPC", 4) || nxt_str_eq(&proto, "grpc", 4)) {
+ return NXT_OK;
+ }
+
+ return NXT_ERROR;
+}
+
+#endif
+
+
static nxt_int_t
nxt_conf_vldt_type(nxt_conf_validation_t *vldt, const nxt_str_t *name,
nxt_conf_value_t *value, nxt_conf_vldt_type_t type)