Skip to content

Commit afd4c07

Browse files
MB-49579 Skip events list trimming when limit=-1 in /events
/events&sinceTime=<time>&limit=-1 specifically fails since we call lists:nthtail with n as "-1". Avoid calling lists:nthtail when n is -1 and add validation checks for limit to be always >= -1. Change-Id: I5063b14938bb540a39942db62b9119c8012e69e6 Reviewed-on: https://review.couchbase.org/c/ns_server/+/165953 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Tested-by: Hareen Kancharla <[email protected]> Reviewed-by: Abhijeeth Nuthan <[email protected]>
1 parent 85f2e11 commit afd4c07

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/event_log_server.erl

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ recent(StartSeqNum) ->
249249
end, {StartSeqNum, []}, recent()),
250250
{MaxSeqNum, [{struct, get_event(strip_seqnum(L))} || L <- Logs]}.
251251

252+
-spec build_events_json(MinTStamp :: undefined | string(),
253+
Limit :: -1 | non_neg_integer()) ->
254+
[term()].
252255
build_events_json(MinTStamp, Limit) ->
253256
Logs0 = recent(),
254257
Logs = case {MinTStamp, Limit} of
@@ -259,17 +262,25 @@ build_events_json(MinTStamp, Limit) ->
259262
{undefined, L} ->
260263
misc:tail_of_length(Logs0, L);
261264
_ ->
262-
misc:tail_of_length(
263-
lists:filter(fun (Log0) ->
264-
Log = strip_seqnum(Log0),
265-
TStamp = Log#log_entry.timestamp,
266-
if
267-
TStamp >= MinTStamp ->
268-
true;
269-
true ->
270-
false
271-
end
272-
end, Logs0), Limit)
265+
FilteredLogs = lists:filter(
266+
fun (Log0) ->
267+
Log = strip_seqnum(Log0),
268+
TStamp = Log#log_entry.timestamp,
269+
if
270+
TStamp >= MinTStamp ->
271+
true;
272+
true ->
273+
false
274+
end
275+
end, Logs0),
276+
%% Limit = -1 implies, return all logs. We validate 'Limit'
277+
%% is >= -1 before calling this function.
278+
case Limit of
279+
-1 ->
280+
FilteredLogs;
281+
L ->
282+
misc:tail_of_length(FilteredLogs, L)
283+
end
273284
end,
274285
%% Reverse the logs since they are stored in the descending order of time.
275286
[{struct, get_event(strip_seqnum(Log))} || Log <- lists:reverse(Logs)].

src/menelaus_alert.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ get_handle_events_params(Values) ->
8282

8383
handle_events_validators() ->
8484
[validator:iso_8601_utc(sinceTime, [], _),
85-
validator:integer(limit, _),
85+
validator:integer(limit, -1, infinity, _),
8686
validator:unsupported(_)].
8787

8888
handle_events(Req) ->

0 commit comments

Comments
 (0)