@Test public void testAnomaliesByApplicationInvalid() throws Exception { List<AnomalySummary> anomalies = this.resource.queryAnomalies(1000L, null, "Invalid", null, null, null, null, false, null); Assert.assertEquals(anomalies.size(), 0); }
public List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric, String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit) { if (limit == null) { LOG.warn("No upper limit specified while fetching anomalies. Defaulting to " + ANOMALIES_LIMIT_DEFAULT); limit = ANOMALIES_LIMIT_DEFAULT; } Preconditions.checkNotNull(start, "Please specify the start time of the anomaly retrieval window"); List<Set<MergedAnomalyResultDTO>> anomalySets = new ArrayList<>(); if (group != null) { anomalySets.add(new HashSet<>(fetchAnomaliesBySubsGroup(start, end, group))); } if (application != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByApplication(start, end, application))); } if (metric != null || dataset != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDataset(start, end, metric, dataset))); } if (metricDatasetPairs != null && !metricDatasetPairs.isEmpty()) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs))); } if (anomalySets.isEmpty()) { return getAnomalyFormattedOutput(new ArrayList<>()); } for (int i = 1; i < anomalySets.size(); i++) { anomalySets.get(0).retainAll(anomalySets.get(i)); } List<MergedAnomalyResultDTO> anomalies = new ArrayList<>(anomalySets.get(0)); Collections.sort(anomalies, (o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime())); if (fetchTrueAnomaly) { List<MergedAnomalyResultDTO> trueAnomalies = new ArrayList<>(); for (MergedAnomalyResultDTO anomaly : anomalies) { if (anomaly.getFeedback() != null && anomaly.getFeedback().getFeedbackType().isAnomaly()) { trueAnomalies.add(anomaly); } } anomalies = trueAnomalies; } anomalies = anomalies.stream().filter(anomaly -> !anomaly.isChild()).collect(Collectors.toList()); anomalies = anomalies.subList(0, Math.min(anomalies.size(), limit)); return getAnomalyFormattedOutput(anomalies); }
UserDashboardResource { public List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric, String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit) { if (limit == null) { LOG.warn("No upper limit specified while fetching anomalies. Defaulting to " + ANOMALIES_LIMIT_DEFAULT); limit = ANOMALIES_LIMIT_DEFAULT; } Preconditions.checkNotNull(start, "Please specify the start time of the anomaly retrieval window"); List<Set<MergedAnomalyResultDTO>> anomalySets = new ArrayList<>(); if (group != null) { anomalySets.add(new HashSet<>(fetchAnomaliesBySubsGroup(start, end, group))); } if (application != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByApplication(start, end, application))); } if (metric != null || dataset != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDataset(start, end, metric, dataset))); } if (metricDatasetPairs != null && !metricDatasetPairs.isEmpty()) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs))); } if (anomalySets.isEmpty()) { return getAnomalyFormattedOutput(new ArrayList<>()); } for (int i = 1; i < anomalySets.size(); i++) { anomalySets.get(0).retainAll(anomalySets.get(i)); } List<MergedAnomalyResultDTO> anomalies = new ArrayList<>(anomalySets.get(0)); Collections.sort(anomalies, (o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime())); if (fetchTrueAnomaly) { List<MergedAnomalyResultDTO> trueAnomalies = new ArrayList<>(); for (MergedAnomalyResultDTO anomaly : anomalies) { if (anomaly.getFeedback() != null && anomaly.getFeedback().getFeedbackType().isAnomaly()) { trueAnomalies.add(anomaly); } } anomalies = trueAnomalies; } anomalies = anomalies.stream().filter(anomaly -> !anomaly.isChild()).collect(Collectors.toList()); anomalies = anomalies.subList(0, Math.min(anomalies.size(), limit)); return getAnomalyFormattedOutput(anomalies); } }
UserDashboardResource { public List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric, String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit) { if (limit == null) { LOG.warn("No upper limit specified while fetching anomalies. Defaulting to " + ANOMALIES_LIMIT_DEFAULT); limit = ANOMALIES_LIMIT_DEFAULT; } Preconditions.checkNotNull(start, "Please specify the start time of the anomaly retrieval window"); List<Set<MergedAnomalyResultDTO>> anomalySets = new ArrayList<>(); if (group != null) { anomalySets.add(new HashSet<>(fetchAnomaliesBySubsGroup(start, end, group))); } if (application != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByApplication(start, end, application))); } if (metric != null || dataset != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDataset(start, end, metric, dataset))); } if (metricDatasetPairs != null && !metricDatasetPairs.isEmpty()) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs))); } if (anomalySets.isEmpty()) { return getAnomalyFormattedOutput(new ArrayList<>()); } for (int i = 1; i < anomalySets.size(); i++) { anomalySets.get(0).retainAll(anomalySets.get(i)); } List<MergedAnomalyResultDTO> anomalies = new ArrayList<>(anomalySets.get(0)); Collections.sort(anomalies, (o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime())); if (fetchTrueAnomaly) { List<MergedAnomalyResultDTO> trueAnomalies = new ArrayList<>(); for (MergedAnomalyResultDTO anomaly : anomalies) { if (anomaly.getFeedback() != null && anomaly.getFeedback().getFeedbackType().isAnomaly()) { trueAnomalies.add(anomaly); } } anomalies = trueAnomalies; } anomalies = anomalies.stream().filter(anomaly -> !anomaly.isChild()).collect(Collectors.toList()); anomalies = anomalies.subList(0, Math.min(anomalies.size(), limit)); return getAnomalyFormattedOutput(anomalies); } @Inject  UserDashboardResource(MergedAnomalyResultManager anomalyDAO,
      MetricConfigManager metricDAO,
      DatasetConfigManager datasetDAO,
      DetectionConfigManager detectionDAO,
      DetectionAlertConfigManager detectionAlertDAO); }
UserDashboardResource { public List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric, String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit) { if (limit == null) { LOG.warn("No upper limit specified while fetching anomalies. Defaulting to " + ANOMALIES_LIMIT_DEFAULT); limit = ANOMALIES_LIMIT_DEFAULT; } Preconditions.checkNotNull(start, "Please specify the start time of the anomaly retrieval window"); List<Set<MergedAnomalyResultDTO>> anomalySets = new ArrayList<>(); if (group != null) { anomalySets.add(new HashSet<>(fetchAnomaliesBySubsGroup(start, end, group))); } if (application != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByApplication(start, end, application))); } if (metric != null || dataset != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDataset(start, end, metric, dataset))); } if (metricDatasetPairs != null && !metricDatasetPairs.isEmpty()) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs))); } if (anomalySets.isEmpty()) { return getAnomalyFormattedOutput(new ArrayList<>()); } for (int i = 1; i < anomalySets.size(); i++) { anomalySets.get(0).retainAll(anomalySets.get(i)); } List<MergedAnomalyResultDTO> anomalies = new ArrayList<>(anomalySets.get(0)); Collections.sort(anomalies, (o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime())); if (fetchTrueAnomaly) { List<MergedAnomalyResultDTO> trueAnomalies = new ArrayList<>(); for (MergedAnomalyResultDTO anomaly : anomalies) { if (anomaly.getFeedback() != null && anomaly.getFeedback().getFeedbackType().isAnomaly()) { trueAnomalies.add(anomaly); } } anomalies = trueAnomalies; } anomalies = anomalies.stream().filter(anomaly -> !anomaly.isChild()).collect(Collectors.toList()); anomalies = anomalies.subList(0, Math.min(anomalies.size(), limit)); return getAnomalyFormattedOutput(anomalies); } @Inject  UserDashboardResource(MergedAnomalyResultManager anomalyDAO,
      MetricConfigManager metricDAO,
      DatasetConfigManager datasetDAO,
      DetectionConfigManager detectionDAO,
      DetectionAlertConfigManager detectionAlertDAO); List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric,
      String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit); @GET @Path("/anomalies") @ApiOperation(value = "Query anomalies") Response fetchAnomalies(
      @ApiParam(value = "start time of anomaly retrieval window")
      @QueryParam("start") Long start,
      @ApiParam(value = "end time of anomaly retrieval window")
      @QueryParam("end") Long end,
      @ApiParam(value = "alert application/product/team")
      @QueryParam("application") String application,
      @ApiParam(value = "subscription group")
      @QueryParam("group") String group,
      @ApiParam(value = "The name of the metric to fetch anomalies from")
      @QueryParam("metric") String metric,
      @ApiParam(value = "The name of the pinot table to which this metric belongs")
      @QueryParam("dataset") String dataset,
      @ApiParam(value = "Specify multiple dataset::metric pairs")
      @QueryParam("metricAlias") List<MetricDatasetPair> metricDatasetPairs,
      @ApiParam(value = "Specify if you want to only fetch true anomalies")
      @QueryParam("fetchTrueAnomaly") @DefaultValue("false") boolean fetchTrueAnomaly,
      @ApiParam(value = "max number of results")
      @QueryParam("limit") Integer limit); }
UserDashboardResource { public List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric, String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit) { if (limit == null) { LOG.warn("No upper limit specified while fetching anomalies. Defaulting to " + ANOMALIES_LIMIT_DEFAULT); limit = ANOMALIES_LIMIT_DEFAULT; } Preconditions.checkNotNull(start, "Please specify the start time of the anomaly retrieval window"); List<Set<MergedAnomalyResultDTO>> anomalySets = new ArrayList<>(); if (group != null) { anomalySets.add(new HashSet<>(fetchAnomaliesBySubsGroup(start, end, group))); } if (application != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByApplication(start, end, application))); } if (metric != null || dataset != null) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDataset(start, end, metric, dataset))); } if (metricDatasetPairs != null && !metricDatasetPairs.isEmpty()) { anomalySets.add(new HashSet<>(fetchAnomaliesByMetricDatasetPairs(start, end, metricDatasetPairs))); } if (anomalySets.isEmpty()) { return getAnomalyFormattedOutput(new ArrayList<>()); } for (int i = 1; i < anomalySets.size(); i++) { anomalySets.get(0).retainAll(anomalySets.get(i)); } List<MergedAnomalyResultDTO> anomalies = new ArrayList<>(anomalySets.get(0)); Collections.sort(anomalies, (o1, o2) -> -1 * Long.compare(o1.getStartTime(), o2.getStartTime())); if (fetchTrueAnomaly) { List<MergedAnomalyResultDTO> trueAnomalies = new ArrayList<>(); for (MergedAnomalyResultDTO anomaly : anomalies) { if (anomaly.getFeedback() != null && anomaly.getFeedback().getFeedbackType().isAnomaly()) { trueAnomalies.add(anomaly); } } anomalies = trueAnomalies; } anomalies = anomalies.stream().filter(anomaly -> !anomaly.isChild()).collect(Collectors.toList()); anomalies = anomalies.subList(0, Math.min(anomalies.size(), limit)); return getAnomalyFormattedOutput(anomalies); } @Inject  UserDashboardResource(MergedAnomalyResultManager anomalyDAO,
      MetricConfigManager metricDAO,
      DatasetConfigManager datasetDAO,
      DetectionConfigManager detectionDAO,
      DetectionAlertConfigManager detectionAlertDAO); List<AnomalySummary> queryAnomalies(Long start, Long end, String application, String group, String metric,
      String dataset, List<MetricDatasetPair> metricDatasetPairs, boolean fetchTrueAnomaly, Integer limit); @GET @Path("/anomalies") @ApiOperation(value = "Query anomalies") Response fetchAnomalies(
      @ApiParam(value = "start time of anomaly retrieval window")
      @QueryParam("start") Long start,
      @ApiParam(value = "end time of anomaly retrieval window")
      @QueryParam("end") Long end,
      @ApiParam(value = "alert application/product/team")
      @QueryParam("application") String application,
      @ApiParam(value = "subscription group")
      @QueryParam("group") String group,
      @ApiParam(value = "The name of the metric to fetch anomalies from")
      @QueryParam("metric") String metric,
      @ApiParam(value = "The name of the pinot table to which this metric belongs")
      @QueryParam("dataset") String dataset,
      @ApiParam(value = "Specify multiple dataset::metric pairs")
      @QueryParam("metricAlias") List<MetricDatasetPair> metricDatasetPairs,
      @ApiParam(value = "Specify if you want to only fetch true anomalies")
      @QueryParam("fetchTrueAnomaly") @DefaultValue("false") boolean fetchTrueAnomaly,
      @ApiParam(value = "max number of results")
      @QueryParam("limit") Integer limit);  }