Skip to content

Commit

Permalink
Implement code cell for Prom config
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Dec 1, 2023
1 parent 13b77ca commit 979caba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions providers/prometheus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ pub(crate) async fn query_config(_query: ConfigQuery, config: Config) -> Result<

Yaml(response.data.yaml).to_blob()
}

pub fn create_code_cell(response: Blob) -> Result<Vec<Cell>> {
let code_cell = Cell::Code(
CodeCell::builder()
.id("config".to_owned())
.content(String::from_utf8(response.data.into()).map_err(|err| {
Error::Deserialization {
message: err.to_string(),
}
})?)
.syntax("yaml")
.build(),
);
Ok(vec![code_cell])
}
3 changes: 2 additions & 1 deletion providers/prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ pdk_query_types! {
}

#[pdk_export]
fn create_cells(query_type: String, _response: Blob) -> Result<Vec<Cell>> {
fn create_cells(query_type: String, response: Blob) -> Result<Vec<Cell>> {
log(format!("Creating cells for query type: {query_type}"));

match query_type.as_str() {
TIMESERIES_QUERY_TYPE => create_graph_cell(),
YAML_MIME_TYPE => create_code_cell(response),
_ => Err(Error::UnsupportedRequest),
}
}
Expand Down

0 comments on commit 979caba

Please sign in to comment.