diff --git a/config/config.md b/config/config.md index c19bdd4d35a..63c62ea96e5 100644 --- a/config/config.md +++ b/config/config.md @@ -99,7 +99,7 @@ | `prom_store` | -- | -- | Prometheus remote storage options | | `prom_store.enable` | Bool | `true` | Whether to enable Prometheus remote write and read in HTTP API. | | `prom_store.with_metric_engine` | Bool | `true` | Whether to store the data from Prometheus remote write in metric engine. | -| `prom_store.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests.
Available options:
- strict: deny invalid UTF-8 strings (default).
- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).
- unchecked: do not valid strings. | +| `prom_store.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests.
Available options:
- strict: deny invalid UTF-8 strings (default).
- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).
- unchecked: same as `lossy`. Kept for compatibility. | | `wal` | -- | -- | The WAL options. | | `wal.provider` | String | `raft_engine` | The provider of the WAL.
- `raft_engine`: the wal is stored in the local file system by raft-engine.
- `kafka`: it's remote wal that data is stored in Kafka.
- `experimental_object_store`: the wal is stored as objects in an object store.
**Notes: experimental and not supported yet.** | | `wal.dir` | String | Unset | The directory to store the WAL files.
**It's only used when the provider is `raft_engine`**. | @@ -374,7 +374,7 @@ | `prom_store` | -- | -- | Prometheus remote storage options | | `prom_store.enable` | Bool | `true` | Whether to enable Prometheus remote write and read in HTTP API. | | `prom_store.with_metric_engine` | Bool | `true` | Whether to store the data from Prometheus remote write in metric engine. | -| `prom_store.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests.
Available options:
- strict: deny invalid UTF-8 strings (default).
- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).
- unchecked: do not valid strings. | +| `prom_store.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests.
Available options:
- strict: deny invalid UTF-8 strings (default).
- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).
- unchecked: same as `lossy`. Kept for compatibility. | | `meta_client` | -- | -- | The metasrv client options. | | `meta_client.metasrv_addrs` | Array | -- | The addresses of the metasrv. | | `meta_client.timeout` | String | `3s` | Operation timeout. | diff --git a/config/frontend.example.toml b/config/frontend.example.toml index 8d6a353f123..a42fa717724 100644 --- a/config/frontend.example.toml +++ b/config/frontend.example.toml @@ -319,7 +319,7 @@ with_metric_engine = true ## Available options: ## - strict: deny invalid UTF-8 strings (default). ## - lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD). -## - unchecked: do not valid strings. +## - unchecked: same as `lossy`. Kept for compatibility. prom_validation_mode = "strict" diff --git a/config/standalone.example.toml b/config/standalone.example.toml index 3e9cc3c409c..8caf3709690 100644 --- a/config/standalone.example.toml +++ b/config/standalone.example.toml @@ -299,7 +299,7 @@ with_metric_engine = true ## Available options: ## - strict: deny invalid UTF-8 strings (default). ## - lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD). -## - unchecked: do not valid strings. +## - unchecked: same as `lossy`. Kept for compatibility. prom_validation_mode = "strict" diff --git a/src/servers/src/prom_remote_write/decode.rs b/src/servers/src/prom_remote_write/decode.rs index f7324b4be6e..7f789407d0e 100644 --- a/src/servers/src/prom_remote_write/decode.rs +++ b/src/servers/src/prom_remote_write/decode.rs @@ -611,4 +611,13 @@ mod tests { assert_eq!(lossy_result, "simple_ascii_123"); assert_eq!(unchecked_result, "simple_ascii_123"); } + + #[test] + fn test_decode_string_unchecked_replaces_invalid_utf8() { + let invalid = Bytes::from_static(b"a\xffb"); + let result = PromValidationMode::Unchecked + .decode_string(&invalid) + .unwrap(); + assert_eq!(result, "a\u{FFFD}b"); + } } diff --git a/src/servers/src/prom_remote_write/validation.rs b/src/servers/src/prom_remote_write/validation.rs index 6d93db04d77..04e6e850881 100644 --- a/src/servers/src/prom_remote_write/validation.rs +++ b/src/servers/src/prom_remote_write/validation.rs @@ -90,8 +90,10 @@ impl PromValidationMode { return Err(DecodeError::new("invalid utf-8")); } }, - PromValidationMode::Lossy => String::from_utf8_lossy(bytes).to_string(), - PromValidationMode::Unchecked => unsafe { String::from_utf8_unchecked(bytes.to_vec()) }, + // `Unchecked` is accepted for config compatibility and decodes like `Lossy`. + PromValidationMode::Lossy | PromValidationMode::Unchecked => { + String::from_utf8_lossy(bytes).into_owned() + } }; Ok(result) }