Skip to content

Commit 298335f

Browse files
committed
use base64 encoding
1 parent 13c2c35 commit 298335f

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jemallocator = ["dep:jemallocator-global"]
2727

2828
# Commands
2929
mount = ["dep:fuse_mt"]
30-
prometheus = ["dep:prometheus"]
30+
prometheus = ["dep:prometheus", "dep:base64"]
3131
self-update = ["dep:self_update", "dep:semver"]
3232
tui = ["dep:ratatui", "dep:crossterm", "dep:tui-textarea"]
3333
webdav = [
@@ -97,6 +97,7 @@ semver = { version = "1", optional = true }
9797
simplelog = "0.12"
9898

9999
# commands
100+
base64 = { version = "0.22.1", optional = true }
100101
bytes = { version = "1.9.0", optional = true }
101102
bytesize = "1"
102103
cached = "0.54.0"

src/config.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub(crate) mod hooks;
88
pub(crate) mod progress_options;
99

1010
use std::{
11-
collections::{BTreeMap, HashMap},
11+
collections::BTreeMap,
1212
fmt::{self, Display, Formatter},
1313
path::PathBuf,
1414
};
@@ -283,30 +283,26 @@ impl GlobalOptions {
283283
fn make_url_and_encoded_metrics(
284284
url: &Url,
285285
job: &str,
286-
grouping: HashMap<&str, &str>,
286+
grouping: BTreeMap<&str, &str>,
287287
) -> Result<(Url, Vec<u8>)> {
288+
use base64::prelude::*;
288289
use prometheus::{Encoder, ProtobufEncoder};
289290
const LABEL_NAME_JOB: &str = "job";
290291

291-
if job.contains('/') {
292-
bail!("job contains '/': {}", job);
293-
}
294-
295-
let url = url.join("metrics/job/")?;
296-
// TODO: escape job
297-
let mut url_components = vec![job];
292+
let mut url_components = vec![
293+
"metrics".to_string(),
294+
"job@base64".to_string(),
295+
BASE64_URL_SAFE_NO_PAD.encode(job),
296+
];
298297

299298
for (ln, lv) in &grouping {
300299
// TODO: check label name
301-
if lv.contains('/') {
302-
bail!("value of grouping label {} contains '/': {}", ln, lv);
303-
}
304-
url_components.push(ln);
305-
url_components.push(lv);
300+
let name = ln.to_string() + "@base64";
301+
url_components.push(name);
302+
url_components.push(BASE64_URL_SAFE_NO_PAD.encode(lv));
306303
}
307304

308305
let url = url.join(&url_components.join("/"))?;
309-
310306
let encoder = ProtobufEncoder::new();
311307
let mut buf = Vec::new();
312308

0 commit comments

Comments
 (0)