fix(proxy_server.py): introduces a beta endpoint for admin to view global spend

This commit is contained in:
Krrish Dholakia 2024-02-28 12:47:51 -08:00
parent a042092faa
commit 6a94ef6c16
4 changed files with 183 additions and 19 deletions

View file

@ -2,7 +2,11 @@ import { BarChart, Card, Title } from "@tremor/react";
import React, { useState, useEffect } from "react";
import { Grid, Col, Text, LineChart } from "@tremor/react";
import { userSpendLogsCall, keyInfoCall } from "./networking";
import {
userSpendLogsCall,
keyInfoCall,
adminSpendLogsCall,
} from "./networking";
import { start } from "repl";
interface UsagePageProps {
@ -175,27 +179,26 @@ const UsagePage: React.FC<UsagePageProps> = ({
console.log("result from spend logs call", response);
if ("daily_spend" in response) {
// this is from clickhouse analytics
//
//
let daily_spend = response["daily_spend"];
console.log("daily spend", daily_spend);
setKeySpendData(daily_spend);
let topApiKeys = response.top_api_keys;
setTopKeys(topApiKeys);
}
else {
const topKeysResponse = await keyInfoCall(
accessToken,
getTopKeys(response)
);
const filtered_keys = topKeysResponse["info"].map((k: any) => ({
key: (k["key_name"] || k["key_alias"] || k["token"]).substring(
0,
7
),
spend: k["spend"],
}));
setTopKeys(filtered_keys);
setTopUsers(getTopUsers(response));
} else {
// const topKeysResponse = await keyInfoCall(
// accessToken,
// getTopKeys(response)
// );
// const filtered_keys = topKeysResponse["info"].map((k: any) => ({
// key: (k["key_name"] || k["key_alias"] || k["token"]).substring(
// 0,
// 7
// ),
// spend: k["spend"],
// }));
// setTopKeys(filtered_keys);
// setTopUsers(getTopUsers(response));
setKeySpendData(response);
}
});
@ -222,7 +225,7 @@ const UsagePage: React.FC<UsagePageProps> = ({
valueFormatter={valueFormatter}
yAxisWidth={100}
tickGap={5}
customTooltip={customTooltip}
// customTooltip={customTooltip}
/>
</Card>
</Col>