summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_conf_validation.c
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2024-12-19 10:23:57 -0800
committerKonstantin Pavlov <thresh@nginx.com>2024-12-19 10:23:57 -0800
commitd8acad350a52a20918c46c09cb0a0f5479400923 (patch)
tree7d9c4b64daa60d3ac121743dfa3735c6fc5687a4 /src/nxt_conf_validation.c
parent624debcf17ea7faab01fa841bd4dcd9f308cf306 (diff)
parent27bde184dedcbf687db2f314c60c037623318a8d (diff)
downloadunit-d8acad350a52a20918c46c09cb0a0f5479400923.tar.gz
unit-d8acad350a52a20918c46c09cb0a0f5479400923.tar.bz2
Merge tag '1.34.0' into packaging1.34.0-1
Unit 1.34.0 release.
Diffstat (limited to 'src/nxt_conf_validation.c')
-rw-r--r--src/nxt_conf_validation.c152
1 files changed, 151 insertions, 1 deletions
diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c
index 5d7f7c52..a0b4992f 100644
--- a/src/nxt_conf_validation.c
+++ b/src/nxt_conf_validation.c
@@ -216,6 +216,11 @@ static nxt_int_t nxt_conf_vldt_server_weight(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
static nxt_int_t nxt_conf_vldt_access_log(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_conf_vldt_access_log_format(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data);
+static nxt_int_t nxt_conf_vldt_access_log_format_field(
+ nxt_conf_validation_t *vldt, const nxt_str_t *name,
+ nxt_conf_value_t *value);
static nxt_int_t nxt_conf_vldt_isolation(nxt_conf_validation_t *vldt,
nxt_conf_value_t *value, void *data);
@@ -241,9 +246,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 +334,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 +409,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"),
@@ -1418,7 +1470,8 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_access_log_members[] = {
.type = NXT_CONF_VLDT_STRING,
}, {
.name = nxt_string("format"),
- .type = NXT_CONF_VLDT_STRING,
+ .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_OBJECT,
+ .validator = nxt_conf_vldt_access_log_format,
}, {
.name = nxt_string("if"),
.type = NXT_CONF_VLDT_STRING,
@@ -1465,6 +1518,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)
@@ -3523,3 +3630,46 @@ nxt_conf_vldt_access_log(nxt_conf_validation_t *vldt, nxt_conf_value_t *value,
return NXT_OK;
}
+
+
+static nxt_int_t
+nxt_conf_vldt_access_log_format(nxt_conf_validation_t *vldt,
+ nxt_conf_value_t *value, void *data)
+{
+ static const nxt_str_t format = nxt_string("format");
+
+ if (nxt_conf_type(value) == NXT_CONF_OBJECT) {
+ return nxt_conf_vldt_object_iterator(vldt, value,
+ nxt_conf_vldt_access_log_format_field);
+ }
+
+ /* NXT_CONF_STRING */
+
+ return nxt_conf_vldt_access_log_format_field(vldt, &format, value);
+}
+
+
+static nxt_int_t
+nxt_conf_vldt_access_log_format_field(nxt_conf_validation_t *vldt,
+ const nxt_str_t *name, nxt_conf_value_t *value)
+{
+ nxt_str_t str;
+
+ if (name->length == 0) {
+ return nxt_conf_vldt_error(vldt, "In the access log format, the name "
+ "must not be empty.");
+ }
+
+ if (nxt_conf_type(value) != NXT_CONF_STRING) {
+ return nxt_conf_vldt_error(vldt, "In the access log format, the value "
+ "must be a string.");
+ }
+
+ nxt_conf_get_string(value, &str);
+
+ if (nxt_is_tstr(&str)) {
+ return nxt_conf_vldt_var(vldt, name, &str);
+ }
+
+ return NXT_OK;
+}