use of com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO in project pinot by linkedin.
the class OnboardResource method deleteExistingAnomalies.
/**
* Delete raw or merged anomalies whose start time is located in the given time ranges, except
* the following two cases:
*
* 1. If a raw anomaly belongs to a merged anomaly whose start time is not located in the given
* time ranges, then the raw anomaly will not be deleted.
*
* 2. If a raw anomaly belongs to a merged anomaly whose start time is located in the given
* time ranges, then it is deleted regardless its start time.
*
* If monitoringWindowStartTime is not given, then start time is set to 0.
* If monitoringWindowEndTime is not given, then end time is set to Long.MAX_VALUE.
* @param monitoringWindowStartTime The start time of the monitoring window (in milli-second)
* @param monitoringWindowEndTime The start time of the monitoring window (in milli-second)
*/
@POST
@Path("function/{id}/deleteExistingAnomalies")
public Map<String, Integer> deleteExistingAnomalies(@PathParam("id") String id, @QueryParam("start") long monitoringWindowStartTime, @QueryParam("end") long monitoringWindowEndTime) {
long functionId = Long.valueOf(id);
AnomalyFunctionDTO anomalyFunction = anomalyFunctionDAO.findById(functionId);
if (anomalyFunction == null) {
LOG.info("Anomaly functionId {} is not found", functionId);
return null;
}
HashMap<String, Integer> returnInfo = new HashMap<>();
// Find merged anomaly result and delete them first
LOG.info("Deleting merged anomaly results in the time range: {} -- {}", new DateTime(monitoringWindowStartTime), new DateTime(monitoringWindowEndTime));
LOG.info("Beginning cleanup merged anomaly results of functionId {} collection {} metric {}", functionId, anomalyFunction.getCollection(), anomalyFunction.getMetric());
int mergedAnomaliesDeleted = 0;
List<MergedAnomalyResultDTO> mergedResults = mergedAnomalyResultDAO.findByStartTimeInRangeAndFunctionId(monitoringWindowStartTime, monitoringWindowEndTime, functionId);
if (CollectionUtils.isNotEmpty(mergedResults)) {
mergedAnomaliesDeleted = deleteMergedResults(mergedResults);
}
returnInfo.put("mergedAnomaliesDeleted", mergedAnomaliesDeleted);
LOG.info("{} merged anomaly results have been deleted", mergedAnomaliesDeleted);
// Find raw anomaly results and delete them
LOG.info("Deleting raw anomaly results in the time range: {} -- {}", new DateTime(monitoringWindowStartTime), new DateTime(monitoringWindowEndTime));
LOG.info("Beginning cleanup merged anomaly results of functionId {} collection {} metric {}", functionId, anomalyFunction.getCollection(), anomalyFunction.getMetric());
int rawAnomaliesDeleted = 0;
List<RawAnomalyResultDTO> rawResults = rawAnomalyResultDAO.findAllByTimeAndFunctionId(monitoringWindowStartTime, monitoringWindowEndTime, functionId);
if (CollectionUtils.isNotEmpty(rawResults)) {
rawAnomaliesDeleted = deleteRawResults(rawResults);
}
returnInfo.put("rawAnomaliesDeleted", rawAnomaliesDeleted);
LOG.info("{} raw anomaly results have been deleted", rawAnomaliesDeleted);
return returnInfo;
}
use of com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO in project pinot by linkedin.
the class OnboardResource method deleteMergedResults.
// Delete merged anomaly results from mergedAnomalyResultDAO
private int deleteMergedResults(List<MergedAnomalyResultDTO> mergedResults) {
LOG.info("Deleting merged results");
int mergedAnomaliesDeleted = 0;
for (MergedAnomalyResultDTO mergedResult : mergedResults) {
// Delete raw anomalies of the merged anomaly
List<RawAnomalyResultDTO> rawAnomalyResultDTOs = mergedResult.getAnomalyResults();
//deleteRawResults(rawAnomalyResultDTOs);
LOG.info(".....Deleting merged result id {} for functionId {}", mergedResult.getId(), mergedResult.getFunctionId());
mergedAnomalyResultDAO.delete(mergedResult);
mergedAnomaliesDeleted++;
}
return mergedAnomaliesDeleted;
}
use of com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO in project pinot by linkedin.
the class AnomaliesResource method getAnomaliesByTime.
/**
* Search anomalies only by time
* @param startTime
* @param endTime
* @return
* @throws Exception
*/
@GET
@Path("search/time/{startTime}/{endTime}/{pageNumber}")
public AnomaliesWrapper getAnomaliesByTime(@PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime, @PathParam("pageNumber") int pageNumber) throws Exception {
List<MergedAnomalyResultDTO> mergedAnomalies = mergedAnomalyResultDAO.findByTime(startTime, endTime);
try {
mergedAnomalies = AlertFilterHelper.applyFiltrationRule(mergedAnomalies, alertFilterFactory);
} catch (Exception e) {
LOG.warn("Failed to apply alert filters on anomalies in start:{}, end:{}, exception:{}", new DateTime(startTime), new DateTime(endTime), e);
}
AnomaliesWrapper anomaliesWrapper = constructAnomaliesWrapperFromMergedAnomalies(mergedAnomalies, pageNumber);
return anomaliesWrapper;
}
use of com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO in project pinot by linkedin.
the class AnomaliesResource method getAnomaliesByMetricIds.
/**
* Find anomalies by metric ids
* @param startTime
* @param endTime
* @param metricIdsString
* @param functionName
* @return
* @throws Exception
*/
@GET
@Path("search/metricIds/{startTime}/{endTime}/{pageNumber}")
public AnomaliesWrapper getAnomaliesByMetricIds(@PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime, @PathParam("pageNumber") int pageNumber, @QueryParam("metricIds") String metricIdsString, @QueryParam("functionName") String functionName) throws Exception {
String[] metricIdsList = metricIdsString.split(COMMA_SEPARATOR);
List<Long> metricIds = new ArrayList<>();
for (String metricId : metricIdsList) {
metricIds.add(Long.valueOf(metricId));
}
List<MergedAnomalyResultDTO> mergedAnomalies = getAnomaliesForMetricIdsInRange(metricIds, startTime, endTime);
AnomaliesWrapper anomaliesWrapper = constructAnomaliesWrapperFromMergedAnomalies(mergedAnomalies, pageNumber);
return anomaliesWrapper;
}
use of com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO in project pinot by linkedin.
the class AnomalyResource method updateAnomalyMergedResultFeedback.
/**
* @param anomalyResultId : anomaly merged result id
* @param payload : Json payload containing feedback @see com.linkedin.thirdeye.constant.AnomalyFeedbackType
* eg. payload
* <p/>
* { "feedbackType": "NOT_ANOMALY", "comment": "this is not an anomaly" }
*/
@POST
@Path(value = "anomaly-merged-result/feedback/{anomaly_merged_result_id}")
public void updateAnomalyMergedResultFeedback(@PathParam("anomaly_merged_result_id") long anomalyResultId, String payload) {
try {
MergedAnomalyResultDTO result = anomalyMergedResultDAO.findById(anomalyResultId);
if (result == null) {
throw new IllegalArgumentException("AnomalyResult not found with id " + anomalyResultId);
}
AnomalyFeedbackDTO feedbackRequest = OBJECT_MAPPER.readValue(payload, AnomalyFeedbackDTO.class);
AnomalyFeedbackDTO feedback = result.getFeedback();
if (feedback == null) {
feedback = new AnomalyFeedbackDTO();
result.setFeedback(feedback);
}
if (feedbackRequest.getStatus() == null) {
feedback.setStatus(FeedbackStatus.NEW);
} else {
feedback.setStatus(feedbackRequest.getStatus());
}
feedback.setComment(feedbackRequest.getComment());
feedback.setFeedbackType(feedbackRequest.getFeedbackType());
anomalyMergedResultDAO.updateAnomalyFeedback(result);
} catch (IOException e) {
throw new IllegalArgumentException("Invalid payload " + payload, e);
}
}
Aggregations