From 565f526bc37c1b0b7334710227756d8a23b74385 Mon Sep 17 00:00:00 2001 From: Victoria Erokhina Date: Wed, 14 May 2025 15:47:40 +0000 Subject: [PATCH] get saved trace if not found --- pkg/api/event_handlers.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/api/event_handlers.go b/pkg/api/event_handlers.go index 62659c17..cab8e55e 100644 --- a/pkg/api/event_handlers.go +++ b/pkg/api/event_handlers.go @@ -156,7 +156,19 @@ func (h *Handler) GetTrace(ctx context.Context, params oas.GetTraceParams) (*oas } trace, emulated, err := h.getTraceByHash(ctx, hash) if errors.Is(err, core.ErrEntityNotFound) { - return nil, toError(http.StatusNotFound, err) + var version int + trace, version, _, err = h.storage.GetTraceWithState(ctx, hash.Hex()) + if errors.Is(err, core.ErrEntityNotFound) { + return nil, toError(http.StatusNotFound, err) + } + if err != nil { + return nil, toError(http.StatusInternalServerError, err) + } + if h.tongoVersion > 0 && version > h.tongoVersion { + savedEmulatedTraces.WithLabelValues("expired").Inc() + return nil, toError(http.StatusNotFound, fmt.Errorf("trace expired")) + } + emulated = false } if errors.Is(err, core.ErrTraceIsTooLong) { return nil, toError(http.StatusRequestEntityTooLarge, err) @@ -178,7 +190,19 @@ func (h *Handler) GetEvent(ctx context.Context, params oas.GetEventParams) (*oas } trace, emulated, err := h.getTraceByHash(ctx, traceID) if errors.Is(err, core.ErrEntityNotFound) { - return nil, toError(http.StatusNotFound, err) + var version int + trace, version, _, err = h.storage.GetTraceWithState(ctx, traceID.Hex()) + if errors.Is(err, core.ErrEntityNotFound) { + return nil, toError(http.StatusNotFound, err) + } + if err != nil { + return nil, toError(http.StatusInternalServerError, err) + } + if h.tongoVersion > 0 && version > h.tongoVersion { + savedEmulatedTraces.WithLabelValues("expired").Inc() + return nil, toError(http.StatusNotFound, fmt.Errorf("trace expired")) + } + emulated = false } if errors.Is(err, core.ErrTraceIsTooLong) { return nil, toError(http.StatusRequestEntityTooLarge, err)