Skip to content

Commit 88b519c

Browse files
committed
fix: replace json with serde_json
Fixes grafana#139
1 parent 860f7b8 commit 88b519c

File tree

7 files changed

+18
-23
lines changed

7 files changed

+18
-23
lines changed

Cargo.lock

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ libflate = "1.2.0"
6363
libc = "^0.2.124"
6464
prost = "0.11"
6565
winapi = "0.3.9"
66-
json = "0.12.4"
66+
serde_json = "1"
6767

6868
[dev-dependencies]
6969
tokio = { version = "1.18", features = ["full"] }

pyroscope_cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pyroscope = { path = "../", default-features = false }
3838
pyroscope_pprofrs = { path = "../pyroscope_backends/pyroscope_pprofrs", default-features = false }
3939
pyroscope_rbspy = { path = "../pyroscope_backends/pyroscope_rbspy", default-features = false }
4040
pyroscope_pyspy = { path = "../pyroscope_backends/pyroscope_pyspy", default-features = false }
41-
json = "0.12.4"
41+
serde_json = "1.0.115"
4242

4343
[dependencies.clap]
4444
version = "3.2"

pyroscope_cli/src/utils/app_config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl AppConfig {
172172
.map(|s| s.to_string())
173173
.collect::<Vec<String>>();
174174

175-
AppConfig::set("command_args", &json::stringify(command_args))?;
175+
AppConfig::set("command_args", &serde_json::to_string(&command_args)?)?;
176176
}
177177
}
178178
if sub_exec.is_present("log_level") {
@@ -314,9 +314,9 @@ fn set_http_headers(cmd: &clap::ArgMatches) -> Result<()> {
314314
http_headers_map.insert(kv[0].to_string(), kv[1].to_string());
315315
}
316316
}
317-
let http_header = json::stringify(http_headers_map);
317+
let http_header = serde_json::to_string(&http_headers_map)?;
318318
AppConfig::set("http_headers_json", &http_header)?;
319319
};
320320
}
321321
return Ok(());
322-
}
322+
}

pyroscope_cli/src/utils/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub enum Error {
2929

3030
#[error(transparent)]
3131
PyroscopeError(#[from] pyroscope::PyroscopeError),
32+
33+
#[error(transparent)]
34+
Json(#[from] serde_json::Error),
3235
}
3336

3437
impl Error {

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum PyroscopeError {
3131
Io(#[from] std::io::Error),
3232

3333
#[error(transparent)]
34-
Json(#[from] json::JsonError),
34+
Json(#[from] serde_json::Error),
3535
}
3636

3737
impl PyroscopeError {

src/pyroscope.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use crate::{
1818
PyroscopeError,
1919
};
2020

21-
use json;
22-
2321
use crate::backend::BackendImpl;
2422
use crate::pyroscope::Compression::GZIP;
2523
use crate::pyroscope::ReportEncoding::PPROF;
@@ -841,16 +839,16 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
841839

842840
pub fn parse_http_headers_json(http_headers_json: String) -> Result<HashMap<String, String>> {
843841
let mut http_headers = HashMap::new();
844-
let parsed = json::parse(&http_headers_json)?;
842+
let parsed: serde_json::Value = serde_json::from_str(&http_headers_json)?;
845843
if !parsed.is_object() {
846844
return Err(PyroscopeError::AdHoc(format!(
847845
"expected object, got {}",
848846
parsed
849847
)));
850848
}
851-
for (k, v) in parsed.entries() {
849+
for (k, v) in parsed.as_object().unwrap() {
852850
if v.is_string() {
853-
http_headers.insert(k.to_string(), v.to_string());
851+
http_headers.insert(k.to_string(), v.as_str().unwrap().to_string());
854852
} else {
855853
return Err(PyroscopeError::AdHoc(format!(
856854
"invalid http header value, not a string: {}",
@@ -862,17 +860,17 @@ pub fn parse_http_headers_json(http_headers_json: String) -> Result<HashMap<Stri
862860
}
863861

864862
pub fn parse_vec_string_json(s: String) -> Result<Vec<String>> {
865-
let parsed = json::parse(&s)?;
863+
let parsed: serde_json::Value = serde_json::from_str(&s)?;
866864
if !parsed.is_array() {
867865
return Err(PyroscopeError::AdHoc(format!(
868866
"expected array, got {}",
869867
parsed
870868
)));
871869
}
872-
let mut res = Vec::with_capacity(parsed.len());
873-
for v in parsed.members() {
870+
let mut res = Vec::with_capacity(parsed.as_array().unwrap().len());
871+
for v in parsed.as_array().unwrap() {
874872
if v.is_string() {
875-
res.push(v.to_string());
873+
res.push(v.as_str().unwrap().to_string());
876874
} else {
877875
return Err(PyroscopeError::AdHoc(format!(
878876
"invalid element value, not a string: {}",

0 commit comments

Comments
 (0)