-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): store metrics in a dedicated repository (#1047)
close #969
- Loading branch information
1 parent
3e08b16
commit 570374e
Showing
43 changed files
with
888 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
core/src/main/java/io/kestra/core/models/executions/MetricEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.kestra.core.models.executions; | ||
|
||
import io.kestra.core.models.DeletedInterface; | ||
import io.kestra.core.models.executions.metrics.Counter; | ||
import io.kestra.core.models.executions.metrics.Timer; | ||
import io.micronaut.core.annotation.Nullable; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
import javax.validation.constraints.NotNull; | ||
|
||
@Value | ||
@Builder(toBuilder = true) | ||
public class MetricEntry implements DeletedInterface { | ||
@NotNull | ||
String namespace; | ||
|
||
@NotNull | ||
String flowId; | ||
|
||
@Nullable | ||
String taskId; | ||
|
||
@Nullable | ||
String executionId; | ||
|
||
@Nullable | ||
String taskRunId; | ||
|
||
@NotNull | ||
String type; | ||
|
||
@NotNull | ||
String name; | ||
|
||
@NotNull | ||
Double value; | ||
|
||
@NotNull | ||
Instant timestamp; | ||
|
||
@Nullable | ||
Map<String, String> tags; | ||
|
||
@NotNull | ||
@Builder.Default | ||
boolean deleted = false; | ||
|
||
public static MetricEntry of(TaskRun taskRun, AbstractMetricEntry<?> metricEntry) { | ||
return MetricEntry.builder() | ||
.namespace(taskRun.getNamespace()) | ||
.flowId(taskRun.getFlowId()) | ||
.executionId(taskRun.getExecutionId()) | ||
.taskId(taskRun.getTaskId()) | ||
.taskRunId(taskRun.getId()) | ||
.type(metricEntry.getType()) | ||
.name(metricEntry.name) | ||
.tags(metricEntry.getTags()) | ||
.value(computeValue(metricEntry)) | ||
.timestamp(metricEntry.getTimestamp()) | ||
.build(); | ||
} | ||
|
||
private static Double computeValue(AbstractMetricEntry<?> metricEntry) { | ||
if (metricEntry instanceof Counter) { | ||
return ((Counter) metricEntry).getValue(); | ||
} | ||
|
||
if (metricEntry instanceof Timer) { | ||
return (double) ((Timer) metricEntry).getValue().toMillis(); | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown metric type: " + metricEntry.getClass()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/io/kestra/core/repositories/MetricRepositoryInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.kestra.core.repositories; | ||
|
||
import io.kestra.core.models.executions.Execution; | ||
import io.kestra.core.models.executions.MetricEntry; | ||
import io.micronaut.data.model.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface MetricRepositoryInterface extends SaveRepositoryInterface<MetricEntry> { | ||
ArrayListTotal<MetricEntry> findByExecutionId(String id, Pageable pageable); | ||
|
||
ArrayListTotal<MetricEntry> findByExecutionIdAndTaskId(String executionId, String taskId, Pageable pageable); | ||
|
||
ArrayListTotal<MetricEntry> findByExecutionIdAndTaskRunId(String executionId, String taskRunId, Pageable pageable); | ||
|
||
Integer purge(Execution execution); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.