mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-12 10:37:32 +00:00
Update chain head exporter CLI to support running multiple instances (#512)
* Update chain-head-exported CLI for running multiple instances * Update upstream RPC for metrics with active endpoint * Export metrics for watcher package version and commitHash * Upgrade package versions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cerc-io/cli",
|
||||
"version": "0.2.90",
|
||||
"version": "0.2.91",
|
||||
"main": "dist/index.js",
|
||||
"license": "AGPL-3.0",
|
||||
"scripts": {
|
||||
@@ -15,13 +15,13 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.7.1",
|
||||
"@cerc-io/cache": "^0.2.90",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.90",
|
||||
"@cerc-io/cache": "^0.2.91",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.91",
|
||||
"@cerc-io/libp2p": "^0.42.2-laconic-0.1.4",
|
||||
"@cerc-io/nitro-node": "^0.1.15",
|
||||
"@cerc-io/peer": "^0.2.90",
|
||||
"@cerc-io/rpc-eth-client": "^0.2.90",
|
||||
"@cerc-io/util": "^0.2.90",
|
||||
"@cerc-io/peer": "^0.2.91",
|
||||
"@cerc-io/rpc-eth-client": "^0.2.91",
|
||||
"@cerc-io/util": "^0.2.91",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@graphql-tools/utils": "^9.1.1",
|
||||
"@ipld/dag-cbor": "^8.0.0",
|
||||
|
||||
@@ -13,24 +13,23 @@ const log = debug('laconic:chain-head-exporter');
|
||||
// Env overrides:
|
||||
// ETH_RPC_ENDPOINT - Ethereum RPC API endpoint
|
||||
// ETH_RPC_API_KEY - Ethereum RPC API endpoint key
|
||||
// FIL_RPC_ENDPOINT - Filecoin RPC API endpoint
|
||||
// PORT - Metrics server listening port
|
||||
|
||||
// Defaults
|
||||
const DEFAULT_ETH_RPC_ENDPOINT = 'https://mainnet.infura.io/v3';
|
||||
const DEFAULT_FIL_RPC_ENDPOINT = 'https://api.node.glif.io/rpc/v1';
|
||||
const DEFAULT_PORT = 5000;
|
||||
|
||||
async function main (): Promise<void> {
|
||||
const app = express();
|
||||
const metricsRegister = new promClient.Registry();
|
||||
|
||||
const ethRpcBaseUrl = process.env.ETH_RPC_ENDPOINT || DEFAULT_ETH_RPC_ENDPOINT;
|
||||
|
||||
const ethRpcApiKey = process.env.ETH_RPC_API_KEY;
|
||||
if (!ethRpcApiKey) {
|
||||
log('WARNING: ETH_RPC_API_KEY not set');
|
||||
}
|
||||
|
||||
const ethRpcBaseUrl = process.env.ETH_RPC_ENDPOINT || DEFAULT_ETH_RPC_ENDPOINT;
|
||||
const ethUrlSuffix = ethRpcApiKey ? `/${ethRpcApiKey}` : '';
|
||||
const ethRpcUrl = `${ethRpcBaseUrl}${ethUrlSuffix}`;
|
||||
let ethProvider: JsonRpcProvider;
|
||||
@@ -40,14 +39,6 @@ async function main (): Promise<void> {
|
||||
log(`Error creating ETH RPC provider from URL ${ethRpcBaseUrl}`, err);
|
||||
}
|
||||
|
||||
const filRpcUrl = process.env.FILECOIN_RPC_ENDPOINT || DEFAULT_FIL_RPC_ENDPOINT;
|
||||
let filProvider: JsonRpcProvider;
|
||||
try {
|
||||
filProvider = new JsonRpcProvider(filRpcUrl);
|
||||
} catch (err) {
|
||||
log(`Error creating FIL RPC provider from URL ${filRpcUrl}`, err);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-new
|
||||
new promClient.Gauge({
|
||||
name: 'latest_block_number',
|
||||
@@ -56,16 +47,8 @@ async function main (): Promise<void> {
|
||||
labelNames: ['chain'] as const,
|
||||
async collect () {
|
||||
try {
|
||||
const [
|
||||
latestEthBlockNumber,
|
||||
latestFilBlockNumber
|
||||
] = await Promise.all([
|
||||
ethProvider.getBlockNumber(),
|
||||
filProvider.getBlockNumber()
|
||||
]);
|
||||
|
||||
this.set({ chain: 'ethereum' }, latestEthBlockNumber);
|
||||
this.set({ chain: 'filecoin' }, latestFilBlockNumber);
|
||||
const latestEthBlockNumber = await ethProvider.getBlockNumber();
|
||||
this.set(latestEthBlockNumber);
|
||||
} catch (err) {
|
||||
log('Error fetching latest block number', err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user