Skip to content

add analytics to insight page #7488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions apps/dashboard/src/@/api/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import type {
EcosystemWalletStats,
EngineCloudStats,
InAppWalletStats,
InsightChainStats,
InsightEndpointStats,
InsightStatusCodeStats,
InsightUsageStats,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please move the types in this file next to the functions it is created for

RpcMethodStats,
TransactionStats,
UniversalBridgeStats,
Expand Down Expand Up @@ -424,3 +428,95 @@ export async function getEngineCloudMethodUsage(
const json = await res.json();
return json.data as EngineCloudStats[];
}

export async function getInsightChainUsage(
params: AnalyticsQueryParams,
): Promise<InsightChainStats[]> {
const searchParams = buildSearchParams(params);
const res = await fetchAnalytics(
`v2/insight/usage/by-chain?${searchParams.toString()}`,
{
method: "GET",
},
);

if (res?.status !== 200) {
const reason = await res?.text();
console.error(
`Failed to fetch Insight chain usage: ${res?.status} - ${res.statusText} - ${reason}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is silently failing. we won't know if there's something wrong or not in the frontend if the request is failing or just returning empty data

please return { data: [] } | { errorMessage: ''} instead and show the error in frontend

);
return [];
}

const json = await res.json();
return json.data as InsightChainStats[];
}

export async function getInsightStatusCodeUsage(
params: AnalyticsQueryParams,
): Promise<InsightStatusCodeStats[]> {
const searchParams = buildSearchParams(params);
const res = await fetchAnalytics(
`v2/insight/usage/by-status-code?${searchParams.toString()}`,
{
method: "GET",
},
);

if (res?.status !== 200) {
const reason = await res?.text();
console.error(
`Failed to fetch Insight status code usage: ${res?.status} - ${res.statusText} - ${reason}`,
);
return [];
}

const json = await res.json();
return json.data as InsightStatusCodeStats[];
}

export async function getInsightEndpointUsage(
params: AnalyticsQueryParams,
): Promise<InsightEndpointStats[]> {
const searchParams = buildSearchParams(params);
const res = await fetchAnalytics(
`v2/insight/usage/by-endpoint?${searchParams.toString()}`,
{
method: "GET",
},
);

if (res?.status !== 200) {
const reason = await res?.text();
console.error(
`Failed to fetch Insight endpoint usage: ${res?.status} - ${res.statusText} - ${reason}`,
);
return [];
}

const json = await res.json();
return json.data as InsightEndpointStats[];
}

export async function getInsightUsage(
params: AnalyticsQueryParams,
): Promise<InsightUsageStats[]> {
const searchParams = buildSearchParams(params);
const res = await fetchAnalytics(
`v2/insight/usage?${searchParams.toString()}`,
{
method: "GET",
},
);

if (res?.status !== 200) {
const reason = await res?.text();
console.error(
`Failed to fetch Insight usage: ${res?.status} - ${res.statusText} - ${reason}`,
);
return [];
}

const json = await res.json();
return json.data as InsightUsageStats[];
}
24 changes: 24 additions & 0 deletions apps/dashboard/src/@/types/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,28 @@ export interface AnalyticsQueryParams {
from?: Date;
to?: Date;
period?: "day" | "week" | "month" | "year" | "all";
limit?: number;
}

export interface InsightChainStats {
date: string;
chainId: string;
totalRequests: number;
}

export interface InsightStatusCodeStats {
date: string;
httpStatusCode: number;
totalRequests: number;
}

export interface InsightEndpointStats {
date: string;
endpoint: string;
totalRequests: number;
}

export interface InsightUsageStats {
date: string;
totalRequests: number;
}

This file was deleted.

Loading
Loading