CoredumpHandler { void updateMetrics(NodeAgentContext context, Path containerCrashPathOnHost) { Dimensions dimensions = generateDimensions(context); int numberOfUnprocessedCoredumps = FileFinder.files(containerCrashPathOnHost) .match(nameStartsWith(".").negate()) .match(nameMatches(HS_ERR_PATTERN).negate()) .match(nameEndsWith(".lz4").negate()) .match(nameStartsWith("metadata").negate()) .list().size(); metrics.declareGauge(Metrics.APPLICATION_NODE, "coredumps.enqueued", dimensions, Metrics.DimensionType.PRETAGGED).sample(numberOfUnprocessedCoredumps); Path processedCoredumpsPath = doneCoredumpsPath.resolve(context.containerName().asString()); int numberOfProcessedCoredumps = FileFinder.directories(processedCoredumpsPath) .maxDepth(1) .list().size(); metrics.declareGauge(Metrics.APPLICATION_NODE, "coredumps.processed", dimensions, Metrics.DimensionType.PRETAGGED).sample(numberOfProcessedCoredumps); } 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 report_enqueued_and_processed_metrics() throws IOException { Path processingPath = crashPathInContainer.resolve("processing"); Files.createFile(crashPathInContainer.resolve("dump-1")); Files.createFile(crashPathInContainer.resolve("dump-2")); Files.createFile(crashPathInContainer.resolve("hs_err_pid2.log")); Files.createDirectory(processingPath); Files.createFile(processingPath.resolve("metadata.json")); Files.createFile(processingPath.resolve("dump-3")); new UnixPath(doneCoredumpsPath.resolve("container-123").resolve("dump-3-folder").resolve("dump-3")) .createParents() .createNewFile(); coredumpHandler.updateMetrics(context, crashPathInContainer); List<DimensionMetrics> updatedMetrics = metrics.getMetricsByType(Metrics.DimensionType.PRETAGGED); assertEquals(1, updatedMetrics.size()); Map<String, Number> values = updatedMetrics.get(0).getMetrics(); assertEquals(3, values.get("coredumps.enqueued").intValue()); assertEquals(1, values.get("coredumps.processed").intValue()); }