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}}"));
}
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));
}
Aggregations