Search in sources :

Example 1 with Counter

use of io.kestra.core.models.executions.metrics.Counter in project kestra by kestra-io.

the class RunContextTest method metrics.

@SuppressWarnings("OptionalGetWithoutIsPresent")
@Test
void metrics() throws TimeoutException {
    Execution execution = runnerUtils.runOne("io.kestra.tests", "return");
    TaskRunAttempt taskRunAttempt = execution.getTaskRunList().get(1).getAttempts().get(0);
    Counter length = (Counter) taskRunAttempt.findMetrics("length").get();
    Timer duration = (Timer) taskRunAttempt.findMetrics("duration").get();
    assertThat(execution.getTaskRunList(), hasSize(3));
    assertThat(length.getValue(), is(7.0D));
    assertThat(duration.getValue().getNano(), is(greaterThan(0)));
    assertThat(duration.getTags().get("format"), is("{{task.id}}"));
}
Also used : TaskRunAttempt(io.kestra.core.models.executions.TaskRunAttempt) Execution(io.kestra.core.models.executions.Execution) Counter(io.kestra.core.models.executions.metrics.Counter) Timer(io.kestra.core.models.executions.metrics.Timer) Test(org.junit.jupiter.api.Test)

Example 2 with Counter

use of io.kestra.core.models.executions.metrics.Counter in project kestra by kestra-io.

the class RunContextTest method metricsIncrement.

@Test
void metricsIncrement() {
    RunContext runContext = runContextFactory.of();
    Counter counter = Counter.of("counter", 12D);
    runContext.metric(counter);
    runContext.metric(Counter.of("counter", 30D));
    Timer timer = Timer.of("duration", Duration.ofSeconds(12));
    runContext.metric(timer);
    runContext.metric(Timer.of("duration", Duration.ofSeconds(30)));
    runContext.metric(Counter.of("counter", 123D, "key", "value"));
    runContext.metric(Timer.of("duration", Duration.ofSeconds(123), "key", "value"));
    assertThat(runContext.metrics().get(runContext.metrics().indexOf(counter)).getValue(), is(42D));
    assertThat(metricRegistry.counter("counter").count(), is(42D));
    assertThat(runContext.metrics().get(runContext.metrics().indexOf(timer)).getValue(), is(Duration.ofSeconds(42)));
    assertThat(metricRegistry.timer("duration").totalTime(TimeUnit.SECONDS), is(42D));
    assertThat(runContext.metrics().get(2).getValue(), is(123D));
    assertThat(runContext.metrics().get(2).getTags().size(), is(1));
    assertThat(runContext.metrics().get(3).getValue(), is(Duration.ofSeconds(123)));
    assertThat(runContext.metrics().get(3).getTags().size(), is(1));
}
Also used : Counter(io.kestra.core.models.executions.metrics.Counter) Timer(io.kestra.core.models.executions.metrics.Timer) Test(org.junit.jupiter.api.Test)

Aggregations

Counter (io.kestra.core.models.executions.metrics.Counter)2 Timer (io.kestra.core.models.executions.metrics.Timer)2 Test (org.junit.jupiter.api.Test)2 Execution (io.kestra.core.models.executions.Execution)1 TaskRunAttempt (io.kestra.core.models.executions.TaskRunAttempt)1