Skip to content

Commit

Permalink
[SKIP CI]Merge pull request #576 from subquery/feat/autonity-metrics
Browse files Browse the repository at this point in the history
feat: autonity metrics
  • Loading branch information
cool-firer authored Dec 10, 2024
2 parents 91045fd + 970a182 commit 2891962
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/indexer-coordinator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/indexer-coordinator",
"version": "2.8.2-1",
"version": "2.8.2",
"description": "",
"author": "SubQuery",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class ProjectRpcService implements OnModuleInit {
.validate(endpoint, endpointKey as RpcEndpointType);
return this.formatResponse(true);
} catch (e) {
logger.debug(e);
logger.debug(`${e}`);
return this.formatResponse(false, e.message, e.level || ErrorLevel.error);
}
}
Expand Down
12 changes: 10 additions & 2 deletions apps/indexer-coordinator/src/project/rpc.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,15 @@ export class RpcFamilyEvm extends RpcFamily {
throw new ValidateRpcEndpointError(`Request metrics failed: ${result.error}`, errorLevel);
}
if (typeof result.data === 'object') {
const info = safeJSONParse(result.data['chain/info']);
chainIdFromRpc = info?.chain_id;
// eth
if ('chain/info' in result.data) {
const info = safeJSONParse(result.data['chain/info']);
chainIdFromRpc = info?.chain_id;
}
// autonity
if ('p2p/acn/peers' in result.data) {
chainIdFromRpc = chainId;
}
} else {
const metricsObj = parseMetrics(result.data);
if (metricsObj.mType === MetricsType.GETH_PROMETHEUS) {
Expand Down Expand Up @@ -392,6 +399,7 @@ export class RpcFamilyEvm extends RpcFamily {
const metricsObj = parseMetrics(result.data);
switch (metricsObj.mType) {
case MetricsType.GETH_PROMETHEUS:
case MetricsType.AUTONITY_PROMETHEUS:
headBlock = metricsObj.chain_head_block;
errorMsg = 'incorrect head block';
break;
Expand Down
20 changes: 20 additions & 0 deletions apps/indexer-coordinator/src/utils/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum MetricsType {
NETHERMIND_PROMETHEUS = 'nethermind_prom',
RETH_PROMETHEUS = 'reth_prom',
BESU_PROMETHEUS = 'besu_prom',
AUTONITY_PROMETHEUS = 'auto_prom',
}

function extractFromBrace(content: string) {
Expand Down Expand Up @@ -37,6 +38,8 @@ export type MetricsData = {

// geth
chain_id?: string;

// geth & autonity
chain_head_block?: string;

// erigon
Expand All @@ -52,6 +55,9 @@ export type MetricsData = {

// besu & nethermind
ethereum_blockchain_height?: string;

// autonity
p2p_acn_peers?: string;
};

// eslint-disable-next-line complexity
Expand Down Expand Up @@ -168,6 +174,20 @@ export function parseMetrics(metrics: string): MetricsData {
Object.assign(parsedData, blocksInfo);
}
}

// autonity
if (lines[i].startsWith('# TYPE p2p_acn_peers gauge')) {
mType = MetricsType.AUTONITY_PROMETHEUS;
/**
# TYPE p2p_acn_peers gauge
p2p_acn_peers 0
*/
const next = lines[i + 1] || '';
if (next.startsWith('p2p_acn_peers')) {
const peerInfo = extractFromGauge(next);
Object.assign(parsedData, peerInfo);
}
}
}

parsedData.mType = mType;
Expand Down

0 comments on commit 2891962

Please sign in to comment.