Skip to content

Commit

Permalink
feat(webserver): exposed all usages and not only the execution one
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Aug 2, 2023
1 parent e4678a5 commit 89e3fc6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
8 changes: 6 additions & 2 deletions core/src/test/java/io/kestra/core/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ public static void runApplicationContext(BiConsumer<ApplicationContext, Embedded
}
}

public static void runApplicationContext(String[] env, BiConsumer<ApplicationContext, EmbeddedServer> consumer) throws URISyntaxException {
public static void runApplicationContext(String[] env, Map<String, Object> properties, BiConsumer<ApplicationContext, EmbeddedServer> consumer) throws URISyntaxException {
try (ApplicationContext applicationContext = applicationContext(
pluginsPath(),
null,
properties,
env
).start()) {
EmbeddedServer embeddedServer = applicationContext.getBean(EmbeddedServer.class);
Expand All @@ -110,4 +110,8 @@ public static void runApplicationContext(String[] env, BiConsumer<ApplicationCon
consumer.accept(applicationContext, embeddedServer);
}
}

public static void runApplicationContext(String[] env, BiConsumer<ApplicationContext, EmbeddedServer> consumer) throws URISyntaxException {
runApplicationContext(env, null, consumer);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.kestra.webserver.controllers;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.kestra.core.models.collectors.ExecutionUsage;
import io.kestra.core.models.collectors.Usage;
import io.kestra.core.repositories.ExecutionRepositoryInterface;
import io.kestra.core.services.CollectorService;
import io.kestra.core.services.InstanceService;
Expand All @@ -18,8 +18,6 @@
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

import javax.validation.Valid;

@Slf4j
@Controller
public class MiscController {
Expand Down Expand Up @@ -57,11 +55,11 @@ public Configuration configuration() {
.build();
}

@Get("/api/v1/execution-usage")
@Get("/api/v1/usages")
@ExecuteOn(TaskExecutors.IO)
@Operation(tags = {"Misc"}, summary = "Get execution usage information")
public ExecutionUsage executionUsage() {
return ExecutionUsage.of(executionRepository);
public Usage usages() {
return collectorService.metrics();
}

@Value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.kestra.webserver.controllers;

import io.kestra.core.models.collectors.ExecutionUsage;
import io.kestra.webserver.controllers.h2.JdbcH2ControllerTest;
import io.micronaut.http.client.annotation.Client;
import io.micronaut.rxjava2.http.client.RxHttpClient;
Expand Down Expand Up @@ -32,12 +31,4 @@ void configuration() {
assertThat(response.getIsTaskRunEnabled(), is(false));
assertThat(response.getIsAnonymousUsageEnabled(), is(true));
}

@Test
void executionUsage() {
var response = client.toBlocking().retrieve("/api/v1/execution-usage", ExecutionUsage.class);

assertThat(response, notNullValue());
// the memory executor didn't support daily statistics so we cannot have real execution usage
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.kestra.webserver.controllers;

import io.kestra.core.Helpers;
import io.kestra.core.models.collectors.Usage;
import io.micronaut.http.HttpRequest;
import io.micronaut.rxjava2.http.client.RxHttpClient;
import org.junit.jupiter.api.Test;

import java.net.URISyntaxException;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

class MiscUsageControllerTest {
@Test
void usages() throws URISyntaxException {
Helpers.runApplicationContext(new String[]{"test"}, Map.of("kestra.server-type", "STANDALONE"), (applicationContext, embeddedServer) -> {
try (RxHttpClient client = RxHttpClient.create(embeddedServer.getURL())) {

var response = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/usages"), Usage.class);

assertThat(response.getUuid(), notNullValue());
assertThat(response.getVersion(), notNullValue());
assertThat(response.getStartTime(), notNullValue());
assertThat(response.getEnvironments(), contains("test"));
assertThat(response.getStartTime(), notNullValue());
assertThat(response.getHost().getUuid(), notNullValue());
assertThat(response.getHost().getHardware().getLogicalProcessorCount(), notNullValue());
assertThat(response.getHost().getJvm().getName(), notNullValue());
assertThat(response.getHost().getOs().getFamily(), notNullValue());
assertThat(response.getConfigurations().getRepositoryType(), is("h2"));
assertThat(response.getConfigurations().getQueueType(), is("h2"));
}
});
}
}

0 comments on commit 89e3fc6

Please sign in to comment.