Skip to content

Commit d56a198

Browse files
committed
feat: Cache tag and user lookups
1 parent a1da9db commit d56a198

11 files changed

Lines changed: 557 additions & 176 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ futures = { version = "0.3" }
2626
hyper = "1.4"
2727
indoc = "2.0"
2828
ldap3 = { version = "0.12", features = ["gssapi", "tls"] }
29-
md5 = "0.7"
30-
moka = { version = "0.12", features = ["future"] }
29+
md5 = "0.8"
30+
moka = { version = "0.12", default-features = false, features = ["future"] }
3131
native-tls = "0.2.12"
3232
pin-project = "1.1"
3333
# `default-features = false` drops reqwest 0.13's `default-tls = ["rustls"]`; we select

_TEST/rif.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"cache": {
3+
"entryTimeToLive": "0s"
4+
},
25
"backend": {
36
"dataHub": {
47
"hostname": "localhost",

rust/info-fetcher-commons/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ rustls-pki-types.workspace = true
1919
serde.workspace = true
2020
serde_json.workspace = true
2121
snafu.workspace = true
22+
tracing.workspace = true
2223
tokio.workspace = true

rust/info-fetcher-commons/src/utils/http.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ use hyper::StatusCode;
22
use reqwest::{RequestBuilder, Response};
33
use serde::de::DeserializeOwned;
44
use snafu::{ResultExt, Snafu};
5+
use tracing::{instrument, trace};
56

67
#[derive(Snafu, Debug)]
78
pub enum Error {
89
#[snafu(display("failed to execute request"))]
910
HttpRequest { source: reqwest::Error },
1011

1112
#[snafu(display("failed to parse json response"))]
12-
ParseJson { source: reqwest::Error },
13+
ParseJson { source: serde_json::Error },
1314

1415
#[snafu(display("http response {status:?} for {url:?} with response body {text:?}"))]
1516
HttpErrorResponse {
@@ -26,14 +27,19 @@ pub enum Error {
2627
},
2728
}
2829

30+
#[instrument(skip_all)]
2931
pub async fn send_json_request<T: DeserializeOwned>(req: RequestBuilder) -> Result<T, Error> {
3032
// make the request
3133
let response = req.send().await.context(HttpRequestSnafu)?;
3234
// check for client or server errors
35+
let url = response.url().clone();
3336
let non_error_response = error_for_status(response).await?;
3437
// parse the result
35-
let result = non_error_response.json().await.context(ParseJsonSnafu)?;
36-
Ok(result)
38+
let json = non_error_response.text().await.context(HttpRequestSnafu)?;
39+
40+
trace!(%url, json, "Got HTTP JSON response");
41+
42+
serde_json::from_str(&json).context(ParseJsonSnafu)
3743
}
3844

3945
/// Wraps a Response into a Result. If there is an HTTP Client or Server error,

rust/resource-info-fetcher/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ reqwest.workspace = true
2323
serde.workspace = true
2424
serde_json.workspace = true
2525
snafu.workspace = true
26+
strum.workspace = true
2627
tokio.workspace = true
2728
tracing.workspace = true
2829
url.workspace = true

rust/resource-info-fetcher/src/api.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::sync::Arc;
2+
13
use hyper::StatusCode;
24
use info_fetcher_commons::http_error;
35
use serde::{Deserialize, Serialize};
@@ -26,8 +28,6 @@ pub struct ResourceInfoRequest {
2628

2729
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
2830
#[serde(rename_all = "camelCase")]
29-
// Soon there will be something else than Trino
30-
#[expect(clippy::enum_variant_names)]
3131
pub enum ResourceInfoRequestResource {
3232
TrinoTable {
3333
catalog: String,
@@ -41,6 +41,11 @@ pub enum ResourceInfoRequestResource {
4141
TrinoCatalog {
4242
catalog: String,
4343
},
44+
45+
SupersetChart(String),
46+
SupersetDashboard(String),
47+
48+
RawDataHubUrn(String),
4449
}
4550

4651
#[derive(Snafu, Debug)]
@@ -53,6 +58,14 @@ pub enum GetResourceInfoError {
5358
display("failed to get resource information from DataHub")
5459
)]
5560
DataHub { source: backend::data_hub::Error },
61+
62+
#[snafu(
63+
visibility(pub(crate)),
64+
display("failed to get user information from DataHub")
65+
)]
66+
GetDataHubUser {
67+
source: Arc<backend::data_hub::Error>,
68+
},
5669
}
5770

5871
impl http_error::Error for GetResourceInfoError {
@@ -66,6 +79,7 @@ impl http_error::Error for GetResourceInfoError {
6679
match self {
6780
Self::SerializeResponseAsJson { .. } => StatusCode::INTERNAL_SERVER_ERROR,
6881
Self::DataHub { source } => source.status_code(),
82+
Self::GetDataHubUser { source } => source.status_code(),
6983
}
7084
}
7185
}

0 commit comments

Comments
 (0)