Skip to content

Commit

Permalink
removed serverless endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AmineAfia committed Jul 29, 2024
1 parent 8d850fa commit 1c55ca5
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 254 deletions.
4 changes: 4 additions & 0 deletions apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { ResultItem } from "components/engine/status/components/StatusCodes";
import { THIRDWEB_API_HOST } from "constants/urls";
import { useState } from "react";
import { useActiveAccount, useActiveWalletChain } from "thirdweb/react";
Expand Down Expand Up @@ -1450,6 +1451,9 @@ export interface EngineResourceMetrics {
cpu: number;
memory: number;
};
errorRate: { data: { result: ResultItem[] } };
statusCodes: { data: { result: ResultItem[] } };
requestVolume: { data: { result: ResultItem[] } };
}

export function useEngineResourceMetrics(engineId: string) {
Expand Down
45 changes: 0 additions & 45 deletions apps/dashboard/src/app/api/engine-status/errors/route.ts

This file was deleted.

54 changes: 0 additions & 54 deletions apps/dashboard/src/app/api/engine-status/prometheus/route.ts

This file was deleted.

61 changes: 0 additions & 61 deletions apps/dashboard/src/app/api/engine-status/status-codes/route.ts

This file was deleted.

44 changes: 0 additions & 44 deletions apps/dashboard/src/app/api/engine-status/volume/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import { useQuery } from "@tanstack/react-query";
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts";

import {
Expand All @@ -18,20 +17,39 @@ import {
} from "@/components/ui/chart";
import { Skeleton } from "@chakra-ui/react";
import { useMemo } from "react";
import type { ResultItem } from "./StatusCodes";

export function ErrorRate() {
const monitorData = useQuery(["errorRate"], async () => {
const res = await fetch("/api/engine-status/errors", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({}),
});
function transformPrometheusData(
prometheusResult: { data: { result: ResultItem[] } } | undefined,
) {
if (
!prometheusResult ||
!prometheusResult.data ||
!prometheusResult.data.result
) {
throw new TypeError("Invalid Prometheus result format");
}

const json = await res.json();
return json;
});
const results = [];
for (const resultItem of prometheusResult.data.result) {
for (const [timestamp, value] of resultItem.values) {
results.push({
time: new Date(timestamp * 1000).toISOString(),
value: value,
});
}
}

return {
data: results,
tags: ["value"],
};
}

export function ErrorRate(
errorRateData: { data: { result: ResultItem[] } } | undefined,
) {
const monitorData = transformPrometheusData(errorRateData);

const chartConfig: { [key: string]: { label: string; color: string } } = {
value: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { ToolTipLabel } from "@/components/ui/tooltip";
import { useQuery } from "@tanstack/react-query";
import { PrimaryInfoItem } from "app/(dashboard)/(chain)/[chain_id]/(chainPage)/components/server/primary-info-item";
import { CircleCheck, XIcon } from "lucide-react";
import { useState } from "react";

function useEngineHealthStats(engineUrlBase: string) {
const [shouldRefetch, setShouldRefetch] = useState(true);
const engineUrl = `${engineUrlBase}/system/health`;
return useQuery({
queryKey: ["engine-stats", { engineUrl }],
queryKey: ["engine-stats", engineUrlBase, "healthcheck", { engineUrl }],
queryFn: async () => {
const startTimeStamp = performance.now();
const res = await fetch(engineUrl);
Expand All @@ -24,12 +22,9 @@ function useEngineHealthStats(engineUrlBase: string) {
status: json.status,
};
},
refetchInterval: shouldRefetch ? 5 * 1000 : undefined,
refetchInterval: 5 * 1000,
enabled: !!engineUrl,
refetchOnWindowFocus: false,
onError: () => {
setShouldRefetch(false);
},
});
}

Expand Down
Loading

0 comments on commit 1c55ca5

Please sign in to comment.