mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 05:34:02 +00:00
fix(servers)!: validate UTF-8 in unchecked Prometheus validation mode [Backport release/v1.3] (#10599)
fix(servers)!: validate UTF-8 in unchecked Prometheus validation mode (#10593)
fix(servers): validate UTF-8 in unchecked Prometheus validation mode
prom_validation_mode = "unchecked" built Strings from request bytes with
String::from_utf8_unchecked. Invalid UTF-8 in label values produced
invalid Strings, and the rows were written to WAL entries that fail to
decode on replay.
Make unchecked behave like lossy: invalid sequences are replaced with
U+FFFD. The config value is kept for compatibility.
(cherry picked from commit 3b2b67212a)
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
This commit is contained in:
+2
-2
@@ -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.<br/>Available options:<br/>- strict: deny invalid UTF-8 strings (default).<br/>- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).<br/>- unchecked: do not valid strings. |
|
||||
| `prom_store.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests.<br/>Available options:<br/>- strict: deny invalid UTF-8 strings (default).<br/>- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).<br/>- unchecked: same as `lossy`. Kept for compatibility. |
|
||||
| `wal` | -- | -- | The WAL options. |
|
||||
| `wal.provider` | String | `raft_engine` | The provider of the WAL.<br/>- `raft_engine`: the wal is stored in the local file system by raft-engine.<br/>- `kafka`: it's remote wal that data is stored in Kafka.<br/>- `experimental_object_store`: the wal is stored as objects in an object store.<br/>**Notes: experimental and not supported yet.** |
|
||||
| `wal.dir` | String | Unset | The directory to store the WAL files.<br/>**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.<br/>Available options:<br/>- strict: deny invalid UTF-8 strings (default).<br/>- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).<br/>- unchecked: do not valid strings. |
|
||||
| `prom_store.prom_validation_mode` | String | `strict` | Whether to enable validation for Prometheus remote write requests.<br/>Available options:<br/>- strict: deny invalid UTF-8 strings (default).<br/>- lossy: allow invalid UTF-8 strings, replace invalid characters with REPLACEMENT_CHARACTER(U+FFFD).<br/>- 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. |
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user