CoredumpHandler { String getMetadata(NodeAgentContext context, Path coredumpDirectory, Supplier<Map<String, Object>> nodeAttributesSupplier) throws IOException { UnixPath metadataPath = new UnixPath(coredumpDirectory.resolve(METADATA_FILE_NAME)); if (!Files.exists(metadataPath.toPath())) { Path coredumpFilePathOnHost = findCoredumpFileInProcessingDirectory(coredumpDirectory); Path coredumpFilePathInContainer = context.pathInNodeFromPathOnHost(coredumpFilePathOnHost); Map<String, Object> metadata = coreCollector.collect(context, coredumpFilePathInContainer); metadata.putAll(nodeAttributesSupplier.get()); metadata.put("coredump_path", doneCoredumpsPath.resolve(context.containerName().asString()).resolve(coredumpDirectory.getFileName()).toString()); String metadataFields = objectMapper.writeValueAsString(Map.of("fields", metadata)); metadataPath.writeUtf8File(metadataFields); return metadataFields; } else { return metadataPath.readUtf8File(); } } 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 get_metadata_test() throws IOException { Map<String, Object> metadata = new HashMap<>(); metadata.put("bin_path", "/bin/bash"); metadata.put("backtrace", List.of("call 1", "function 2", "something something")); Map<String, Object> attributes = Map.of( "hostname", "host123.yahoo.com", "vespa_version", "6.48.4", "kernel_version", "3.10.0-862.9.1.el7.x86_64", "docker_image", "vespa/ci:6.48.4"); String expectedMetadataStr = "{\"fields\":{" + "\"hostname\":\"host123.yahoo.com\"," + "\"kernel_version\":\"3.10.0-862.9.1.el7.x86_64\"," + "\"backtrace\":[\"call 1\",\"function 2\",\"something something\"]," + "\"vespa_version\":\"6.48.4\"," + "\"bin_path\":\"/bin/bash\"," + "\"coredump_path\":\"/home/docker/dumps/container-123/id-123\"," + "\"docker_image\":\"vespa/ci:6.48.4\"" + "}}"; Path coredumpDirectoryInContainer = fileSystem.getPath("/var/crash/id-123"); Path coredumpDirectory = context.pathOnHostFromPathInNode(coredumpDirectoryInContainer); Files.createDirectories(coredumpDirectory); Files.createFile(coredumpDirectory.resolve("dump_core.456")); when(coreCollector.collect(eq(context), eq(coredumpDirectoryInContainer.resolve("dump_core.456")))) .thenReturn(metadata); assertEquals(expectedMetadataStr, coredumpHandler.getMetadata(context, coredumpDirectory, () -> attributes)); verify(coreCollector, times(1)).collect(any(), any()); assertEquals(expectedMetadataStr, coredumpHandler.getMetadata(context, coredumpDirectory, () -> attributes)); verify(coreCollector, times(1)).collect(any(), any()); }
@Test(expected = IllegalStateException.class) public void cant_get_metadata_if_no_core_file() throws IOException { coredumpHandler.getMetadata(context, fileSystem.getPath("/fake/path"), Map::of); }