use of com.linkedin.thirdeye.anomalydetection.alertFilterAutotune.AlertFilterAutoTune in project pinot by linkedin.
the class DetectionJobResource method tuneAlertFilter.
/**
*
* @param id anomaly function id
* @param startTime start time of anomalies to tune alert filter
* @param endTime end time of anomalies to tune alert filter
* @param autoTuneType the type of auto tune to invoke (default is "AUTOTUNE")
* @return HTTP response of request: string of alert filter
*/
@POST
@Path("/autotune/filter/{functionId}")
public Response tuneAlertFilter(@PathParam("functionId") long id, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @QueryParam("autoTuneType") String autoTuneType) {
// get anomalies by function id, start time and end time
AnomalyFunctionDTO anomalyFunctionSpec = DAO_REGISTRY.getAnomalyFunctionDAO().findById(id);
AnomalyFunctionManager anomalyFunctionDAO = DAO_REGISTRY.getAnomalyFunctionDAO();
MergedAnomalyResultManager anomalyMergedResultDAO = DAO_REGISTRY.getMergedAnomalyResultDAO();
List<MergedAnomalyResultDTO> anomalyResultDTOS = anomalyMergedResultDAO.findByStartTimeInRangeAndFunctionId(startTime, endTime, id);
// create alert filter and evaluator
AlertFilter alertFilter = alertFilterFactory.fromSpec(anomalyFunctionSpec.getAlertFilter());
AlertFilterEvaluationUtil evaluator = new AlertFilterEvaluationUtil(alertFilter);
// create alert filter auto tune
AlertFilterAutoTune alertFilterAutotune = alertFilterAutotuneFactory.fromSpec(autoTuneType);
LOG.info("initiated alertFilterAutoTune of Type {}", alertFilterAutotune.getClass().toString());
try {
//evaluate current alert filter (calculate current precision and recall)
evaluator.updatePrecisionAndRecall(anomalyResultDTOS);
LOG.info("AlertFilter of Type {}, has been evaluated with precision: {}, recall: {}", alertFilter.getClass().toString(), evaluator.getPrecision(), evaluator.getRecall());
// get tuned alert filter
Map<String, String> tunedAlertFilter = alertFilterAutotune.tuneAlertFilter(anomalyResultDTOS, evaluator.getPrecision(), evaluator.getRecall());
LOG.info("tuned AlertFilter");
// otherwise do nothing and return alert filter
if (alertFilterAutotune.isUpdated()) {
anomalyFunctionSpec.setAlertFilter(tunedAlertFilter);
anomalyFunctionDAO.update(anomalyFunctionSpec);
LOG.info("Model has been updated");
} else {
LOG.info("Model hasn't been updated because tuned model cannot beat original model");
}
} catch (Exception e) {
LOG.warn("AutoTune throws exception due to: {}", e.getMessage());
}
return Response.ok(alertFilterAutotune.isUpdated()).build();
}
Aggregations