use of javax.ws.rs.Path in project pinot by linkedin.
the class AnomaliesResource method getAnomalyCountForMetricInRange.
/**
* Get count of anomalies for metric in time range
* @param metricId
* @param startTime
* @param endTime
* @return
*/
@GET
@Path("getAnomalyCount/{metricId}/{startTime}/{endTime}")
public AnomaliesSummary getAnomalyCountForMetricInRange(@PathParam("metricId") Long metricId, @PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime) {
AnomaliesSummary anomaliesSummary = new AnomaliesSummary();
List<MergedAnomalyResultDTO> mergedAnomalies = getAnomaliesForMetricIdInRange(metricId, startTime, endTime);
int resolvedAnomalies = 0;
int unresolvedAnomalies = 0;
for (MergedAnomalyResultDTO mergedAnomaly : mergedAnomalies) {
AnomalyFeedbackDTO anomalyFeedback = mergedAnomaly.getFeedback();
if (anomalyFeedback == null || anomalyFeedback.getFeedbackType() == null) {
unresolvedAnomalies++;
} else if (anomalyFeedback != null && anomalyFeedback.getFeedbackType() != null && anomalyFeedback.getFeedbackType().equals(AnomalyFeedbackType.ANOMALY)) {
unresolvedAnomalies++;
} else {
resolvedAnomalies++;
}
}
anomaliesSummary.setMetricId(metricId);
anomaliesSummary.setStartTime(startTime);
anomaliesSummary.setEndTime(endTime);
anomaliesSummary.setNumAnomalies(mergedAnomalies.size());
anomaliesSummary.setNumAnomaliesResolved(resolvedAnomalies);
anomaliesSummary.setNumAnomaliesUnresolved(unresolvedAnomalies);
return anomaliesSummary;
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class DataResource method getMetricNamesForDataset.
//------------- endpoints to fetch summary -------------
@GET
@Path("summary/metrics")
public List<String> getMetricNamesForDataset(@QueryParam("dataset") String dataset) {
List<MetricConfigDTO> metrics = new ArrayList<>();
if (Strings.isNullOrEmpty(dataset)) {
metrics.addAll(metricConfigDAO.findAll());
} else {
metrics.addAll(metricConfigDAO.findActiveByDataset(dataset));
}
List<String> metricsNames = new ArrayList<>();
for (MetricConfigDTO metricConfigDTO : metrics) {
metricsNames.add(metricConfigDTO.getName());
}
return metricsNames;
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class DataResource method getFiltersForMetric.
@GET
@Path("autocomplete/filters/metric/{metricId}")
public Map<String, List<String>> getFiltersForMetric(@PathParam("metricId") Long metricId) {
Map<String, List<String>> filterMap = new HashMap<>();
try {
// TODO : cache this
MetricConfigDTO metricConfigDTO = metricConfigDAO.findById(metricId);
DatasetConfigDTO datasetConfigDTO = datasetConfigDAO.findByDataset(metricConfigDTO.getDataset());
String dimensionFiltersJson = dimensionsFilterCache.get(datasetConfigDTO.getDataset());
if (!Strings.isNullOrEmpty(dimensionFiltersJson)) {
filterMap = OBJECT_MAPPER.readValue(dimensionFiltersJson, LinkedHashMap.class);
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new WebApplicationException(e);
}
return filterMap;
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class DataResource method getAnomalySummary.
@GET
@Path("dashboard/anomalysummary")
public Map<String, List<AnomaliesSummary>> getAnomalySummary(@QueryParam("dashboard") String dashboard, @QueryParam("timeRanges") String timeRanges) {
List<Long> metricIds = getMetricIdsByDashboard(dashboard);
List<String> timeRangesList = Lists.newArrayList(timeRanges.split(","));
Map<String, Long> timeRangeToDurationMap = new HashMap<>();
for (String timeRange : timeRangesList) {
String[] tokens = timeRange.split("_");
long duration = TimeUnit.MILLISECONDS.convert(Long.valueOf(tokens[0]), TimeUnit.valueOf(tokens[1]));
timeRangeToDurationMap.put(timeRange, duration);
}
Map<String, List<AnomaliesSummary>> metricAliasToAnomaliesSummariesMap = new HashMap<>();
for (Long metricId : metricIds) {
List<AnomaliesSummary> summaries = new ArrayList<>();
MetricConfigDTO metricConfig = metricConfigDAO.findById(metricId);
String metricAlias = metricConfig.getAlias();
String dataset = metricConfig.getDataset();
long endTime = Utils.getMaxDataTimeForDataset(dataset);
for (String timeRange : timeRangesList) {
long startTime = endTime - timeRangeToDurationMap.get(timeRange);
AnomaliesSummary summary = anomaliesResoure.getAnomalyCountForMetricInRange(metricId, startTime, endTime);
summaries.add(summary);
}
metricAliasToAnomaliesSummariesMap.put(metricAlias, summaries);
}
return metricAliasToAnomaliesSummariesMap;
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class IngraphMetricConfigResource method updateMetricConfig.
@GET
@Path("/update")
public String updateMetricConfig(@NotNull @QueryParam("id") long ingraphMetricConfigId, @QueryParam("rrdName") String rrdName, @QueryParam("metricName") String metricName, @QueryParam("dashboardName") String dashboardName, @QueryParam("metricDataType") String metricDataType, @QueryParam("metricSourceType") String metricSourceType, @QueryParam("container") String container) {
try {
IngraphMetricConfigDTO ingraphMetricConfigDTO = ingraphMetricConfigDao.findById(ingraphMetricConfigId);
ingraphMetricConfigDTO.setRrdName(rrdName);
ingraphMetricConfigDTO.setMetricName(metricName);
ingraphMetricConfigDTO.setDashboardName(dashboardName);
ingraphMetricConfigDTO.setContainer(container);
ingraphMetricConfigDTO.setMetricDataType(metricDataType);
ingraphMetricConfigDTO.setMetricSourceType(metricSourceType);
int numRowsUpdated = ingraphMetricConfigDao.update(ingraphMetricConfigDTO);
if (numRowsUpdated == 1) {
return JsonResponseUtil.buildResponseJSON(ingraphMetricConfigDTO).toString();
} else {
return JsonResponseUtil.buildErrorResponseJSON("Failed to update metric id:" + ingraphMetricConfigId).toString();
}
} catch (Exception e) {
return JsonResponseUtil.buildErrorResponseJSON("Failed to update metric id:" + ingraphMetricConfigId + ". Exception:" + e.getMessage()).toString();
}
}
Aggregations