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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Feature] UI - Logs: Add 'Last Minute' to time-range quick select
Yuneng Jiangb379f4f98b3b
diff --git a/ui/litellm-dashboard/src/components/view_logs/constants.ts b/ui/litellm-dashboard/src/components/view_logs/constants.tsindex 57155feae23..5b0b1d0fee3 100644--- a/ui/litellm-dashboard/src/components/view_logs/constants.ts+++ b/ui/litellm-dashboard/src/components/view_logs/constants.ts@@ -19,6 +19,7 @@ export const MCP_CALL_TYPES = ["call_mcp_tool", "list_mcp_tools"];export const AGENT_CALL_TYPES = ["asend_message"];export const QUICK_SELECT_OPTIONS: { label: string; value: number; unit: string }[] = [+ { label: "Last Minute", value: 1, unit: "minutes" },{ label: "Last 15 Minutes", value: 15, unit: "minutes" },{ label: "Last Hour", value: 1, unit: "hours" },{ label: "Last 4 Hours", value: 4, unit: "hours" },diff --git a/ui/litellm-dashboard/src/components/view_logs/index.test.tsx b/ui/litellm-dashboard/src/components/view_logs/index.test.tsxindex 937844e1c1d..7a9a541d3e0 100644--- a/ui/litellm-dashboard/src/components/view_logs/index.test.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/index.test.tsx@@ -1,10 +1,12 @@import { render, screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";+import moment from "moment";import { beforeEach, describe, expect, it, vi } from "vitest";import SpendLogsTable, { RequestViewer } from "./index";import type { LogEntry } from "./columns";import type { Row } from "@tanstack/react-table";import { renderWithProviders } from "../../../tests/test-utils";+import { uiSpendLogsCall } from "../networking";const mockHandleFilterResetFromHook = vi.fn();vi.mock("./log_filter_logic", async (importOriginal) => {@@ -238,4 +240,52 @@ describe("SpendLogsTable", () => {expect(inputsAfterReset.length).toBe(0);});});++ describe("Quick Select time range", () => {+ const waitForWindowSeconds = async (minMinutes: number) => {+ let diff = -1;+ await waitFor(() => {+ const lastCall = vi.mocked(uiSpendLogsCall).mock.calls.at(-1)?.[0];+ if (!lastCall) throw new Error("uiSpendLogsCall was not called");+ diff = moment+ .utc(lastCall.end_date, "YYYY-MM-DD HH:mm:ss")+ .diff(moment.utc(lastCall.start_date, "YYYY-MM-DD HH:mm:ss"), "seconds");+ // start_date is rounded down to the minute boundary; end_date is current time+ expect(diff).toBeGreaterThanOrEqual(minMinutes * 60);+ expect(diff).toBeLessThan((minMinutes + 1) * 60);+ });+ return diff;+ };++ it("should pass a ~1-minute window to uiSpendLogsCall when 'Last Minute' is selected", async () => {+ const user = userEvent.setup();+ renderWithProviders(<SpendLogsTable {...defaultProps} />);++ await user.click(screen.getByRole("button", { name: /Last 24 Hours/i }));+ await user.click(await screen.findByRole("button", { name: "Last Minute" }));++ await waitForWindowSeconds(1);+ });++ it("should pass a ~15-minute window to uiSpendLogsCall when 'Last 15 Minutes' is selected", async () => {+ const user = userEvent.setup();+ renderWithProviders(<SpendLogsTable {...defaultProps} />);++ await user.click(screen.getByRole("button", { name: /Last 24 Hours/i }));+ await user.click(await screen.findByRole("button", { name: "Last 15 Minutes" }));++ await waitForWindowSeconds(15);+ });++ it("should update the time-range button label to 'Last Minute' after selecting it", async () => {+ const user = userEvent.setup();+ renderWithProviders(<SpendLogsTable {...defaultProps} />);++ await user.click(screen.getByRole("button", { name: /Last 24 Hours/i }));+ await user.click(await screen.findByRole("button", { name: "Last Minute" }));++ expect(screen.getByRole("button", { name: "Last Minute" })).toBeInTheDocument();+ expect(screen.queryByRole("button", { name: /Last 24 Hours/i })).not.toBeInTheDocument();+ });+ });});