Skip to content

Commit

Permalink
Remove unnecessary logs and add Ender metrics (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Li authored Aug 21, 2024
1 parent 9263b4c commit 3c13930
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
7 changes: 6 additions & 1 deletion indexer/packages/kafka/src/batch-kafka-producer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { logger } from '@dydxprotocol-indexer/base';
import { logger, stats } from '@dydxprotocol-indexer/base';
import { IHeaders, Producer, RecordMetadata } from 'kafkajs';
import _ from 'lodash';

import config from './config';
import { KafkaTopics } from './types';

/**
Expand Down Expand Up @@ -65,6 +66,7 @@ export class BatchKafkaProducer {
}

private sendBatch(): void {
const startTime: number = Date.now();
if (!_.isEmpty(this.producerMessages)) {
this.producerPromises.push(
this.producer.send({ topic: this.topic, messages: this.producerMessages }),
Expand All @@ -80,7 +82,10 @@ export class BatchKafkaProducer {
0,
),
topic: this.topic,
sendTime: Date.now() - startTime,
});
stats.gauge(`${config.SERVICE_NAME}.kafka_batch_size`, this.currentSize);
stats.timing(`${config.SERVICE_NAME}.kafka_batch_send_time`, Date.now() - startTime);
this.producerMessages = [];
this.currentSize = 0;
}
Expand Down
10 changes: 1 addition & 9 deletions indexer/services/ender/src/lib/batched-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger, stats } from '@dydxprotocol-indexer/base';
import { stats } from '@dydxprotocol-indexer/base';
import _ from 'lodash';
import * as pg from 'pg';

Expand Down Expand Up @@ -100,14 +100,6 @@ export class BatchedHandlers {
_.forEach(consolidatedKafkaEventGroup, (events: ConsolidatedKafkaEvent[]) => {
kafkaPublisher.addEvents(events);
});
logger.info({
at: 'BatchedHandlers#process',
message: 'Finished processing batch of handlers',
batchIndex,
handlerCountMapping,
batchProcessTime: Date.now() - start,
batchSize: this.batchedHandlers[batchIndex].length,
});
stats.timing(`${config.SERVICE_NAME}.batch_process_time`, Date.now() - start);
stats.histogram(`${config.SERVICE_NAME}.batch_size`, this.batchedHandlers[batchIndex].length);
}
Expand Down
2 changes: 2 additions & 0 deletions indexer/services/ender/src/lib/candles-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ export class CandlesGenerator {
* Get the cached orderbook mid price for a given ticker
*/
export async function getOrderbookMidPriceMap(): Promise<{ [ticker: string]: OrderbookMidPrice; }> {
const start: number = Date.now();
const perpetualMarkets = Object.values(perpetualMarketRefresher.getPerpetualMarketsMap());

const promises = perpetualMarkets.map(async (perpetualMarket: PerpetualMarketFromDatabase) => {
Expand All @@ -550,5 +551,6 @@ export async function getOrderbookMidPriceMap(): Promise<{ [ticker: string]: Ord
Object.assign(priceMap, price);
});

stats.timing(`${config.SERVICE_NAME}.get_orderbook_mid_price_map.timing`, Date.now() - start);
return priceMap;
}
8 changes: 8 additions & 0 deletions indexer/services/ender/src/lib/on-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export async function onMessage(message: KafkaMessage): Promise<void> {
topic: KafkaTopics.TO_ENDER,
},
);
logger.info({
at: 'onMessage#onMessage',
message: 'Processing message',
offset,
blockHeight,
messageTimeInQueue: start - Number(message.timestamp),
numEvents: indexerTendermintBlock.events.length,
});

let success: boolean = false;
const txId: number = await Transaction.start();
Expand Down
6 changes: 0 additions & 6 deletions indexer/services/ender/src/lib/sync-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ export class SyncHandlers {
_.forEach(consolidatedKafkaEventGroup, (events: ConsolidatedKafkaEvent[]) => {
kafkaPublisher.addEvents(events);
});
logger.info({
at: 'SyncHandlers#process',
message: 'Finished processing synchronous handlers',
handlerCountMapping,
batchProcessTime: Date.now() - start,
});
stats.timing(`${config.SERVICE_NAME}.synchronous_events_process_time`, Date.now() - start);
}
}

0 comments on commit 3c13930

Please sign in to comment.