From 3fe0f106e5011c0fa62fd5e17b32715d1025b09d Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Tue, 26 Nov 2024 11:05:51 -0500 Subject: [PATCH] refactor(renterd): remove contracts metrics --- .changeset/plenty-tomatoes-teach.md | 5 ++ .changeset/shaggy-dolls-smash.md | 5 -- .changeset/two-seas-judge.md | 7 -- .../components/Contracts/ContractMetrics.tsx | 20 ----- apps/renterd/contexts/contracts/index.tsx | 4 - apps/renterd/contexts/contracts/types.ts | 6 +- .../contracts/useContractsMetrics.tsx | 77 ------------------- libs/renterd-js/src/bus.ts | 18 ----- libs/renterd-react/src/bus.ts | 17 ---- libs/renterd-types/src/bus.ts | 36 --------- 10 files changed, 6 insertions(+), 189 deletions(-) create mode 100644 .changeset/plenty-tomatoes-teach.md delete mode 100644 .changeset/shaggy-dolls-smash.md delete mode 100644 .changeset/two-seas-judge.md delete mode 100644 apps/renterd/contexts/contracts/useContractsMetrics.tsx diff --git a/.changeset/plenty-tomatoes-teach.md b/.changeset/plenty-tomatoes-teach.md new file mode 100644 index 000000000..4e6c11a04 --- /dev/null +++ b/.changeset/plenty-tomatoes-teach.md @@ -0,0 +1,5 @@ +--- +'renterd': minor +--- + +The contracts graphs no longer include a count metric. diff --git a/.changeset/shaggy-dolls-smash.md b/.changeset/shaggy-dolls-smash.md deleted file mode 100644 index bdd025472..000000000 --- a/.changeset/shaggy-dolls-smash.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'renterd': minor ---- - -Add overall contract count metrics graph. diff --git a/.changeset/two-seas-judge.md b/.changeset/two-seas-judge.md deleted file mode 100644 index 1387dd6a9..000000000 --- a/.changeset/two-seas-judge.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@siafoundation/renterd-js': minor -'@siafoundation/renterd-react': minor -'@siafoundation/renterd-types': minor ---- - -Add overall contract churn metrics API. diff --git a/apps/renterd/components/Contracts/ContractMetrics.tsx b/apps/renterd/components/Contracts/ContractMetrics.tsx index 33fe55fd9..b2f6cecb4 100644 --- a/apps/renterd/components/Contracts/ContractMetrics.tsx +++ b/apps/renterd/components/Contracts/ContractMetrics.tsx @@ -7,7 +7,6 @@ export function ContractMetrics() { selectedContract, allContractsSpendingMetrics, selectedContractSpendingMetrics, - contractsCountMetrics, graphMode, setGraphMode, } = useContracts() @@ -31,14 +30,6 @@ export function ContractMetrics() { {stripPrefix(selectedContract.id).slice(0, 6)} )} - {!selectedContract && ( - - )} ) @@ -66,17 +57,6 @@ export function ContractMetrics() { emptyState={} /> )} - {graphMode === 'count' && !selectedContract && ( - } - /> - )} ) } diff --git a/apps/renterd/contexts/contracts/index.tsx b/apps/renterd/contexts/contracts/index.tsx index 5eda4256b..b097f1e18 100644 --- a/apps/renterd/contexts/contracts/index.tsx +++ b/apps/renterd/contexts/contracts/index.tsx @@ -31,7 +31,6 @@ import { defaultDatasetRefreshInterval } from '../../config/swr' import { useDataset } from './dataset' import { useFilteredStats } from './useFilteredStats' import { daysInMilliseconds } from '@siafoundation/units' -import { useContractsMetrics } from './useContractsMetrics' const defaultLimit = 50 @@ -175,8 +174,6 @@ function useContractsMain() { disabled: !selectedContract, }) - const { contractsMetrics: contractsCountMetrics } = useContractsMetrics() - return { dataState, limit, @@ -215,7 +212,6 @@ function useContractsMain() { selectContract, allContractsSpendingMetrics, selectedContractSpendingMetrics, - contractsCountMetrics, isFetchingPrunableSizeAll, isFetchingPrunableSizeById, fetchPrunableSize, diff --git a/apps/renterd/contexts/contracts/types.ts b/apps/renterd/contexts/contracts/types.ts index 9b1d0ee6f..0b4ad7aa6 100644 --- a/apps/renterd/contexts/contracts/types.ts +++ b/apps/renterd/contexts/contracts/types.ts @@ -181,7 +181,7 @@ export const sortOptions: { ] export type ViewMode = 'list' | 'detail' -export type GraphMode = 'spending' | 'count' +export type GraphMode = 'spending' export type ChartContractKey = | 'uploadSpending' @@ -196,7 +196,3 @@ export type ChartContractCategory = 'funding' | 'spending' export type ChartContractsKey = 'contracts' export type ChartContractsCategory = never - -export type ChartContractsChurnKey = 'contracts' - -export type ChartContractsChurnCategory = never diff --git a/apps/renterd/contexts/contracts/useContractsMetrics.tsx b/apps/renterd/contexts/contracts/useContractsMetrics.tsx deleted file mode 100644 index 7fe824a59..000000000 --- a/apps/renterd/contexts/contracts/useContractsMetrics.tsx +++ /dev/null @@ -1,77 +0,0 @@ -import { - Chart, - formatChartData, - computeChartStats, - colors, - getDataIntervalLabelFormatter, -} from '@siafoundation/design-system' -import { useMetricsContracts } from '@siafoundation/renterd-react' -import { useMemo } from 'react' -import { ChartContractsCategory, ChartContractsKey } from './types' -import { getTimeClampedToNearest5min } from './utils' -import { daysInMilliseconds } from '@siafoundation/units' -import { ContractsMetricsParams } from '@siafoundation/renterd-types' - -export function useContractsMetrics() { - // don't use exact times, round to 5 minutes so that swr can cache - // if the user flips back and forth between contracts. - const start = getTimeClampedToNearest5min( - new Date().getTime() - daysInMilliseconds(30) - ) - const interval = daysInMilliseconds(1) - const periods = useMemo(() => { - const now = new Date().getTime() - const today = getTimeClampedToNearest5min(now) - const span = today - start - return Math.round(span / interval) - }, [start, interval]) - const response = useMetricsContracts({ - params: { - start: new Date(start).toISOString(), - interval, - n: periods, - } as ContractsMetricsParams, - }) - const contractsMetrics = useMemo< - Chart - >(() => { - const data = formatChartData( - response.data?.map((m) => ({ - contracts: Number(m.contracts), - timestamp: new Date(m.timestamp).getTime(), - })), - 'none' - ) - const stats = computeChartStats(data) - return { - data, - stats, - config: { - enabledGraph: ['contracts'], - enabledTip: ['contracts'], - data: { - contracts: { - label: 'contracts', - color: colors.emerald[600], - }, - }, - // formatComponent: function ({ value }) { - // return - // }, - formatTimestamp: - interval === daysInMilliseconds(1) - ? getDataIntervalLabelFormatter('daily') - : undefined, - // formatTickY: (v) => `${v} contracts`, - disableAnimations: true, - chartType: 'line', - curveType: 'linear', - stackOffset: 'none', - }, - isLoading: response.isValidating && !response.data, - } - }, [response.data, response.isValidating, interval]) - return { - contractsMetrics, - } -} diff --git a/libs/renterd-js/src/bus.ts b/libs/renterd-js/src/bus.ts index e78a5e1a1..6c8e1f0a2 100644 --- a/libs/renterd-js/src/bus.ts +++ b/libs/renterd-js/src/bus.ts @@ -44,12 +44,6 @@ import { ContractRenewedPayload, ContractRenewedResponse, ContractResponse, - ContractsMetricsParams, - ContractsMetricsPayload, - ContractsMetricsResponse, - ContractsChurnMetricsParams, - ContractsChurnMetricsPayload, - ContractsChurnMetricsResponse, ContractSizeParams, ContractSizePayload, ContractSizeResponse, @@ -191,8 +185,6 @@ import { busHostsBlocklistRoute, busHostsHostKeyRoute, busMetricContractRoute, - busMetricContractsRoute, - busMetricChurnRoute, busMetricWalletRoute, busMultipartAbortRoute, busMultipartCompleteRoute, @@ -560,16 +552,6 @@ export function Bus({ api, password }: { api: string; password?: string }) { ContractMetricsPayload, ContractMetricsResponse >(axios, 'get', busMetricContractRoute), - contractsMetrics: buildRequestHandler< - ContractsMetricsParams, - ContractsMetricsPayload, - ContractsMetricsResponse - >(axios, 'get', busMetricContractsRoute), - contractsChurnMetrics: buildRequestHandler< - ContractsChurnMetricsParams, - ContractsChurnMetricsPayload, - ContractsChurnMetricsResponse - >(axios, 'get', busMetricChurnRoute), walletMetrics: buildRequestHandler< WalletMetricsParams, WalletMetricsPayload, diff --git a/libs/renterd-react/src/bus.ts b/libs/renterd-react/src/bus.ts index cac7b3e73..086849eec 100644 --- a/libs/renterd-react/src/bus.ts +++ b/libs/renterd-react/src/bus.ts @@ -60,10 +60,6 @@ import { ContractRenewedPayload, ContractRenewedResponse, ContractResponse, - ContractsMetricsParams, - ContractsMetricsResponse, - ContractsChurnMetricsParams, - ContractsChurnMetricsResponse, ContractsAddParams, ContractsAddPayload, ContractsAddResponse, @@ -196,8 +192,6 @@ import { busAlertsDismissRoute, busSlabKeyObjectsRoute, busMetricContractRoute, - busMetricContractsRoute, - busMetricChurnRoute, busMetricWalletRoute, busMultipartCreateRoute, busMultipartRoute, @@ -919,17 +913,6 @@ export function useMetricsContract( return useGetSwr({ ...args, route: busMetricContractRoute }) } -export function useMetricsContracts( - args: HookArgsSwr -) { - return useGetSwr({ ...args, route: busMetricContractsRoute }) -} -export function useMetricsContractsChurn( - args: HookArgsSwr -) { - return useGetSwr({ ...args, route: busMetricChurnRoute }) -} - export function useMetricsWallet( args: HookArgsSwr ) { diff --git a/libs/renterd-types/src/bus.ts b/libs/renterd-types/src/bus.ts index e23f92493..2d23450bc 100644 --- a/libs/renterd-types/src/bus.ts +++ b/libs/renterd-types/src/bus.ts @@ -77,8 +77,6 @@ export const busAlertsRoute = '/bus/alerts' export const busAlertsDismissRoute = '/bus/alerts/dismiss' export const busSlabKeyObjectsRoute = '/bus/slab/:key/objects' export const busMetricContractRoute = '/bus/metric/contract' -export const busMetricContractsRoute = '/bus/metric/contracts' -export const busMetricChurnRoute = '/bus/metric/churn' export const busMetricWalletRoute = '/bus/metric/wallet' export const busMultipartRoute = '/bus/multipart' export const busMultipartCreateRoute = '/bus/multipart/create' @@ -523,26 +521,6 @@ export type ContractMetricsParams = MetricsParams & { export type ContractMetricsPayload = void export type ContractMetricsResponse = ContractMetric[] -export type ContractsMetric = { - contracts: number - timestamp: string -} -export type ContractsMetricsParams = MetricsParams -export type ContractsMetricsPayload = void -export type ContractsMetricsResponse = ContractsMetric[] -export type ContractsChurnMetric = { - direction: string - contractID: string - reason: string - timestamp: string -} -export type ContractsChurnMetricsParams = MetricsParams & { - direction?: string - reason?: string -} -export type ContractsChurnMetricsPayload = void -export type ContractsChurnMetricsResponse = ContractsChurnMetric[] - export type WalletMetric = { timestamp: string confirmed: string @@ -554,20 +532,6 @@ export type WalletMetricsParams = MetricsParams export type WalletMetricsPayload = void export type WalletMetricsResponse = WalletMetric[] -// export type PerformanceMetric = { -// action: string -// hostKey: string -// origin: string -// duration: number -// timestamp: string -// } - -// export type PerformanceMetricsParams = MetricsParams & { -// action: string -// hostKey: string -// origin: string -// } - // multipart export type MultipartUploadCreateParams = void