Skip to content

Commit

Permalink
Merge pull request #1914 from balena-io/logs-limit-history-count
Browse files Browse the repository at this point in the history
Logs: limit history count to the retention limit
  • Loading branch information
Page- authored Dec 24, 2024
2 parents c1967b9 + d8f05da commit b4087a1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/features/device-logs/lib/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getNanoTimestamp } from '../../../lib/utils.js';
import type { SetupOptions } from '../../../index.js';
import {
LOGS_DEFAULT_HISTORY_COUNT,
LOGS_DEFAULT_RETENTION_LIMIT,
LOGS_DEFAULT_SUBSCRIPTION_COUNT,
LOGS_HEARTBEAT_INTERVAL,
LOGS_READ_STREAM_FLUSH_INTERVAL,
Expand Down Expand Up @@ -202,21 +203,20 @@ function getCount(
countParam: string | undefined,
defaultCount: number,
): number {
let count: number;
if (countParam == null) {
return defaultCount;
}

if (countParam === 'all') {
return Infinity;
}

const parsedCount = parseInt(countParam, 10);

if (!Number.isNaN(parsedCount)) {
return parsedCount;
count = defaultCount;
} else if (countParam === 'all') {
count = Infinity;
} else {
return defaultCount;
const parsedCount = parseInt(countParam, 10);
if (!Number.isNaN(parsedCount)) {
count = parsedCount;
} else {
count = defaultCount;
}
}
return Math.min(count, LOGS_DEFAULT_RETENTION_LIMIT);
}

function getHistory(
Expand Down

0 comments on commit b4087a1

Please sign in to comment.