forked from Hyperfoil/Horreum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Change Detection Config Discriminators: Fixes Hyperfoil#1380
- Loading branch information
1 parent
794b714
commit 15d78ed
Showing
14 changed files
with
423 additions
and
173 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
33 changes: 10 additions & 23 deletions
33
horreum-api/src/main/java/io/hyperfoil/tools/horreum/api/alerting/ChangeDetection.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
35 changes: 35 additions & 0 deletions
35
...in/java/io/hyperfoil/tools/horreum/api/data/changeDetection/ChangeDetectionModelType.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,35 @@ | ||
package io.hyperfoil.tools.horreum.api.data.changeDetection; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import io.hyperfoil.tools.horreum.api.data.datastore.BaseChangeDetectionConfig; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
@Schema(type = SchemaType.STRING, required = true, | ||
description = "Type of Change Detection Model") | ||
public enum ChangeDetectionModelType { | ||
FIXED_THRESHOLD("fixedThreshold", new TypeReference<FixedThresholdDetectionConfig>() {}), | ||
RELATIVE_DIFFERENCE ("relativeDifference", new TypeReference<RelativeDifferenceDetectionConfig>() {}); | ||
private static final ChangeDetectionModelType[] VALUES = values(); | ||
|
||
private final String name; | ||
private final TypeReference<? extends BaseChangeDetectionConfig> typeReference; | ||
|
||
private <T extends BaseChangeDetectionConfig> ChangeDetectionModelType(String name, TypeReference<T> typeReference) { | ||
this.typeReference = typeReference; | ||
this.name = name; | ||
} | ||
|
||
public <T extends BaseChangeDetectionConfig> TypeReference<T> getTypeReference(){ | ||
return (TypeReference<T>) typeReference; | ||
} | ||
|
||
@JsonCreator | ||
public static ChangeDetectionModelType fromString(String str) { | ||
return Arrays.stream(VALUES).filter(v -> v.name.equals(str)).findAny().orElseThrow(() -> new IllegalArgumentException("Unknown model: " + str)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...src/main/java/io/hyperfoil/tools/horreum/api/data/changeDetection/FixThresholdConfig.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,23 @@ | ||
package io.hyperfoil.tools.horreum.api.data.changeDetection; | ||
|
||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
/* | ||
* Concrete configuration type for io.hyperfoil.tools.horreum.changedetection.FixedThresholdModel | ||
*/ | ||
public class FixThresholdConfig { | ||
@Schema(type = SchemaType.STRING, required = true, example = "fixedThreshold", | ||
description = "model descriminator") | ||
public static final String model = "fixedThreshold"; | ||
@Schema(type = SchemaType.INTEGER, required = true, example = "95", | ||
description = "Threshold Value") | ||
public Double value; | ||
@Schema(type = SchemaType.BOOLEAN, required = true, example = "true", | ||
description = "Threshold enabled/disabled") | ||
public Boolean enabled; | ||
@Schema(type = SchemaType.BOOLEAN, required = true, example = "false", | ||
description = "Is threshold inclusive of defined value?") | ||
public Boolean inclusive; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...va/io/hyperfoil/tools/horreum/api/data/changeDetection/FixedThresholdDetectionConfig.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,19 @@ | ||
package io.hyperfoil.tools.horreum.api.data.changeDetection; | ||
|
||
import io.hyperfoil.tools.horreum.api.data.datastore.BaseChangeDetectionConfig; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
public class FixedThresholdDetectionConfig extends BaseChangeDetectionConfig { | ||
@Schema(type = SchemaType.OBJECT, required = true, | ||
description = "Lower bound for acceptable datapoint values") | ||
public FixThresholdConfig min; | ||
@Schema(type = SchemaType.OBJECT, required = true, | ||
description = "Upper bound for acceptable datapoint values") | ||
public FixThresholdConfig max; | ||
|
||
@Override | ||
public String validateConfig() { | ||
return null; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...o/hyperfoil/tools/horreum/api/data/changeDetection/RelativeDifferenceDetectionConfig.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,31 @@ | ||
package io.hyperfoil.tools.horreum.api.data.changeDetection; | ||
|
||
import io.hyperfoil.tools.horreum.api.data.datastore.BaseChangeDetectionConfig; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
/* | ||
* Concrete configuration type for io.hyperfoil.tools.horreum.changedetection.RelativeDifferenceChangeDetectionModel | ||
*/ | ||
public class RelativeDifferenceDetectionConfig extends BaseChangeDetectionConfig { | ||
@Schema(type = SchemaType.STRING, required = true, example = "relativeDifference", | ||
description = "model descriminator") | ||
public static final String model = "relativeDifference"; | ||
@Schema(type = SchemaType.STRING, required = true, example = "mean", | ||
description = "Relative Difference Detection filter") | ||
public String filter; | ||
@Schema(type = SchemaType.INTEGER, required = true, example = "5", | ||
description = "Number of most recent datapoints used for aggregating the value for comparison.") | ||
public Integer window; | ||
@Schema(type = SchemaType.NUMBER, required = true, example = "0.2", | ||
description = "Maximum difference between the aggregated value of last <window> datapoints and the mean of preceding values.") | ||
public Double threshold; | ||
@Schema(type = SchemaType.INTEGER, required = true, example = "5", | ||
description = "Minimal number of preceding datapoints") | ||
public Integer minPrevious; | ||
|
||
@Override | ||
public String validateConfig() { | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...rc/main/java/io/hyperfoil/tools/horreum/api/data/datastore/BaseChangeDetectionConfig.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,20 @@ | ||
package io.hyperfoil.tools.horreum.api.data.datastore; | ||
|
||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
public abstract class BaseChangeDetectionConfig { | ||
|
||
@Schema(type = SchemaType.BOOLEAN, required = true, | ||
description = "Built In") | ||
public Boolean builtIn = true; | ||
|
||
public BaseChangeDetectionConfig() { | ||
} | ||
|
||
public BaseChangeDetectionConfig(Boolean builtIn) { | ||
this.builtIn = builtIn; | ||
} | ||
|
||
public abstract String validateConfig(); | ||
} |
5 changes: 3 additions & 2 deletions
5
...ackend/src/main/java/io/hyperfoil/tools/horreum/changedetection/ChangeDetectionModel.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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
package io.hyperfoil.tools.horreum.changedetection; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.hyperfoil.tools.horreum.api.data.ConditionConfig; | ||
import io.hyperfoil.tools.horreum.api.data.changeDetection.ChangeDetectionModelType; | ||
import io.hyperfoil.tools.horreum.entity.alerting.ChangeDAO; | ||
import io.hyperfoil.tools.horreum.entity.alerting.DataPointDAO; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
public interface ChangeDetectionModel { | ||
ConditionConfig config(); | ||
|
||
ChangeDetectionModelType type(); | ||
void analyze(List<DataPointDAO> dataPoints, JsonNode configuration, Consumer<ChangeDAO> changeConsumer); | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/io/hyperfoil/tools/horreum/changedetection/ChangeDetectionModelResolver.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,32 @@ | ||
package io.hyperfoil.tools.horreum.changedetection; | ||
|
||
import io.hyperfoil.tools.horreum.api.data.changeDetection.ChangeDetectionModelType; | ||
import io.quarkus.arc.All; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
@ApplicationScoped | ||
public class ChangeDetectionModelResolver { | ||
@Inject | ||
@All | ||
List<ChangeDetectionModel> changeDetectionModels; | ||
|
||
public ChangeDetectionModel getModel(ChangeDetectionModelType type){ | ||
return changeDetectionModels.stream() | ||
.filter( model -> model.type().equals(type)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalStateException("Unknown change detection model type: " + type)); | ||
} | ||
|
||
public Map<String, ChangeDetectionModel> getModels(){ | ||
return changeDetectionModels.stream() | ||
.collect(Collectors.toMap(model -> ((ChangeDetectionModel)model).type().name(), Function.identity())); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.