diff --git a/indexer/src/cache/init.ts b/indexer/src/cache/init.ts index e9afad97..fba482a3 100644 --- a/indexer/src/cache/init.ts +++ b/indexer/src/cache/init.ts @@ -76,10 +76,7 @@ export default async function initCache(context: ResolverContext) { }; MEMORY_CACHE.set(HASH_RATE_AND_TOTAL_DIFFICULTY_KEY, newValue); } catch (err) { - console.error( - '[ERROR][CACHE][CONN_TIMEOUT] Failed to get hash rate and total difficulty', - err, - ); + console.error('[WARN][CACHE][DB] Failed to get hash rate and total difficulty', err); } } @@ -94,7 +91,7 @@ export default async function initCache(context: ResolverContext) { const networkStatistics = await networkRepository.getNetworkStatistics(); MEMORY_CACHE.set(NETWORK_STATISTICS_KEY, networkStatistics); } catch (err) { - console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get network statistics', err); + console.error('[WARN][CACHE][DB] Failed to get network statistics', err); } } @@ -109,23 +106,20 @@ export default async function initCache(context: ResolverContext) { const nodeInfo = await networkRepository.getNodeInfo(); MEMORY_CACHE.set(NODE_INFO_KEY, nodeInfo); } catch (err) { - console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get node info', err); + console.error('[WARN][CACHE][DB] Failed to get node info', err); } } /** - * Fetches and caches information about the blockchain node - * - * This includes node version, connectivity status, and other - * node-specific information that helps monitor the node's health. + * Fetches and caches information about number of blocks, transactions, + * and total gas used in each chain. */ - async function getCountersOfEachChain() { try { const counters = await networkRepository.getCountersOfEachChain(); MEMORY_CACHE.set(COUNTERS_OF_EACH_CHAIN_KEY, counters); } catch (err) { - console.error('[ERROR][CACHE][CONN_TIMEOUT] Failed to get counters of each chain', err); + console.error('[WARN][CACHE][DB] Failed to get counters of each chain', err); } } diff --git a/indexer/src/kadena-server/server.ts b/indexer/src/kadena-server/server.ts index 90ba1fe2..83017cee 100644 --- a/indexer/src/kadena-server/server.ts +++ b/indexer/src/kadena-server/server.ts @@ -44,7 +44,6 @@ import { } from 'graphql'; import initCache from '../cache/init'; -import { getArrayEnvString } from '../utils/helpers'; import { directiveEstimator, fieldExtensionsEstimator, @@ -520,7 +519,7 @@ export async function startGraphqlServer() { // Capture heap snapshot at 1GB memory threshold if (mem.heapUsed > 1 * 1024 * 1024 * 1024) { const filename = `/snapshots/indexer-heap-1GB-${Date.now()}.heapsnapshot`; - console.warn(`[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${filename}`); + console.error(`[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${filename}`); heapdump.writeSnapshot(filename); } }; diff --git a/indexer/src/services/monitoring.ts b/indexer/src/services/monitoring.ts index 01be8981..de8fd912 100644 --- a/indexer/src/services/monitoring.ts +++ b/indexer/src/services/monitoring.ts @@ -72,7 +72,7 @@ export function initializeErrorMonitoring(): void { ] .filter(Boolean) .join(', '); - console.warn(`[WARN][MONITORING] Monitoring not initialized. Missing env: ${missing}`); + console.error(`[WARN][MONITORING][ENV] Monitoring not initialized. Missing env: ${missing}`); return; // Monitoring disabled; keep local logging only } diff --git a/indexer/src/services/price/price-updater.service.ts b/indexer/src/services/price/price-updater.service.ts index 10041226..b9c669e1 100644 --- a/indexer/src/services/price/price-updater.service.ts +++ b/indexer/src/services/price/price-updater.service.ts @@ -1,5 +1,3 @@ -import axios from 'axios'; - import { PriceService } from './price.service'; export class PriceUpdaterService { @@ -23,11 +21,26 @@ export class PriceUpdaterService { private async updatePrice(): Promise { try { - const response = await axios.get(this.DIA_API_URL); - const price = response.data.Price; - this.priceService.setKdaUsdPrice(price); + const response = await fetch(this.DIA_API_URL, { + headers: { + Accept: 'application/json', + 'User-Agent': 'node-fetch', + }, + }); + + if (!response.ok) { + throw new Error(`HTTP ${response.status} - ${response.statusText}`); + } + + const data = await response.json(); + + if (data?.Price === undefined) { + throw new Error('Price field is missing in API response'); + } + + this.priceService.setKdaUsdPrice(data.Price); } catch (error) { - console.error('[ERROR][INT][INT_API] Failed to update KDA/USD price:', error); + console.error('[WARN][INT][INT_API] Failed to update KDA/USD price:', error); } } diff --git a/indexer/src/utils/helpers.ts b/indexer/src/utils/helpers.ts index 4cff7f45..39b053f5 100644 --- a/indexer/src/utils/helpers.ts +++ b/indexer/src/utils/helpers.ts @@ -40,18 +40,6 @@ export function getRequiredEnvString(key: string): string { return value; } -/** - * Retrieves an optional environment variable as a string array. - * The environment variable is expected to be a comma-separated string. - * - * @param key - The name of the environment variable to retrieve. - * @returns The value of the environment variable as a string array, or an empty array if the variable is not set. - */ -export function getArrayEnvString(key: string): string[] { - const value = process.env[key] ?? ''; - return value.split(',').filter(item => item.trim() !== ''); -} - /** * Checks if a value is null or undefined. *