Skip to content

Commit 07a4c6d

Browse files
committed
add saved traces metrics
1 parent e66a30b commit 07a4c6d

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

pkg/api/event_handlers.go

+39-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ var (
4141
Name: "tonapi_send_message_counter",
4242
Help: "The total number of messages received by /v2/blockchain/message endpoint",
4343
})
44+
savedEmulatedTraces = promauto.NewCounterVec(prometheus.CounterOpts{
45+
Name: "saved_emulated_traces",
46+
}, []string{"status"})
4447
)
4548

4649
type decodedMessage struct {
@@ -398,8 +401,12 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
398401
trace, version, _, err := h.storage.GetTraceWithState(ctx, hash)
399402
if err != nil {
400403
h.logger.Warn("get trace from storage: ", zap.Error(err))
404+
savedEmulatedTraces.WithLabelValues("error_restore").Inc()
401405
}
402406
if trace == nil || h.tongoVersion == 0 || version > h.tongoVersion {
407+
if version > h.tongoVersion {
408+
savedEmulatedTraces.WithLabelValues("expired").Inc()
409+
}
403410
configBase64, err := h.storage.TrimmedConfigBase64()
404411
if err != nil {
405412
return nil, toError(http.StatusInternalServerError, err)
@@ -426,8 +433,12 @@ func (h *Handler) EmulateMessageToAccountEvent(ctx context.Context, request *oas
426433
}
427434
err = h.storage.SaveTraceWithState(ctx, hash, trace, h.tongoVersion, []abi.MethodInvocation{}, 24*time.Hour)
428435
if err != nil {
429-
fmt.Println("trace not saved: ", err)
436+
h.logger.Warn("trace not saved: ", zap.Error(err))
437+
savedEmulatedTraces.WithLabelValues("error_save").Inc()
430438
}
439+
savedEmulatedTraces.WithLabelValues("success").Inc()
440+
} else {
441+
savedEmulatedTraces.WithLabelValues("restored").Inc()
431442
}
432443
actions, err := bath.FindActions(ctx, trace, bath.WithInformationSource(h.storage))
433444
if err != nil {
@@ -459,8 +470,12 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
459470
trace, version, _, err := h.storage.GetTraceWithState(ctx, hs)
460471
if err != nil {
461472
h.logger.Warn("get trace from storage: ", zap.Error(err))
473+
savedEmulatedTraces.WithLabelValues("error_restore").Inc()
462474
}
463475
if trace == nil || h.tongoVersion == 0 || version > h.tongoVersion {
476+
if version > h.tongoVersion {
477+
savedEmulatedTraces.WithLabelValues("expired").Inc()
478+
}
464479
var m tlb.Message
465480
if err := tlb.Unmarshal(c, &m); err != nil {
466481
return nil, toError(http.StatusBadRequest, err)
@@ -491,8 +506,12 @@ func (h *Handler) EmulateMessageToEvent(ctx context.Context, request *oas.Emulat
491506
}
492507
err = h.storage.SaveTraceWithState(ctx, hs, trace, h.tongoVersion, []abi.MethodInvocation{}, 24*time.Hour)
493508
if err != nil {
494-
fmt.Println("trace not saved: ", err)
509+
h.logger.Warn("trace not saved: ", zap.Error(err))
510+
savedEmulatedTraces.WithLabelValues("error_save").Inc()
495511
}
512+
savedEmulatedTraces.WithLabelValues("success").Inc()
513+
} else {
514+
savedEmulatedTraces.WithLabelValues("restored").Inc()
496515
}
497516
}
498517
actions, err := bath.FindActions(ctx, trace, bath.WithInformationSource(h.storage))
@@ -525,8 +544,12 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
525544
trace, version, _, err := h.storage.GetTraceWithState(ctx, hs)
526545
if err != nil {
527546
h.logger.Warn("get trace from storage: ", zap.Error(err))
547+
savedEmulatedTraces.WithLabelValues("error_restore").Inc()
528548
}
529549
if trace == nil || h.tongoVersion == 0 || version > h.tongoVersion {
550+
if version > h.tongoVersion {
551+
savedEmulatedTraces.WithLabelValues("expired").Inc()
552+
}
530553
var m tlb.Message
531554
err = tlb.Unmarshal(c, &m)
532555
if err != nil {
@@ -558,8 +581,12 @@ func (h *Handler) EmulateMessageToTrace(ctx context.Context, request *oas.Emulat
558581
}
559582
err = h.storage.SaveTraceWithState(ctx, hs, trace, h.tongoVersion, []abi.MethodInvocation{}, 24*time.Hour)
560583
if err != nil {
561-
fmt.Println("trace not saved: ", err)
584+
h.logger.Warn("trace not saved: ", zap.Error(err))
585+
savedEmulatedTraces.WithLabelValues("error_save").Inc()
562586
}
587+
savedEmulatedTraces.WithLabelValues("success").Inc()
588+
} else {
589+
savedEmulatedTraces.WithLabelValues("restored").Inc()
563590
}
564591
}
565592
t := convertTrace(trace, h.addressBook)
@@ -654,8 +681,12 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
654681
trace, version, _, err := h.storage.GetTraceWithState(ctx, hash)
655682
if err != nil {
656683
h.logger.Warn("get trace from storage: ", zap.Error(err))
684+
savedEmulatedTraces.WithLabelValues("error_restore").Inc()
657685
}
658686
if trace == nil || h.tongoVersion == 0 || version > h.tongoVersion {
687+
if version > h.tongoVersion {
688+
savedEmulatedTraces.WithLabelValues("expired").Inc()
689+
}
659690
configBase64, err := h.storage.TrimmedConfigBase64()
660691
if err != nil {
661692
return nil, toError(http.StatusInternalServerError, err)
@@ -698,8 +729,12 @@ func (h *Handler) EmulateMessageToWallet(ctx context.Context, request *oas.Emula
698729
}
699730
err = h.storage.SaveTraceWithState(ctx, hash, trace, h.tongoVersion, []abi.MethodInvocation{}, 24*time.Hour)
700731
if err != nil {
701-
fmt.Println("trace not saved: ", err)
732+
h.logger.Warn("trace not saved: ", zap.Error(err))
733+
savedEmulatedTraces.WithLabelValues("error_save").Inc()
702734
}
735+
savedEmulatedTraces.WithLabelValues("success").Inc()
736+
} else {
737+
savedEmulatedTraces.WithLabelValues("restored").Inc()
703738
}
704739
t := convertTrace(trace, h.addressBook)
705740
actions, err := bath.FindActions(ctx, trace, bath.ForAccount(*walletAddress), bath.WithInformationSource(h.storage))

pkg/core/trace.go

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func hasInterface(interfacesList []abi.ContractInterface, name abi.ContractInter
193193
}
194194

195195
func Visit(trace *Trace, fn func(trace *Trace)) {
196+
if trace == nil {
197+
return
198+
}
196199
fn(trace)
197200
for _, child := range trace.Children {
198201
Visit(child, fn)

0 commit comments

Comments
 (0)