Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix date mutation bug causing 'Today' selector to return no data

Cole McIntoshc42a876735e4
diff --git a/ui/litellm-dashboard/src/components/cache_dashboard.tsx b/ui/litellm-dashboard/src/components/cache_dashboard.tsx
index 37875cb7f9b..2bb6b28af04 100644
--- a/ui/litellm-dashboard/src/components/cache_dashboard.tsx
+++ b/ui/litellm-dashboard/src/components/cache_dashboard.tsx
@@ -161,16 +161,20 @@ const CacheDashboard: React.FC<CachePageProps> = ({
return;
}
+ // Create new Date objects to avoid mutating the original dates
+ const adjustedStartTime = new Date(startTime);
+ const adjustedEndTime = new Date(endTime);
+
// the endTime put it to the last hour of the selected date
- endTime.setHours(23, 59, 59, 999);
+ adjustedEndTime.setHours(23, 59, 59, 999);
// startTime put it to the first hour of the selected date
- startTime.setHours(0, 0, 0, 0);
+ adjustedStartTime.setHours(0, 0, 0, 0);
let new_cache_data = await adminGlobalCacheActivity(
accessToken,
- formatDateWithoutTZ(startTime),
- formatDateWithoutTZ(endTime)
+ formatDateWithoutTZ(adjustedStartTime),
+ formatDateWithoutTZ(adjustedEndTime)
)
setData(new_cache_data);
diff --git a/ui/litellm-dashboard/src/components/model_dashboard.tsx b/ui/litellm-dashboard/src/components/model_dashboard.tsx
index 61f9353bb0b..c40092c3f47 100644
--- a/ui/litellm-dashboard/src/components/model_dashboard.tsx
+++ b/ui/litellm-dashboard/src/components/model_dashboard.tsx
@@ -306,14 +306,18 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
selected_customer = null;
}
+ // Create new Date objects to avoid mutating the original dates
+ const adjustedStartTime = new Date(startTime);
+ const adjustedEndTime = new Date(endTime);
+
// make startTime and endTime to last hour of the day
- startTime.setHours(0);
- startTime.setMinutes(0);
- startTime.setSeconds(0);
+ adjustedStartTime.setHours(0);
+ adjustedStartTime.setMinutes(0);
+ adjustedStartTime.setSeconds(0);
- endTime.setHours(23);
- endTime.setMinutes(59);
- endTime.setSeconds(59);
+ adjustedEndTime.setHours(23);
+ adjustedEndTime.setMinutes(59);
+ adjustedEndTime.setSeconds(59);
try {
const modelMetricsResponse = await modelMetricsCall(
@@ -321,8 +325,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
userID,
userRole,
modelGroup,
- startTime.toISOString(),
- endTime.toISOString(),
+ adjustedStartTime.toISOString(),
+ adjustedEndTime.toISOString(),
selected_token,
selected_customer
);
@@ -335,8 +339,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
const streamingModelMetricsResponse = await streamingModelMetricsCall(
accessToken,
modelGroup,
- startTime.toISOString(),
- endTime.toISOString()
+ adjustedStartTime.toISOString(),
+ adjustedEndTime.toISOString()
);
// Assuming modelMetricsResponse now contains the metric data for the specified model group
@@ -350,8 +354,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
userID,
userRole,
modelGroup,
- startTime.toISOString(),
- endTime.toISOString(),
+ adjustedStartTime.toISOString(),
+ adjustedEndTime.toISOString(),
selected_token,
selected_customer
);
@@ -364,8 +368,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
userID,
userRole,
modelGroup,
- startTime.toISOString(),
- endTime.toISOString(),
+ adjustedStartTime.toISOString(),
+ adjustedEndTime.toISOString(),
selected_token,
selected_customer
);
@@ -378,8 +382,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
if (modelGroup) {
const dailyExceptions = await adminGlobalActivityExceptions(
accessToken,
- startTime?.toISOString().split('T')[0],
- endTime?.toISOString().split('T')[0],
+ adjustedStartTime?.toISOString().split('T')[0],
+ adjustedEndTime?.toISOString().split('T')[0],
modelGroup,
);
@@ -387,8 +391,8 @@ const ModelDashboard: React.FC<ModelDashboardProps> = ({
const dailyExceptionsPerDeplyment = await adminGlobalActivityExceptionsPerDeployment(
accessToken,
- startTime?.toISOString().split('T')[0],
- endTime?.toISOString().split('T')[0],
+ adjustedStartTime?.toISOString().split('T')[0],
+ adjustedEndTime?.toISOString().split('T')[0],
modelGroup,
)
diff --git a/ui/litellm-dashboard/src/components/usage.tsx b/ui/litellm-dashboard/src/components/usage.tsx
index 6779ba7f94f..d1c0ecb87e4 100644
--- a/ui/litellm-dashboard/src/components/usage.tsx
+++ b/ui/litellm-dashboard/src/components/usage.tsx
@@ -213,19 +213,23 @@ const UsagePage: React.FC<UsagePageProps> = ({
return;
}
+ // Create new Date objects to avoid mutating the original dates
+ const adjustedStartTime = new Date(startTime);
+ const adjustedEndTime = new Date(endTime);
+
// the endTime put it to the last hour of the selected date
- endTime.setHours(23, 59, 59, 999);
+ adjustedEndTime.setHours(23, 59, 59, 999);
// startTime put it to the first hour of the selected date
- startTime.setHours(0, 0, 0, 0);
+ adjustedStartTime.setHours(0, 0, 0, 0);
console.log("uiSelectedKey", uiSelectedKey);
let newTopUserData = await adminTopEndUsersCall(
accessToken,
uiSelectedKey,
- startTime.toISOString(),
- endTime.toISOString()
+ adjustedStartTime.toISOString(),
+ adjustedEndTime.toISOString()
)
console.log("End user data updated successfully", newTopUserData);
setTopUsers(newTopUserData);
@@ -245,16 +249,20 @@ const UsagePage: React.FC<UsagePageProps> = ({
return; // Don't run expensive DB queries - return out when SpendLogs has more than 1M rows
}
+ // Create new Date objects to avoid mutating the original dates
+ const adjustedStartTime = new Date(startTime);
+ const adjustedEndTime = new Date(endTime);
+
// the endTime put it to the last hour of the selected date
- endTime.setHours(23, 59, 59, 999);
+ adjustedEndTime.setHours(23, 59, 59, 999);
// startTime put it to the first hour of the selected date
- startTime.setHours(0, 0, 0, 0);
+ adjustedStartTime.setHours(0, 0, 0, 0);
let top_tags = await tagsSpendLogsCall(
accessToken,
- startTime.toISOString(),
- endTime.toISOString(),
+ adjustedStartTime.toISOString(),
+ adjustedEndTime.toISOString(),
selectedTags.length === 0 ? undefined : selectedTags
);
setTopTagsData(top_tags.spend_per_tag);