metrics: encode influxdb org and bucket parameters

In order to remove the current limitations on the bucket and
organization names, we need to make sure that they are transmitted
correctly. In order to do this, we encode them using the url crate.

This way we support organization/bucket names that include slashes,
whitespaces, etc.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
This commit is contained in:
Gabriel Goller 2024-04-26 16:02:42 +02:00 committed by Thomas Lamprecht
parent 5987eb0c3f
commit bfa73aadf8
2 changed files with 7 additions and 1 deletions

View File

@ -18,6 +18,7 @@ openssl.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = [ "net", "sync" ] }
url.workspace = true
proxmox-async.workspace = true
proxmox-http = { workspace = true, features = [ "client" ] }

View File

@ -93,12 +93,17 @@ impl InfluxDbHttp {
""
};
let encoded_org: String =
url::form_urlencoded::byte_serialize(organization.as_bytes()).collect();
let encoded_bucket: String =
url::form_urlencoded::byte_serialize(bucket.as_bytes()).collect();
let writeuri = http::uri::Builder::new()
.scheme(uri_parts.scheme.clone().unwrap())
.authority(uri_parts.authority.clone().unwrap())
.path_and_query(format!(
"{}/api/v2/write?org={}&bucket={}",
base_path, organization, bucket
base_path, encoded_org, encoded_bucket
))
.build()?;