From b6d6e83ed45158cca31a65cb97c40be92b1677cb Mon Sep 17 00:00:00 2001 From: Florian Hussonnois Date: Thu, 28 Mar 2024 12:07:42 +0100 Subject: [PATCH] fix(core): fix stats webserver (#3408) Fix: #3408 --- .../kestra/core/services/CollectorService.java | 18 +++++++++++------- .../core/services/CollectorServiceTest.java | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/io/kestra/core/services/CollectorService.java b/core/src/main/java/io/kestra/core/services/CollectorService.java index f6445de6d6..593e03b0e0 100644 --- a/core/src/main/java/io/kestra/core/services/CollectorService.java +++ b/core/src/main/java/io/kestra/core/services/CollectorService.java @@ -86,21 +86,25 @@ protected synchronized Usage defaultUsage() { } public Usage metrics() { - Usage.UsageBuilder builder = defaultUsage().toBuilder() + return metrics(true); + } + + private Usage metrics(boolean details) { + Usage.UsageBuilder builder = defaultUsage() + .toBuilder() .uuid(IdUtils.create()); - if (serverType == ServerType.EXECUTOR || serverType == ServerType.STANDALONE) { - builder - .flows(FlowUsage.of(flowRepository)) - .executions(ExecutionUsage.of(executionRepository)); + if (details) { + builder = builder + .flows(FlowUsage.of(flowRepository)) + .executions(ExecutionUsage.of(executionRepository)); } - return builder.build(); } public void report() { try { - Usage metrics = this.metrics(); + Usage metrics = this.metrics(serverType == ServerType.EXECUTOR || serverType == ServerType.STANDALONE); MutableHttpRequest post = this.request(metrics); if (log.isTraceEnabled()) { diff --git a/core/src/test/java/io/kestra/core/services/CollectorServiceTest.java b/core/src/test/java/io/kestra/core/services/CollectorServiceTest.java index a31c23b340..96d918b880 100644 --- a/core/src/test/java/io/kestra/core/services/CollectorServiceTest.java +++ b/core/src/test/java/io/kestra/core/services/CollectorServiceTest.java @@ -45,6 +45,9 @@ public void metrics() throws URISyntaxException { assertThat(metrics.getHost().getOs().getFamily(), notNullValue()); assertThat(metrics.getConfigurations().getRepositoryType(), is("memory")); assertThat(metrics.getConfigurations().getQueueType(), is("memory")); + assertThat(metrics.getExecutions(), notNullValue()); + assertThat(metrics.getExecutions().getDailyExecutionsCount().size(), is(0)); + assertThat(metrics.getExecutions().getDailyTaskRunsCount().size(), is(0)); assertThat(metrics.getInstanceUuid(), is(TestSettingRepository.instanceUuid)); } }