Skip to content

Commit 254d0f8

Browse files
configurable migrated indices
1 parent f72b482 commit 254d0f8

9 files changed

Lines changed: 36 additions & 8 deletions

File tree

config/config.devnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ features:
8484
durationThresholdMs: 5000
8585
failureCountThreshold: 5
8686
resetTimeoutMs: 30000
87+
elasticMigratedIndices:
88+
logs: 'events'
8789
statusChecker:
8890
enabled: false
8991
thresholds:

config/config.e2e.mainnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ features:
8585
durationThresholdMs: 5000
8686
failureCountThreshold: 5
8787
resetTimeoutMs: 30000
88+
elasticMigratedIndices:
89+
logs: 'events'
8890
statusChecker:
8991
enabled: false
9092
thresholds:

config/config.mainnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ features:
8585
durationThresholdMs: 5000
8686
failureCountThreshold: 5
8787
resetTimeoutMs: 30000
88+
elasticMigratedIndices:
89+
logs: 'events'
8890
statusChecker:
8991
enabled: false
9092
thresholds:

config/config.testnet.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ features:
8484
durationThresholdMs: 5000
8585
failureCountThreshold: 5
8686
resetTimeoutMs: 30000
87+
elasticMigratedIndices:
88+
logs: 'events'
8789
statusChecker:
8890
enabled: false
8991
thresholds:

src/common/api-config/api.config.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ export class ApiConfigService {
407407
};
408408
}
409409

410+
getElasticMigratedIndicesConfig(): Record<string, string> {
411+
return this.configService.get<Record<string, string>>('features.elasticMigratedIndices') ?? {};
412+
}
413+
410414
getIsWebsocketApiActive(): boolean {
411415
return this.configService.get<boolean>('api.websocket') ?? true;
412416
}

src/common/indexer/elastic/elastic.indexer.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,17 @@ export class ElasticIndexerService implements IndexerInterface {
591591
return query;
592592
}
593593

594-
async getTransactionLogs(hashes: string[]): Promise<any[]> {
594+
async getTransactionLogs(hashes: string[], eventsIndex: string, txHashField: string): Promise<any[]> {
595595
const queries = [];
596596
for (const hash of hashes) {
597-
queries.push(QueryType.Match('txHash', hash));
597+
queries.push(QueryType.Match(txHashField, hash));
598598
}
599599

600600
const elasticQueryLogs = ElasticQuery.create()
601601
.withPagination({ from: 0, size: 10000 })
602602
.withCondition(QueryConditionOptions.should, queries);
603603

604-
return await this.elasticService.getList('events', 'id', elasticQueryLogs);
604+
return await this.elasticService.getList(eventsIndex, 'id', elasticQueryLogs);
605605
}
606606

607607
async getTransactionScResults(txHash: string): Promise<any[]> {

src/common/indexer/indexer.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export interface IndexerInterface {
134134

135135
getTokensForAddress(address: string, queryPagination: QueryPagination, filter: TokenFilter): Promise<Token[]>
136136

137-
getTransactionLogs(hashes: string[]): Promise<ElasticTransactionLogEvent[]>
137+
getTransactionLogs(hashes: string[], eventsIndex: string, txHashField: string): Promise<ElasticTransactionLogEvent[]>
138138

139139
getTransactionScResults(txHash: string): Promise<ScResult[]>
140140

src/common/indexer/indexer.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ export class IndexerService implements IndexerInterface {
302302
}
303303

304304
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)
305-
async getTransactionLogs(hashes: string[]): Promise<ElasticTransactionLogEvent[]> {
306-
return await this.indexerInterface.getTransactionLogs(hashes);
305+
async getTransactionLogs(hashes: string[], eventsIndex: string, txHashField: string): Promise<ElasticTransactionLogEvent[]> {
306+
return await this.indexerInterface.getTransactionLogs(hashes, eventsIndex, txHashField);
307307
}
308308

309309
@LogPerformanceAsync(MetricsEvents.SetIndexerDuration)

src/endpoints/transactions/transaction.get.service.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { TransactionOperationType } from "./entities/transaction.operation.type"
2020
import { QueryPagination } from "src/common/entities/query.pagination";
2121
import { NftFilter } from "../nfts/entities/nft.filter";
2222
import { TokenAccount } from "src/common/indexer/entities";
23+
import { ApiConfigService } from "../../common/api-config/api.config.service";
2324

2425
@Injectable()
2526
export class TransactionGetService {
@@ -30,6 +31,7 @@ export class TransactionGetService {
3031
private readonly gatewayService: GatewayService,
3132
@Inject(forwardRef(() => TokenTransferService))
3233
private readonly tokenTransferService: TokenTransferService,
34+
private readonly apiConfigService: ApiConfigService,
3335
) { }
3436

3537
private async tryGetTransactionFromElasticBySenderAndNonce(sender: string, nonce: number): Promise<TransactionDetailed | undefined> {
@@ -51,8 +53,22 @@ export class TransactionGetService {
5153
return result.map(x => ApiUtils.mergeObjects(new TransactionLog(), x));
5254
}
5355

54-
private async getTransactionLogsFromElasticInternal(hashes: string[]): Promise<any[]> {
55-
const rawHits = await this.indexerService.getTransactionLogs(hashes);
56+
private async getTransactionLogsFromElasticInternal(hashes: string[]) {
57+
const esMigratedIndices = this.apiConfigService.getElasticMigratedIndicesConfig();
58+
const index = esMigratedIndices?.['logs'] ?? 'logs';
59+
if (index === 'events') {
60+
return await this.getTransactionLogsFromElasticInternalEventsIndex(hashes);
61+
}
62+
63+
return await this.getTransactionLogsFromElasticInternalLogsIndex(hashes);
64+
}
65+
66+
private async getTransactionLogsFromElasticInternalLogsIndex(hashes: string[]): Promise<any[]> {
67+
return await this.indexerService.getTransactionLogs(hashes, 'logs', '_id');
68+
}
69+
70+
private async getTransactionLogsFromElasticInternalEventsIndex(hashes: string[]): Promise<any[]> {
71+
const rawHits = await this.indexerService.getTransactionLogs(hashes, 'events', 'txHash');
5672

5773
const logsMap: Map<string, TransactionLog> = new Map();
5874

0 commit comments

Comments
 (0)