Skip to content

Commit

Permalink
Merge pull request #82 from caibirdme/dev
Browse files Browse the repository at this point in the history
feat: preload labels for ck
  • Loading branch information
caibirdme authored Aug 1, 2024
2 parents 6ccd677 + 0eb773f commit 8e3bf6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/storage/ck/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ impl LogStorage for CKLogQuerier {
}

impl CKLogQuerier {
pub async fn init_labels(&self) {
let sql = format!(
"SELECT {} FROM {} WHERE {} >= now() - INTERVAL 5 MINUTE LIMIT 3000",
self.schema.projection().join(","),
self.schema.table(),
self.schema.ts_key(),
);
let rows =
send_query(self.cli.clone(), self.ck_cfg.common.clone(), sql)
.await
.unwrap_or_default();
let mut records = vec![];
for row in rows {
if let Ok(record) = LogRecod::try_from(row) {
records.push(record.into());
}
}
self.record_label(&records).await;
}
async fn record_label(&self, records: &[LogItem]) {
let cfg = self.ck_cfg.label.clone();
for name in Self::collect_svcname(records) {
Expand Down
10 changes: 4 additions & 6 deletions src/storage/ck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ pub mod trace;
pub async fn new_log_source(cfg: ClickhouseLog) -> Result<Box<dyn LogStorage>> {
let cli = Client::builder()
.gzip(true)
.timeout(Duration::from_secs(60))
.timeout(Duration::from_secs(90))
.build()?;
Ok(Box::new(log::CKLogQuerier::new(
cli,
cfg.common.table.clone(),
cfg,
)))
let q = log::CKLogQuerier::new(cli, cfg.common.table.clone(), cfg);
q.init_labels().await;
Ok(Box::new(q))
}

pub async fn new_trace_source(
Expand Down

0 comments on commit 8e3bf6b

Please sign in to comment.