@VisibleForTesting
    List<LogFile> applyBundleSizeLogFileLimit(List<LogFile> allLogs) {
        final ImmutableList.Builder<LogFile> truncatedLogFileList = ImmutableList.builder();

        // Always collect the in-memory log and the newest on-disk log file
        // Keep collecting until we pass LOG_COLLECTION_SIZE_LIMIT
        final AtomicBoolean oneFileAdded = new AtomicBoolean(false);
        final AtomicLong collectedSize = new AtomicLong();
        allLogs.stream().sorted(Comparator.comparing(LogFile::lastModified).reversed()).forEach(logFile -> {
            if (logFile.id().equals(IN_MEMORY_LOGFILE_ID)) {
                truncatedLogFileList.add(logFile);
            } else if (!oneFileAdded.get() || collectedSize.get() < LOG_COLLECTION_SIZE_LIMIT) {
                truncatedLogFileList.add(logFile);
                oneFileAdded.set(true);
                collectedSize.addAndGet(logFile.size());
            }
        });
        return truncatedLogFileList.build();
    }
@Test
    public void testLogSizeLimiterWithLimitedSpace() {
        final List<LogFile> fullLoglist = List.of(
                new LogFile("memory", "server.mem.log", 500, Instant.now()),
                new LogFile("0", "server.log", 65 * 1024 * 1024, Instant.now()),
                new LogFile("1", "server.log.1.gz", 500, Instant.now().minus(1, ChronoUnit.DAYS)),
                new LogFile("2", "server.log.2.gz", 500, Instant.now().minus(2, ChronoUnit.DAYS))
        );
        final List<LogFile> shrinkedList = supportBundleService.applyBundleSizeLogFileLimit(fullLoglist);

        assertThat(shrinkedList).hasSize(2);
        assertThat(shrinkedList).extracting(LogFile::id).contains("memory", "0");
    }