mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
a9441879c3
Some checks are pending
CI / Check formatting and spelling (push) Waiting to run
CI / (macOS) Run Clippy and tests (push) Waiting to run
CI / (Linux) Run Clippy and tests (push) Waiting to run
CI / (Windows) Run Clippy and tests (push) Waiting to run
CI / Create a macOS bundle (push) Blocked by required conditions
CI / Create a Linux bundle (push) Blocked by required conditions
CI / Create arm64 Linux bundle (push) Blocked by required conditions
Deploy Docs / Deploy Docs (push) Waiting to run
Docs / Check formatting (push) Waiting to run
This PR fixes the writing of LLM rate limit events to Clickhouse. We had a table in the table name: `llm_rate_limits` instead of `llm_rate_limit_events`. I also extracted a helper function to write to Clickhouse so we can use it anywhere we need to. Release Notes: - N/A
28 lines
679 B
Rust
28 lines
679 B
Rust
use serde::Serialize;
|
|
|
|
/// Writes the given rows to the specified Clickhouse table.
|
|
pub async fn write_to_table<T: clickhouse::Row + Serialize + std::fmt::Debug>(
|
|
table: &str,
|
|
rows: &[T],
|
|
clickhouse_client: &clickhouse::Client,
|
|
) -> anyhow::Result<()> {
|
|
if rows.is_empty() {
|
|
return Ok(());
|
|
}
|
|
|
|
let mut insert = clickhouse_client.insert(table)?;
|
|
|
|
for event in rows {
|
|
insert.write(event).await?;
|
|
}
|
|
|
|
insert.end().await?;
|
|
|
|
let event_count = rows.len();
|
|
log::info!(
|
|
"wrote {event_count} {event_specifier} to '{table}'",
|
|
event_specifier = if event_count == 1 { "event" } else { "events" }
|
|
);
|
|
|
|
Ok(())
|
|
}
|