CoredumpHandler { Optional<Path> enqueueCoredump(Path containerCrashPathOnHost, Path containerProcessingPathOnHost) { List<Path> toProcess = FileFinder.files(containerCrashPathOnHost) .match(nameStartsWith(".").negate()) .maxDepth(1) .stream() .sorted(Comparator.comparing(FileFinder.FileAttributes::lastModifiedTime)) .map(FileFinder.FileAttributes::path) .collect(Collectors.toList()); int coredumpIndex = IntStream.range(0, toProcess.size()) .filter(i -> !HS_ERR_PATTERN.matcher(toProcess.get(i).getFileName().toString()).matches()) .findFirst() .orElse(-1); if (coredumpIndex == -1) return Optional.empty(); Path enqueuedDir = uncheck(() -> Files.createDirectories(containerProcessingPathOnHost.resolve(coredumpIdSupplier.get()))); IntStream.range(0, coredumpIndex + 1) .forEach(i -> { Path path = toProcess.get(i); String prefix = i == coredumpIndex ? COREDUMP_FILENAME_PREFIX : ""; uncheck(() -> Files.move(path, enqueuedDir.resolve(prefix + path.getFileName()))); }); return Optional.of(enqueuedDir); } CoredumpHandler(Terminal terminal, CoreCollector coreCollector, CoredumpReporter coredumpReporter,
                           Path crashPathInContainer, Path doneCoredumpsPath, String operatorGroupName, Metrics metrics);   CoredumpHandler(Terminal terminal, CoreCollector coreCollector, CoredumpReporter coredumpReporter,
                           Path crashPathInContainer, Path doneCoredumpsPath, String operatorGroupName, Metrics metrics, Supplier<String> coredumpIdSupplier); void converge(NodeAgentContext context, Supplier<Map<String, Object>> nodeAttributesSupplier); static final String COREDUMP_FILENAME_PREFIX; }
@Test public void coredump_enqueue_test() throws IOException { final Path crashPathOnHost = fileSystem.getPath("/home/docker/container-1/some/crash/path"); final Path processingDir = fileSystem.getPath("/home/docker/container-1/some/other/processing"); Files.createDirectories(crashPathOnHost); createFileAged(crashPathOnHost.resolve(".bash.core.431"), Duration.ZERO); assertFolderContents(crashPathOnHost, ".bash.core.431"); Optional<Path> enqueuedPath = coredumpHandler.enqueueCoredump(crashPathOnHost, processingDir); assertEquals(Optional.empty(), enqueuedPath); Files.move(crashPathOnHost.resolve(".bash.core.431"), crashPathOnHost.resolve("bash.core.431")); createFileAged(crashPathOnHost.resolve("vespa-proton.core.119"), Duration.ofMinutes(10)); createFileAged(crashPathOnHost.resolve("vespa-slobrok.core.673"), Duration.ofMinutes(5)); when(coredumpIdSupplier.get()).thenReturn("id-123").thenReturn("id-321"); enqueuedPath = coredumpHandler.enqueueCoredump(crashPathOnHost, processingDir); assertEquals(Optional.of(processingDir.resolve("id-123")), enqueuedPath); assertFolderContents(crashPathOnHost, "bash.core.431", "vespa-slobrok.core.673"); assertFolderContents(processingDir, "id-123"); assertFolderContents(processingDir.resolve("id-123"), "dump_vespa-proton.core.119"); verify(coredumpIdSupplier, times(1)).get(); enqueuedPath = coredumpHandler.enqueueCoredump(crashPathOnHost, processingDir); assertEquals(Optional.of(processingDir.resolve("id-321")), enqueuedPath); assertFolderContents(crashPathOnHost, "bash.core.431"); assertFolderContents(processingDir, "id-123", "id-321"); assertFolderContents(processingDir.resolve("id-321"), "dump_vespa-slobrok.core.673"); verify(coredumpIdSupplier, times(2)).get(); }
@Test public void enqueue_with_hs_err_files() throws IOException { final Path crashPathOnHost = fileSystem.getPath("/home/docker/container-1/some/crash/path"); final Path processingDir = fileSystem.getPath("/home/docker/container-1/some/other/processing"); Files.createDirectories(crashPathOnHost); createFileAged(crashPathOnHost.resolve("java.core.69"), Duration.ofSeconds(15)); createFileAged(crashPathOnHost.resolve("hs_err_pid69.log"), Duration.ofSeconds(20)); createFileAged(crashPathOnHost.resolve("java.core.2420"), Duration.ofSeconds(40)); createFileAged(crashPathOnHost.resolve("hs_err_pid2420.log"), Duration.ofSeconds(49)); createFileAged(crashPathOnHost.resolve("hs_err_pid2421.log"), Duration.ofSeconds(50)); when(coredumpIdSupplier.get()).thenReturn("id-123").thenReturn("id-321"); Optional<Path> enqueuedPath = coredumpHandler.enqueueCoredump(crashPathOnHost, processingDir); assertEquals(Optional.of(processingDir.resolve("id-123")), enqueuedPath); assertFolderContents(crashPathOnHost, "hs_err_pid69.log", "java.core.69"); assertFolderContents(processingDir, "id-123"); assertFolderContents(processingDir.resolve("id-123"), "hs_err_pid2420.log", "hs_err_pid2421.log", "dump_java.core.2420"); }