Skip to content

Commit

Permalink
Merge pull request #88 from AudiusProject/saliou-aud-metrics
Browse files Browse the repository at this point in the history
Use new aggregate metrics endpoints
  • Loading branch information
sddioulde committed May 4, 2021
1 parent b204546 commit f6082a7
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ type OwnProps = {}

type ApiCallsStatProps = OwnProps

const ApiCallsStat: React.FC<ApiCallsStatProps> = (
props: ApiCallsStatProps
) => {
const ApiCallsStat: React.FC<ApiCallsStatProps> = () => {
const { apiCalls } = useTrailingApiCalls(Bucket.MONTH)
let error, stat
if (apiCalls === MetricError.ERROR) {
error = true
stat = null
} else {
stat = apiCalls?.count ?? null
stat = apiCalls?.total_count ?? null
}
return (
<Stat
Expand Down
21 changes: 2 additions & 19 deletions packages/protocol-dashboard/src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ const getData = (data: number[], labels: string[], showLeadingDay: boolean) => {
pointRadius: 0,
pointHitRadius: 8
}
let solidLine = data.slice(0, -1) as (number | undefined)[]
if (showLeadingDay) {
solidLine = solidLine.concat([undefined])
}

const newLabels = showLeadingDay ? labels : labels.slice(0, -1)
const solidLine = showLeadingDay ? data : data.slice(0, -1)
const datasets = [
{
...common,
Expand All @@ -58,21 +56,6 @@ const getData = (data: number[], labels: string[], showLeadingDay: boolean) => {
}
]

if (showLeadingDay) {
const dottedLine = new Array(Math.max(data.length - 2, 0))
.fill(undefined)
.concat(data.slice(-2))

datasets.push({
...common,
label: 'current',
data: dottedLine,
borderDash: [2, 6]
})
}

const newLabels = showLeadingDay ? labels : labels.slice(0, -1)

return {
labels: newLabels,
datasets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,16 @@ import styles from './ServiceTable.module.css'
import Table from 'components/Table'
import Error from 'components/Error'

export type ServiceRow = {
type ServiceRow = {
endpoint: string
version: string
}

type Service = {
endpoint: string
version: string
spID: number
}

type OwnProps = {
className?: string
isLoading?: boolean
title: string
data: Array<ServiceRow>
data: ServiceRow[]
limit?: number
moreText?: string
onRowClick:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type OwnProps = {
}

const messages = {
title: 'Top API Apps by Total Requests',
title: 'Top 3rd Party API Apps by Total Requests',
yLabel: 'Total Requests',
viewMore: 'View Full Leaderboard'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ import { Bucket, MetricError } from 'store/cache/analytics/slice'
import { useIsMobile } from 'utils/hooks'

const messages = {
title: 'Top API Apps by Total Requests',
title: 'Top 3rd Party API Apps by Total Requests',
rank: 'Rank',
totalReq: 'Total Requests'
}

export type ServiceRow = {
endpoint: string
version: string
}

export type APIAppRequests = {
rank: number
name: string
Expand All @@ -41,7 +36,6 @@ const filterCount = (name: string, count: number): boolean =>

const TopAPITable: React.FC<TopAPITableProps> = ({
className,
limit,
alwaysShowMore
}: TopAPITableProps) => {
const isMobile = useIsMobile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TopAppsChart: React.FC<TopAppsChartProps> = () => {

return (
<BarChart
title="Top Apps"
title="Top 3rd Party Apps"
column1="apps"
column2="requests"
data={data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const TotalApiCallsChart: React.FC<TotalApiCallsChartProps> = props => {
labels = []
data = []
} else {
labels = apiCalls?.map(a => a.timestamp) ?? null
data = apiCalls?.map(a => a.count) ?? null
labels = apiCalls?.map(a => new Date(a.timestamp).getTime() / 1000) ?? null
data = apiCalls?.map(a => a.total_count) ?? null
}
return (
<LineChart
Expand All @@ -30,6 +30,7 @@ const TotalApiCallsChart: React.FC<TotalApiCallsChartProps> = props => {
selection={bucket}
options={[Bucket.ALL_TIME, Bucket.MONTH, Bucket.WEEK]}
onSelectOption={(option: string) => setBucket(option as Bucket)}
showLeadingDay
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Bucket, MetricError } from 'store/cache/analytics/slice'

type OwnProps = {}

type TotalApiCallsChartProps = OwnProps
type UniqueUsersChartProps = OwnProps

const TotalApiCallsChart: React.FC<TotalApiCallsChartProps> = () => {
const UniqueUsersChart: React.FC<UniqueUsersChartProps> = () => {
const [bucket, setBucket] = useState(Bucket.MONTH)

const { apiCalls } = useApiCalls(bucket)
Expand All @@ -17,8 +17,8 @@ const TotalApiCallsChart: React.FC<TotalApiCallsChartProps> = () => {
labels = []
data = []
} else {
labels = apiCalls?.map(a => a.timestamp) ?? null
data = apiCalls?.map(a => a.unique_count || 0) ?? null
labels = apiCalls?.map(a => new Date(a.timestamp).getTime() / 1000) ?? null
data = apiCalls?.map(a => a.summed_unique_count) ?? null
}
return (
<LineChart
Expand All @@ -30,8 +30,9 @@ const TotalApiCallsChart: React.FC<TotalApiCallsChartProps> = () => {
error={error}
options={[Bucket.ALL_TIME, Bucket.MONTH, Bucket.WEEK]}
onSelectOption={(option: string) => setBucket(option as Bucket)}
showLeadingDay
/>
)
}

export default TotalApiCallsChart
export default UniqueUsersChart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ type OwnProps = {}

type UniqueUsersStatProps = OwnProps

const UniqueUsersStat: React.FC<UniqueUsersStatProps> = (
props: UniqueUsersStatProps
) => {
const UniqueUsersStat: React.FC<UniqueUsersStatProps> = () => {
const { apiCalls } = useTrailingApiCalls(Bucket.MONTH)
let error, stat
if (apiCalls === MetricError.ERROR) {
error = true
stat = null
} else {
stat = apiCalls?.unique_count ?? null
stat = apiCalls?.summed_unique_count ?? null
}
return (
<Stat
Expand Down
Loading

0 comments on commit f6082a7

Please sign in to comment.