mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 09:27:46 +08:00
chore: pass fmt clippy and nextest checks
Format merged Rust sources, satisfy strict clippy lints, and restore documentation fixtures required by format registry tests. Validation: cargo fmt --all --check; CI-scoped clippy with -D warnings; cargo nextest workspace excluding integration tests, 9747 passed and 47 skipped; targeted PostgreSQL analytics regression passed.
This commit is contained in:
@@ -486,7 +486,10 @@ async fn live_overview_canonical_queries_and_dirty_rebuild() {
|
||||
let state = sqlx::query("SELECT source_revision,built_revision FROM stats_bucket_state WHERE projection_version='overview-v2' AND granularity='hour' AND bucket_start=$1").bind(start).fetch_one(&pool).await.unwrap();
|
||||
// Bucket state stays unchanged on the foreground write; pending events
|
||||
// invalidate the projection before the background merger consumes them.
|
||||
assert_eq!(state.get::<i64, _>("source_revision"), state.get::<i64, _>("built_revision"));
|
||||
assert_eq!(
|
||||
state.get::<i64, _>("source_revision"),
|
||||
state.get::<i64, _>("built_revision")
|
||||
);
|
||||
let pending: bool = sqlx::query_scalar("SELECT EXISTS(SELECT 1 FROM stats_overview_dirty_events WHERE projection_version='overview-v2' AND granularity='hour' AND bucket_start=$1)")
|
||||
.bind(start).fetch_one(&pool).await.unwrap();
|
||||
assert!(pending);
|
||||
@@ -607,12 +610,21 @@ async fn live_overview_dirty_events_merge_without_shared_writer_bucket_lock() {
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(row, (2, "unrecoverable".into(), Some("retained usage facts were deleted".into())));
|
||||
let remaining: i64 = sqlx::query_scalar("SELECT count(*) FROM stats_overview_dirty_events WHERE bucket_start=$1")
|
||||
.bind(bucket)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
row,
|
||||
(
|
||||
2,
|
||||
"unrecoverable".into(),
|
||||
Some("retained usage facts were deleted".into())
|
||||
)
|
||||
);
|
||||
let remaining: i64 = sqlx::query_scalar(
|
||||
"SELECT count(*) FROM stats_overview_dirty_events WHERE bucket_start=$1",
|
||||
)
|
||||
.bind(bucket)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(remaining, 0);
|
||||
sqlx::query("DELETE FROM stats_bucket_state WHERE projection_version='overview-v2' AND granularity='hour' AND bucket_start=$1")
|
||||
.bind(bucket)
|
||||
|
||||
@@ -63,8 +63,8 @@ mod analytics_tests;
|
||||
mod attribution;
|
||||
pub mod cleanup;
|
||||
mod dashboard;
|
||||
mod dashboard_summary;
|
||||
mod dashboard_retention;
|
||||
mod dashboard_summary;
|
||||
#[cfg(test)]
|
||||
mod dashboard_summary_tests;
|
||||
mod health;
|
||||
@@ -82,25 +82,29 @@ const FIND_USAGE_BODY_BLOB_BY_REF_SQL: &str = r#"SELECT CASE WHEN octet_length(p
|
||||
const DELETE_USAGE_BODY_BLOB_SQL: &str = include_str!("queries/delete_usage_body_blob_sql.sql");
|
||||
static USAGE_BODY_DECODE_SLOTS: tokio::sync::Semaphore = tokio::sync::Semaphore::const_new(4);
|
||||
|
||||
struct UsageAnalyticsDrilldown<'a> {
|
||||
provider_id: Option<&'a str>,
|
||||
api_key_id: Option<&'a str>,
|
||||
request_id: Option<&'a str>,
|
||||
attribution_kind: Option<&'a str>,
|
||||
actor_user_id: Option<&'a str>,
|
||||
endpoint_kind: Option<&'a str>,
|
||||
request_type: Option<&'a str>,
|
||||
slow_threshold_ms: Option<u64>,
|
||||
has_format_conversion: Option<bool>,
|
||||
}
|
||||
|
||||
fn push_usage_analytics_drilldown(
|
||||
builder: &mut QueryBuilder<'_, Postgres>,
|
||||
has_where: &mut bool,
|
||||
provider_id: &Option<String>,
|
||||
api_key_id: &Option<String>,
|
||||
request_id: &Option<String>,
|
||||
attribution_kind: &Option<String>,
|
||||
actor_user_id: &Option<String>,
|
||||
endpoint_kind: &Option<String>,
|
||||
request_type: &Option<String>,
|
||||
slow_threshold_ms: Option<u64>,
|
||||
has_format_conversion: Option<bool>,
|
||||
filters: UsageAnalyticsDrilldown<'_>,
|
||||
) {
|
||||
for (column, value) in [
|
||||
("provider_id", provider_id),
|
||||
("api_key_id", api_key_id),
|
||||
("request_id", request_id),
|
||||
("endpoint_kind", endpoint_kind),
|
||||
("request_type", request_type),
|
||||
("provider_id", filters.provider_id),
|
||||
("api_key_id", filters.api_key_id),
|
||||
("request_id", filters.request_id),
|
||||
("endpoint_kind", filters.endpoint_kind),
|
||||
("request_type", filters.request_type),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
builder.push(if *has_where { " AND " } else { " WHERE " });
|
||||
@@ -109,27 +113,27 @@ fn push_usage_analytics_drilldown(
|
||||
.push("\"usage\".")
|
||||
.push(column)
|
||||
.push(" = ")
|
||||
.push_bind(value.clone());
|
||||
.push_bind(value.to_string());
|
||||
}
|
||||
}
|
||||
for (column, value) in [
|
||||
("attribution_kind", attribution_kind),
|
||||
("actor_user_id", actor_user_id),
|
||||
("attribution_kind", filters.attribution_kind),
|
||||
("actor_user_id", filters.actor_user_id),
|
||||
] {
|
||||
if let Some(value) = value {
|
||||
builder.push(if *has_where { " AND " } else { " WHERE " });
|
||||
*has_where = true;
|
||||
builder.push("EXISTS(SELECT 1 FROM usage_analytics_facts_v1 f WHERE f.request_id=\"usage\".request_id AND f.").push(column).push(" = ").push_bind(value.clone()).push(")");
|
||||
builder.push("EXISTS(SELECT 1 FROM usage_analytics_facts_v1 f WHERE f.request_id=\"usage\".request_id AND f.").push(column).push(" = ").push_bind(value.to_string()).push(")");
|
||||
}
|
||||
}
|
||||
if let Some(value) = slow_threshold_ms {
|
||||
if let Some(value) = filters.slow_threshold_ms {
|
||||
builder.push(if *has_where { " AND " } else { " WHERE " });
|
||||
*has_where = true;
|
||||
builder
|
||||
.push("\"usage\".response_time_ms >= ")
|
||||
.push_bind(i64::try_from(value).unwrap_or(i64::MAX));
|
||||
}
|
||||
if let Some(value) = has_format_conversion {
|
||||
if let Some(value) = filters.has_format_conversion {
|
||||
builder.push(if *has_where { " AND " } else { " WHERE " });
|
||||
*has_where = true;
|
||||
builder
|
||||
@@ -3168,15 +3172,17 @@ ORDER BY request_count DESC, "usage".provider_name ASC
|
||||
push_usage_analytics_drilldown(
|
||||
&mut builder,
|
||||
&mut has_where,
|
||||
&query.provider_id,
|
||||
&query.api_key_id,
|
||||
&query.request_id,
|
||||
&query.attribution_kind,
|
||||
&query.actor_user_id,
|
||||
&query.endpoint_kind,
|
||||
&query.request_type,
|
||||
query.slow_threshold_ms,
|
||||
query.has_format_conversion,
|
||||
UsageAnalyticsDrilldown {
|
||||
provider_id: query.provider_id.as_deref(),
|
||||
api_key_id: query.api_key_id.as_deref(),
|
||||
request_id: query.request_id.as_deref(),
|
||||
attribution_kind: query.attribution_kind.as_deref(),
|
||||
actor_user_id: query.actor_user_id.as_deref(),
|
||||
endpoint_kind: query.endpoint_kind.as_deref(),
|
||||
request_type: query.request_type.as_deref(),
|
||||
slow_threshold_ms: query.slow_threshold_ms,
|
||||
has_format_conversion: query.has_format_conversion,
|
||||
},
|
||||
);
|
||||
if let Some(user_id) = query.user_id.as_deref() {
|
||||
builder.push(if has_where { " AND " } else { " WHERE " });
|
||||
@@ -3294,15 +3300,17 @@ OR (\"usage\".error_message IS NOT NULL AND BTRIM(\"usage\".error_message) <> ''
|
||||
push_usage_analytics_drilldown(
|
||||
&mut builder,
|
||||
&mut has_where,
|
||||
&query.provider_id,
|
||||
&query.api_key_id,
|
||||
&query.request_id,
|
||||
&query.attribution_kind,
|
||||
&query.actor_user_id,
|
||||
&query.endpoint_kind,
|
||||
&query.request_type,
|
||||
query.slow_threshold_ms,
|
||||
query.has_format_conversion,
|
||||
UsageAnalyticsDrilldown {
|
||||
provider_id: query.provider_id.as_deref(),
|
||||
api_key_id: query.api_key_id.as_deref(),
|
||||
request_id: query.request_id.as_deref(),
|
||||
attribution_kind: query.attribution_kind.as_deref(),
|
||||
actor_user_id: query.actor_user_id.as_deref(),
|
||||
endpoint_kind: query.endpoint_kind.as_deref(),
|
||||
request_type: query.request_type.as_deref(),
|
||||
slow_threshold_ms: query.slow_threshold_ms,
|
||||
has_format_conversion: query.has_format_conversion,
|
||||
},
|
||||
);
|
||||
if let Some(user_id) = query.user_id.as_deref() {
|
||||
builder.push(if has_where { " AND " } else { " WHERE " });
|
||||
@@ -3501,15 +3509,17 @@ OR (\"usage\".error_message IS NOT NULL AND BTRIM(\"usage\".error_message) <> ''
|
||||
push_usage_analytics_drilldown(
|
||||
&mut builder,
|
||||
&mut has_where,
|
||||
&query.provider_id,
|
||||
&query.api_key_id,
|
||||
&query.request_id,
|
||||
&query.attribution_kind,
|
||||
&query.actor_user_id,
|
||||
&query.endpoint_kind,
|
||||
&query.request_type,
|
||||
query.slow_threshold_ms,
|
||||
query.has_format_conversion,
|
||||
UsageAnalyticsDrilldown {
|
||||
provider_id: query.provider_id.as_deref(),
|
||||
api_key_id: query.api_key_id.as_deref(),
|
||||
request_id: query.request_id.as_deref(),
|
||||
attribution_kind: query.attribution_kind.as_deref(),
|
||||
actor_user_id: query.actor_user_id.as_deref(),
|
||||
endpoint_kind: query.endpoint_kind.as_deref(),
|
||||
request_type: query.request_type.as_deref(),
|
||||
slow_threshold_ms: query.slow_threshold_ms,
|
||||
has_format_conversion: query.has_format_conversion,
|
||||
},
|
||||
);
|
||||
if let Some(user_id) = query.user_id.as_deref() {
|
||||
builder.push(if has_where { " AND " } else { " WHERE " });
|
||||
@@ -3616,15 +3626,17 @@ OR (\"usage\".error_message IS NOT NULL AND BTRIM(\"usage\".error_message) <> ''
|
||||
push_usage_analytics_drilldown(
|
||||
&mut builder,
|
||||
&mut has_where,
|
||||
&query.provider_id,
|
||||
&query.api_key_id,
|
||||
&query.request_id,
|
||||
&query.attribution_kind,
|
||||
&query.actor_user_id,
|
||||
&query.endpoint_kind,
|
||||
&query.request_type,
|
||||
query.slow_threshold_ms,
|
||||
query.has_format_conversion,
|
||||
UsageAnalyticsDrilldown {
|
||||
provider_id: query.provider_id.as_deref(),
|
||||
api_key_id: query.api_key_id.as_deref(),
|
||||
request_id: query.request_id.as_deref(),
|
||||
attribution_kind: query.attribution_kind.as_deref(),
|
||||
actor_user_id: query.actor_user_id.as_deref(),
|
||||
endpoint_kind: query.endpoint_kind.as_deref(),
|
||||
request_type: query.request_type.as_deref(),
|
||||
slow_threshold_ms: query.slow_threshold_ms,
|
||||
has_format_conversion: query.has_format_conversion,
|
||||
},
|
||||
);
|
||||
if let Some(user_id) = query.user_id.as_deref() {
|
||||
builder.push(if has_where { " AND " } else { " WHERE " });
|
||||
@@ -10528,7 +10540,8 @@ impl UsageReadRepository for SqlxUsageReadRepository {
|
||||
async fn query_dashboard_summary(
|
||||
&self,
|
||||
query: &aether_data_contracts::repository::usage::UsageDashboardAnalyticsQuery,
|
||||
) -> Result<aether_data_contracts::repository::usage::StoredDashboardSummary, DataLayerError> {
|
||||
) -> Result<aether_data_contracts::repository::usage::StoredDashboardSummary, DataLayerError>
|
||||
{
|
||||
Self::query_dashboard_summary(self, query).await
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::analytics::{
|
||||
analytics_additive_metrics_sql, dashboard_total_metrics_sql, push_analytics_filter,
|
||||
};
|
||||
use crate::error::SqlxResultExt;
|
||||
use aether_data_contracts::{DataLayerError, repository::usage::*};
|
||||
use aether_data_contracts::{repository::usage::*, DataLayerError};
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::{Postgres, QueryBuilder, Row};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user