Skip to content
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

[Feature] Add new metric for the max percentage deviation (Max price cross-sectional deviation) to improve monitoring and alerting #175

Open
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions src/aggregator_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function crossCheckPriceData(
// 1. Prices should not deviate more than maxPercentageDeviation.
const prices = tickerData.map((price: WeightedPrice) => price.price)
const maxNormalizedAbsMeanDev = maxPercentageDeviaton(prices)
config.metricCollector?.maxPercentageDeviation(config.currencyPair, maxNormalizedAbsMeanDev)
assert(
maxNormalizedAbsMeanDev.isLessThanOrEqualTo(config.maxPercentageDeviation),
`Max price cross-sectional deviation too large (${maxNormalizedAbsMeanDev} >= ${config.maxPercentageDeviation} )`
Expand Down
14 changes: 14 additions & 0 deletions src/metric_collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class MetricCollector {

private tickerPropertyGauge: Gauge<string>
private priceSourceGauge: Gauge<string>
private maxPercentageDeviationGauge: Gauge<string>

private transactionBlockNumberGauge: Gauge<string>
private transactionGasGauge: Gauge<string>
Expand Down Expand Up @@ -158,6 +159,12 @@ export class MetricCollector {
labelNames: ['pair', 'source', 'property'],
})

this.maxPercentageDeviationGauge = new Gauge({
name: 'oracle_max_percentage_deviation',
help: 'Gauge to indicate the max price cross-sectional deviation of a price pair',
labelNames: ['currencyPair'],
})

this.transactionBlockNumberGauge = new Gauge({
name: 'oracle_transaction_block_number',
help: 'Gauge showing the block number of the most recent transaction defined by type',
Expand Down Expand Up @@ -331,6 +338,13 @@ export class MetricCollector {
this.priceSourceGauge.set({ pair, source, property: 'weight' }, weightedPrice.weight.toNumber())
}

/**
* Indicates the max price cross-sectional deviation of a price pair
*/
maxPercentageDeviation(pair: string, maxPercentageDeviation: BigNumber) {
this.maxPercentageDeviationGauge.set({ pair }, maxPercentageDeviation.toNumber())
}

/**
* Indicates the most recent block number of a specific type
*/
Expand Down