Skip to content

Commit e7f952b

Browse files
JJSantos22RafaelAPB
authored andcommitted
fix(satp): quick fix to include environment variables in the monitor url
Signed-off-by: Jorge Santos <[email protected]>
1 parent 73b4d34 commit e7f952b

File tree

9 files changed

+215
-80
lines changed

9 files changed

+215
-80
lines changed

packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class SATPSession {
180180
sessionData.satpMessages.stage3 = create(Stage3MessagesSchema, {});
181181
sessionData.state = State.ONGOING;
182182

183-
this.monitorService.incrementCounter("created_sessions");
183+
this.monitorService.updateCounter("created_sessions");
184184
} catch (err) {
185185
span.setStatus({ code: SpanStatusCode.ERROR, message: String(err) });
186186
span.recordException(err);

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage0-handler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,13 @@ export class Stage0SATPHandler implements SATPHandler {
192192
session?.getServerSessionData().recipientLedgerAssetId || undefined;
193193
attributes.satp_phase = 0;
194194

195-
this.monitorService.incrementCounter(
195+
this.monitorService.updateCounter(
196+
"ongoing_transactions",
197+
-1,
198+
attributes,
199+
);
200+
201+
this.monitorService.updateCounter(
196202
"failed_transactions",
197203
1,
198204
attributes,
@@ -324,7 +330,13 @@ export class Stage0SATPHandler implements SATPHandler {
324330
session?.getServerSessionData().recipientLedgerAssetId || undefined;
325331
attributes.satp_phase = 0;
326332

327-
this.monitorService.incrementCounter(
333+
this.monitorService.updateCounter(
334+
"ongoing_transactions",
335+
-1,
336+
attributes,
337+
);
338+
339+
this.monitorService.updateCounter(
328340
"failed_transactions",
329341
1,
330342
attributes,

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage1-handler.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,18 @@ export class Stage1SATPHandler implements SATPHandler {
252252
attributes.recipientLedgerAssetId =
253253
session?.getServerSessionData().recipientLedgerAssetId || undefined;
254254

255-
this.monitorService.incrementCounter(
255+
this.monitorService.updateCounter(
256256
"initiated_transactions",
257257
1,
258258
attributes,
259259
);
260260

261+
this.monitorService.updateCounter(
262+
"ongoing_transactions",
263+
1,
264+
attributes,
265+
);
266+
261267
await this.serverService.checkTransferCommenceRequestMessage(
262268
req,
263269
session,
@@ -351,7 +357,13 @@ export class Stage1SATPHandler implements SATPHandler {
351357
session?.getServerSessionData().recipientLedgerAssetId || undefined;
352358
attributes.satp_phase = 1;
353359

354-
this.monitorService.incrementCounter(
360+
this.monitorService.updateCounter(
361+
"ongoing_transactions",
362+
-1,
363+
attributes,
364+
);
365+
366+
this.monitorService.updateCounter(
355367
"failed_transactions",
356368
1,
357369
attributes,
@@ -548,7 +560,13 @@ export class Stage1SATPHandler implements SATPHandler {
548560
session?.getServerSessionData().recipientLedgerAssetId || undefined;
549561
attributes.satp_phase = 1;
550562

551-
this.monitorService.incrementCounter(
563+
this.monitorService.updateCounter(
564+
"ongoing_transactions",
565+
-1,
566+
attributes,
567+
);
568+
569+
this.monitorService.updateCounter(
552570
"failed_transactions",
553571
1,
554572
attributes,

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage2-handler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ export class Stage2SATPHandler implements SATPHandler {
176176
session?.getServerSessionData().recipientLedgerAssetId || undefined;
177177
attributes.satp_phase = 2;
178178

179-
this.monitorService.incrementCounter(
179+
this.monitorService.updateCounter(
180+
"ongoing_transactions",
181+
-1,
182+
attributes,
183+
);
184+
185+
this.monitorService.updateCounter(
180186
"failed_transactions",
181187
1,
182188
attributes,
@@ -297,7 +303,13 @@ export class Stage2SATPHandler implements SATPHandler {
297303
session?.getServerSessionData().recipientLedgerAssetId || undefined;
298304
attributes.satp_phase = 2;
299305

300-
this.monitorService.incrementCounter(
306+
this.monitorService.updateCounter(
307+
"ongoing_transactions",
308+
-1,
309+
attributes,
310+
);
311+
312+
this.monitorService.updateCounter(
301313
"failed_transactions",
302314
1,
303315
attributes,

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage3-handler.ts

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ export class Stage3SATPHandler implements SATPHandler {
187187
session?.getServerSessionData().recipientLedgerAssetId || undefined;
188188
attributes.satp_phase = 3;
189189

190-
this.monitorService.incrementCounter(
190+
this.monitorService.updateCounter(
191+
"ongoing_transactions",
192+
-1,
193+
attributes,
194+
);
195+
196+
this.monitorService.updateCounter(
191197
"failed_transactions",
192198
1,
193199
attributes,
@@ -326,7 +332,13 @@ export class Stage3SATPHandler implements SATPHandler {
326332
session?.getServerSessionData().recipientLedgerAssetId || undefined;
327333
attributes.satp_phase = 3;
328334

329-
this.monitorService.incrementCounter(
335+
this.monitorService.updateCounter(
336+
"ongoing_transactions",
337+
-1,
338+
attributes,
339+
);
340+
341+
this.monitorService.updateCounter(
330342
"failed_transactions",
331343
1,
332344
attributes,
@@ -443,7 +455,13 @@ export class Stage3SATPHandler implements SATPHandler {
443455
session?.getServerSessionData().recipientLedgerAssetId || undefined;
444456
attributes.satp_phase = 3;
445457

446-
this.monitorService.incrementCounter(
458+
this.monitorService.updateCounter(
459+
"ongoing_transactions",
460+
-1,
461+
attributes,
462+
);
463+
464+
this.monitorService.updateCounter(
447465
"failed_transactions",
448466
1,
449467
attributes,
@@ -571,7 +589,13 @@ export class Stage3SATPHandler implements SATPHandler {
571589
session?.getServerSessionData().recipientLedgerAssetId || undefined;
572590
attributes.satp_phase = 3;
573591

574-
this.monitorService.incrementCounter(
592+
this.monitorService.updateCounter(
593+
"ongoing_transactions",
594+
-1,
595+
attributes,
596+
);
597+
598+
this.monitorService.updateCounter(
575599
"failed_transactions",
576600
1,
577601
attributes,
@@ -670,7 +694,13 @@ export class Stage3SATPHandler implements SATPHandler {
670694
session?.getServerSessionData().recipientLedgerAssetId || undefined;
671695
attributes.satp_phase = 3;
672696

673-
this.monitorService.incrementCounter(
697+
this.monitorService.updateCounter(
698+
"ongoing_transactions",
699+
-1,
700+
attributes,
701+
);
702+
703+
this.monitorService.updateCounter(
674704
"failed_transactions",
675705
1,
676706
attributes,
@@ -767,7 +797,13 @@ export class Stage3SATPHandler implements SATPHandler {
767797
session?.getServerSessionData().recipientLedgerAssetId || undefined;
768798
attributes.satp_phase = 3;
769799

770-
this.monitorService.incrementCounter(
800+
this.monitorService.updateCounter(
801+
"ongoing_transactions",
802+
-1,
803+
attributes,
804+
);
805+
806+
this.monitorService.updateCounter(
771807
"failed_transactions",
772808
1,
773809
attributes,
@@ -836,32 +872,47 @@ export class Stage3SATPHandler implements SATPHandler {
836872
attributes.recipientLedgerAssetId =
837873
session.getServerSessionData().recipientLedgerAssetId || undefined;
838874

839-
const stage3Str =
840-
session.getServerSessionData().processedTimestamps?.stage3
841-
?.transferCompleteResponseMessageTimestamp;
842875
const stage0Str =
843876
session.getClientSessionData().processedTimestamps?.stage0
844877
?.newSessionRequestMessageTimestamp;
878+
const stage3Str =
879+
session.getServerSessionData().processedTimestamps?.stage3
880+
?.transferCompleteResponseMessageTimestamp;
845881

846882
if (stage0Str && stage3Str) {
847883
const duration = Number(stage3Str) - Number(stage0Str);
848-
await this.monitorService.incrementCounter(
849-
"transfer_duration",
884+
await this.monitorService.updateCounter(
885+
"transaction_duration",
850886
duration,
851887
attributes,
852888
);
853889
}
854-
this.monitorService.incrementCounter(
890+
this.monitorService.updateCounter(
891+
"transaction_gas_used",
892+
Number(JSON.parse(session.getClientSessionData().senderWrapAssertionClaim?.receipt ?? "{}").gas ?? 0) + Number(JSON.parse(session.getClientSessionData().lockAssertionClaim?.receipt ?? "{}").gas ?? 0) + Number(JSON.parse(session.getClientSessionData().burnAssertionClaim?.receipt ?? "{}").gas ?? 0),
893+
{ ...attributes, side: "client" },
894+
);
895+
this.monitorService.updateCounter(
896+
"transaction_gas_used",
897+
Number(JSON.parse(session.getServerSessionData().receiverWrapAssertionClaim?.receipt ?? "{}").gas ?? 0) + Number(JSON.parse(session.getServerSessionData().mintAssertionClaim?.receipt ?? "{}").gas ?? 0),
898+
{ ...attributes, side: "server" },
899+
);
900+
this.monitorService.updateCounter(
901+
"ongoing_transactions",
902+
-1,
903+
attributes,
904+
);
905+
this.monitorService.updateCounter(
855906
"successful_transactions",
856907
1,
857908
attributes,
858909
);
859-
this.monitorService.incrementCounter(
910+
this.monitorService.updateCounter(
860911
"total_value_exchanged",
861912
Number(session.getClientSessionData().senderAsset?.amount),
862913
{ ...attributes, transaction_direction: "sent" },
863914
);
864-
this.monitorService.incrementCounter(
915+
this.monitorService.updateCounter(
865916
"total_value_exchanged",
866917
Number(session.getServerSessionData().receiverAsset?.amount),
867918
{ ...attributes, transaction_direction: "received" },
@@ -905,7 +956,13 @@ export class Stage3SATPHandler implements SATPHandler {
905956
session?.getServerSessionData().recipientLedgerAssetId || undefined;
906957
attributes.satp_phase = 3;
907958

908-
this.monitorService.incrementCounter(
959+
this.monitorService.updateCounter(
960+
"ongoing_transactions",
961+
-1,
962+
attributes,
963+
);
964+
965+
this.monitorService.updateCounter(
909966
"failed_transactions",
910967
1,
911968
attributes,

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/satp-bridge-execution-layer-implementation.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
120120
attributes.assetId = asset.id;
121121
attributes.operation = "wrapAsset";
122122

123-
this.monitorService.incrementCounter(
124-
"gas_used",
123+
this.monitorService.updateCounter(
124+
"operation_gas_used",
125125
parsedReceipt.gas,
126126
attributes,
127127
);
@@ -186,8 +186,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
186186
attributes.assetId = asset.id;
187187
attributes.operation = "unwrapAsset";
188188

189-
this.monitorService.incrementCounter(
190-
"gas_used",
189+
this.monitorService.updateCounter(
190+
"operation_gas_used",
191191
parsedReceipt.gas,
192192
attributes,
193193
);
@@ -260,8 +260,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
260260
attributes.assetId = asset.id;
261261
attributes.operation = "lockAsset";
262262

263-
this.monitorService.incrementCounter(
264-
"gas_used",
263+
this.monitorService.updateCounter(
264+
"operation_gas_used",
265265
parsedReceipt.gas,
266266
attributes,
267267
);
@@ -331,8 +331,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
331331
attributes.assetId = asset.id;
332332
attributes.operation = "unlockAsset";
333333

334-
this.monitorService.incrementCounter(
335-
"gas_used",
334+
this.monitorService.updateCounter(
335+
"operation_gas_used",
336336
parsedReceipt.gas,
337337
attributes,
338338
);
@@ -402,8 +402,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
402402
attributes.assetId = asset.id;
403403
attributes.operation = "mintAsset";
404404

405-
this.monitorService.incrementCounter(
406-
"gas_used",
405+
this.monitorService.updateCounter(
406+
"operation_gas_used",
407407
parsedReceipt.gas,
408408
attributes,
409409
);
@@ -473,8 +473,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
473473
attributes.assetId = asset.id;
474474
attributes.operation = "burnAsset";
475475

476-
this.monitorService.incrementCounter(
477-
"gas_used",
476+
this.monitorService.updateCounter(
477+
"operation_gas_used",
478478
parsedReceipt.gas,
479479
attributes,
480480
);
@@ -546,8 +546,8 @@ export class SATPBridgeExecutionLayerImpl implements SATPBridgeExecutionLayer {
546546
attributes.assetId = asset.id;
547547
attributes.operation = "assignAsset";
548548

549-
this.monitorService.incrementCounter(
550-
"gas_used",
549+
this.monitorService.updateCounter(
550+
"operation_gas_used",
551551
parsedReceipt.gas,
552552
attributes,
553553
);

packages/cactus-plugin-satp-hermes/src/main/typescript/services/gateway/gateway-orchestrator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ export class GatewayOrchestrator {
657657
addedIDs.push(gateway.id);
658658
}
659659
this.logger.debug(`Added ${addedIDs.length} gateways: ${addedIDs}`);
660-
this.monitorService.incrementCounter("gateways", addedIDs.length);
660+
this.monitorService.updateCounter("gateways", addedIDs.length);
661661
return addedIDs;
662662
} catch (error) {
663663
span.setStatus({
@@ -692,7 +692,7 @@ export class GatewayOrchestrator {
692692
}
693693
this.channels.set(gateway.id, this.createChannel(gateway));
694694
this.counterPartyGateways.set(gateway.id, gateway);
695-
this.monitorService.incrementCounter("gateways");
695+
this.monitorService.updateCounter("gateways");
696696
}
697697

698698
alreadyConnected(ID: string): boolean {

0 commit comments

Comments
 (0)