Skip to content

Commit

Permalink
use base64 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Feb 10, 2025
1 parent 13c2c35 commit 298335f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jemallocator = ["dep:jemallocator-global"]

# Commands
mount = ["dep:fuse_mt"]
prometheus = ["dep:prometheus"]
prometheus = ["dep:prometheus", "dep:base64"]
self-update = ["dep:self_update", "dep:semver"]
tui = ["dep:ratatui", "dep:crossterm", "dep:tui-textarea"]
webdav = [
Expand Down Expand Up @@ -97,6 +97,7 @@ semver = { version = "1", optional = true }
simplelog = "0.12"

# commands
base64 = { version = "0.22.1", optional = true }
bytes = { version = "1.9.0", optional = true }
bytesize = "1"
cached = "0.54.0"
Expand Down
26 changes: 11 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) mod hooks;
pub(crate) mod progress_options;

use std::{
collections::{BTreeMap, HashMap},
collections::BTreeMap,
fmt::{self, Display, Formatter},
path::PathBuf,
};
Expand Down Expand Up @@ -283,30 +283,26 @@ impl GlobalOptions {
fn make_url_and_encoded_metrics(
url: &Url,
job: &str,
grouping: HashMap<&str, &str>,
grouping: BTreeMap<&str, &str>,
) -> Result<(Url, Vec<u8>)> {
use base64::prelude::*;
use prometheus::{Encoder, ProtobufEncoder};
const LABEL_NAME_JOB: &str = "job";

if job.contains('/') {
bail!("job contains '/': {}", job);
}

let url = url.join("metrics/job/")?;
// TODO: escape job
let mut url_components = vec![job];
let mut url_components = vec![
"metrics".to_string(),
"job@base64".to_string(),
BASE64_URL_SAFE_NO_PAD.encode(job),
];

for (ln, lv) in &grouping {
// TODO: check label name
if lv.contains('/') {
bail!("value of grouping label {} contains '/': {}", ln, lv);
}
url_components.push(ln);
url_components.push(lv);
let name = ln.to_string() + "@base64";
url_components.push(name);
url_components.push(BASE64_URL_SAFE_NO_PAD.encode(lv));
}

let url = url.join(&url_components.join("/"))?;

let encoder = ProtobufEncoder::new();
let mut buf = Vec::new();

Expand Down

0 comments on commit 298335f

Please sign in to comment.