Skip to content

Commit b23894c

Browse files
committed
get saved trace if not found
1 parent 52e1caf commit b23894c

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

pkg/api/event_handlers.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,19 @@ func (h *Handler) GetTrace(ctx context.Context, params oas.GetTraceParams) (*oas
156156
}
157157
trace, emulated, err := h.getTraceByHash(ctx, hash)
158158
if errors.Is(err, core.ErrEntityNotFound) {
159-
return nil, toError(http.StatusNotFound, err)
159+
var version int
160+
trace, version, _, err = h.storage.GetTraceWithState(ctx, hash.Hex())
161+
if errors.Is(err, core.ErrEntityNotFound) {
162+
return nil, toError(http.StatusNotFound, err)
163+
}
164+
if err != nil {
165+
return nil, toError(http.StatusInternalServerError, err)
166+
}
167+
if h.tongoVersion > 0 && version > h.tongoVersion {
168+
savedEmulatedTraces.WithLabelValues("expired").Inc()
169+
return nil, toError(http.StatusNotFound, fmt.Errorf("trace expired"))
170+
}
171+
emulated = false
160172
}
161173
if errors.Is(err, core.ErrTraceIsTooLong) {
162174
return nil, toError(http.StatusRequestEntityTooLarge, err)
@@ -178,7 +190,19 @@ func (h *Handler) GetEvent(ctx context.Context, params oas.GetEventParams) (*oas
178190
}
179191
trace, emulated, err := h.getTraceByHash(ctx, traceID)
180192
if errors.Is(err, core.ErrEntityNotFound) {
181-
return nil, toError(http.StatusNotFound, err)
193+
var version int
194+
trace, version, _, err = h.storage.GetTraceWithState(ctx, hash.Hex())
195+
if errors.Is(err, core.ErrEntityNotFound) {
196+
return nil, toError(http.StatusNotFound, err)
197+
}
198+
if err != nil {
199+
return nil, toError(http.StatusInternalServerError, err)
200+
}
201+
if h.tongoVersion > 0 && version > h.tongoVersion {
202+
savedEmulatedTraces.WithLabelValues("expired").Inc()
203+
return nil, toError(http.StatusNotFound, fmt.Errorf("trace expired"))
204+
}
205+
emulated = false
182206
}
183207
if errors.Is(err, core.ErrTraceIsTooLong) {
184208
return nil, toError(http.StatusRequestEntityTooLarge, err)

0 commit comments

Comments
 (0)