Skip to content

Commit

Permalink
Updates arweave metrics queries (relay/metrics & validation/stats) to…
Browse files Browse the repository at this point in the history
… only search for last 2 weeks, and not use protocol tag
  • Loading branch information
jim-toth committed Sep 5, 2024
1 parent 6ba319b commit e87484b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions composables/ardb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export async function getLatestBlockHeight(): Promise<number> {
return height;
}

export async function calculateBlockHeightOneMonthAgo(
export async function calculateMinimumQueryBlockHeight(
latestHeight: number
): Promise<number> {
const blocksPerMonth = 60 * 24 * 30;
return latestHeight - blocksPerMonth;
const twoWeeksAgo = Math.floor(blocksPerMonth / 2);
return latestHeight - twoWeeksAgo;
}
28 changes: 14 additions & 14 deletions stores/useMetricsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parseTimestampTag } from '@/utils/transactions';
import {
useArdb,
getLatestBlockHeight,
calculateBlockHeightOneMonthAgo,
calculateMinimumQueryBlockHeight,
} from '@/composables/ardb';
import { useTxCache } from '@/composables/txCache';

Expand Down Expand Up @@ -71,7 +71,7 @@ export interface MetricsStoreState {
};
relayMetricsPending: boolean;
latestHeight: number | null;
oneMonthAgoHeight: number | null;
minimumHeight: number | null;
}

const logger = new Logger('MetricsStore');
Expand All @@ -92,7 +92,7 @@ export const useMetricsStore = defineStore('metrics', {
},
relayMetricsPending: true,
latestHeight: null,
oneMonthAgoHeight: null,
minimumHeight: null,
};
},
getters: {},
Expand Down Expand Up @@ -125,13 +125,13 @@ export const useMetricsStore = defineStore('metrics', {
if (!this.latestHeight) {
this.latestHeight = await getLatestBlockHeight();
}
if (!this.oneMonthAgoHeight) {
this.oneMonthAgoHeight = await calculateBlockHeightOneMonthAgo(
if (!this.minimumHeight) {
this.minimumHeight = await calculateMinimumQueryBlockHeight(
this.latestHeight
);
}
console.log('this.latestHeight', this.latestHeight);
console.log('this.oneMonthAgoHeight', this.oneMonthAgoHeight);
console.log('this.minimumHeight', this.minimumHeight);

const txCache = useTxCache();

Expand All @@ -140,12 +140,12 @@ export const useMetricsStore = defineStore('metrics', {
.search('transactions')
.from(runtimeConfig.public.metricsDeployer as string)
.tags([
{ name: 'Protocol', values: 'ator' },
// { name: 'Protocol', values: 'ator' },
{ name: 'Entity-Type', values: 'relay/metrics' },
])
.limit(limit)
.min(this.oneMonthAgoHeight)
.max(this.latestHeight)
.min(this.minimumHeight)
// .max(this.latestHeight)
.sort('HEIGHT_DESC')
.find()) as ArdbTransaction[];

Expand Down Expand Up @@ -202,8 +202,8 @@ export const useMetricsStore = defineStore('metrics', {
if (!this.latestHeight) {
this.latestHeight = await getLatestBlockHeight();
}
if (!this.oneMonthAgoHeight) {
this.oneMonthAgoHeight = await calculateBlockHeightOneMonthAgo(
if (!this.minimumHeight) {
this.minimumHeight = await calculateMinimumQueryBlockHeight(
this.latestHeight
);
}
Expand All @@ -212,12 +212,12 @@ export const useMetricsStore = defineStore('metrics', {
.search('transactions')
.from(runtimeConfig.public.metricsDeployer as string)
.tags([
{ name: 'Protocol', values: 'ator' },
// { name: 'Protocol', values: 'ator' },
{ name: 'Entity-Type', values: 'validation/stats' },
])
.limit(limit)
.min(this.oneMonthAgoHeight)
.max(this.latestHeight)
.min(this.minimumHeight)
// .max(this.latestHeight)
.sort('HEIGHT_DESC')
.find()) as ArdbTransaction[];

Expand Down

0 comments on commit e87484b

Please sign in to comment.