use of com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO in project pinot by linkedin.
the class EntityManagerResource method updateEntity.
@POST
public Response updateEntity(@QueryParam("entityType") String entityTypeStr, String jsonPayload) {
if (Strings.isNullOrEmpty(entityTypeStr)) {
throw new WebApplicationException("EntryType can not be null");
}
EntityType entityType = EntityType.valueOf(entityTypeStr);
try {
switch(entityType) {
case ANOMALY_FUNCTION:
AnomalyFunctionDTO anomalyFunctionDTO = OBJECT_MAPPER.readValue(jsonPayload, AnomalyFunctionDTO.class);
if (anomalyFunctionDTO.getId() == null) {
anomalyFunctionManager.save(anomalyFunctionDTO);
} else {
anomalyFunctionManager.update(anomalyFunctionDTO);
}
break;
case EMAIL_CONFIGURATION:
EmailConfigurationDTO emailConfigurationDTO = OBJECT_MAPPER.readValue(jsonPayload, EmailConfigurationDTO.class);
emailConfigurationManager.update(emailConfigurationDTO);
break;
case DASHBOARD_CONFIG:
DashboardConfigDTO dashboardConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, DashboardConfigDTO.class);
dashboardConfigManager.update(dashboardConfigDTO);
break;
case DATASET_CONFIG:
DatasetConfigDTO datasetConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, DatasetConfigDTO.class);
datasetConfigManager.update(datasetConfigDTO);
break;
case METRIC_CONFIG:
MetricConfigDTO metricConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, MetricConfigDTO.class);
metricConfigManager.update(metricConfigDTO);
break;
case OVERRIDE_CONFIG:
OverrideConfigDTO overrideConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, OverrideConfigDTO.class);
if (overrideConfigDTO.getId() == null) {
overrideConfigManager.save(overrideConfigDTO);
} else {
overrideConfigManager.update(overrideConfigDTO);
}
break;
case ALERT_CONFIG:
AlertConfigDTO alertConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, AlertConfigDTO.class);
if (alertConfigDTO.getId() == null) {
alertConfigManager.save(alertConfigDTO);
} else {
alertConfigManager.update(alertConfigDTO);
}
break;
}
} catch (IOException e) {
LOG.error("Error saving the entity with payload : " + jsonPayload, e);
throw new WebApplicationException(e);
}
return Response.ok().build();
}
use of com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO in project pinot by linkedin.
the class AnomaliesResource method getAnomaliesForMetricIdInRange.
// ----------- HELPER FUNCTIONS
/**
* Get anomalies for metric id in a time range
* @param metricId
* @param startTime
* @param endTime
* @return
*/
private List<MergedAnomalyResultDTO> getAnomaliesForMetricIdInRange(Long metricId, Long startTime, Long endTime) {
MetricConfigDTO metricConfig = metricConfigDAO.findById(metricId);
String dataset = metricConfig.getDataset();
String metric = metricConfig.getName();
List<MergedAnomalyResultDTO> mergedAnomalies = mergedAnomalyResultDAO.findByCollectionMetricTime(dataset, metric, startTime, endTime, false);
try {
mergedAnomalies = AlertFilterHelper.applyFiltrationRule(mergedAnomalies, alertFilterFactory);
} catch (Exception e) {
LOG.warn("Failed to apply alert filters on anomalies for metricid:{}, start:{}, end:{}, exception:{}", metricId, new DateTime(startTime), new DateTime(endTime), e);
}
return mergedAnomalies;
}
use of com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO in project pinot by linkedin.
the class AnomaliesResource method constructAnomalyDetails.
/** Construct anomaly details using all details fetched from calls
*
* @param metricName
* @param dataset
* @param datasetConfig
* @param mergedAnomaly
* @param anomalyFunction
* @param currentStartTime inclusive
* @param currentEndTime inclusive
* @param anomalyTimelinesView
* @param timeSeriesDateFormatter
* @param startEndDateFormatterHours
* @param startEndDateFormatterDays
* @return
* @throws JSONException
*/
private AnomalyDetails constructAnomalyDetails(String metricName, String dataset, DatasetConfigDTO datasetConfig, MergedAnomalyResultDTO mergedAnomaly, AnomalyFunctionDTO anomalyFunction, long currentStartTime, long currentEndTime, AnomalyTimelinesView anomalyTimelinesView, DateTimeFormatter timeSeriesDateFormatter, DateTimeFormatter startEndDateFormatterHours, DateTimeFormatter startEndDateFormatterDays, String externalUrl) throws JSONException {
MetricConfigDTO metricConfigDTO = metricConfigDAO.findByMetricAndDataset(metricName, dataset);
AnomalyDetails anomalyDetails = new AnomalyDetails();
anomalyDetails.setMetric(metricName);
anomalyDetails.setDataset(dataset);
if (metricConfigDTO != null) {
anomalyDetails.setMetricId(metricConfigDTO.getId());
}
// The filter ensures that the returned time series from anomalies function only includes the values that are
// located inside the request windows (i.e., between currentStartTime and currentEndTime, inclusive).
List<TimeBucket> timeBuckets = anomalyTimelinesView.getTimeBuckets();
int timeStartIndex = -1;
int timeEndIndex = -1;
for (int i = 0; i < timeBuckets.size(); ++i) {
long currentTimeStamp = timeBuckets.get(i).getCurrentStart();
if (timeStartIndex < 0 && currentTimeStamp >= currentStartTime) {
timeStartIndex = i;
timeEndIndex = i + 1;
} else if (currentTimeStamp <= currentEndTime) {
timeEndIndex = i + 1;
} else if (currentTimeStamp > currentEndTime) {
break;
}
}
if (timeStartIndex < 0 || timeEndIndex < 0) {
timeStartIndex = 0;
timeEndIndex = 0;
}
// get this from timeseries calls
List<String> dateValues = getDateFromTimeSeriesObject(timeBuckets.subList(timeStartIndex, timeEndIndex), timeSeriesDateFormatter);
anomalyDetails.setDates(dateValues);
anomalyDetails.setCurrentEnd(getFormattedDateTime(currentEndTime, datasetConfig, startEndDateFormatterHours, startEndDateFormatterDays));
anomalyDetails.setCurrentStart(getFormattedDateTime(currentStartTime, datasetConfig, startEndDateFormatterHours, startEndDateFormatterDays));
List<String> baselineValues = getDataFromTimeSeriesObject(anomalyTimelinesView.getBaselineValues().subList(timeStartIndex, timeEndIndex));
anomalyDetails.setBaselineValues(baselineValues);
List<String> currentValues = getDataFromTimeSeriesObject(anomalyTimelinesView.getCurrentValues().subList(timeStartIndex, timeEndIndex));
anomalyDetails.setCurrentValues(currentValues);
// from function and anomaly
anomalyDetails.setAnomalyId(mergedAnomaly.getId());
anomalyDetails.setAnomalyRegionStart(timeSeriesDateFormatter.print(mergedAnomaly.getStartTime()));
anomalyDetails.setAnomalyRegionEnd(timeSeriesDateFormatter.print(mergedAnomaly.getEndTime()));
Map<String, String> messageDataMap = getAnomalyMessageDataMap(mergedAnomaly.getMessage());
anomalyDetails.setCurrent(messageDataMap.get(ANOMALY_CURRENT_VAL_KEY));
anomalyDetails.setBaseline(messageDataMap.get(ANOMALY_BASELINE_VAL_KEY));
anomalyDetails.setAnomalyFunctionId(anomalyFunction.getId());
anomalyDetails.setAnomalyFunctionName(anomalyFunction.getFunctionName());
anomalyDetails.setAnomalyFunctionType(anomalyFunction.getType());
anomalyDetails.setAnomalyFunctionProps(anomalyFunction.getProperties());
anomalyDetails.setAnomalyFunctionDimension(mergedAnomaly.getDimensions().toString());
if (mergedAnomaly.getFeedback() != null) {
anomalyDetails.setAnomalyFeedback(AnomalyDetails.getFeedbackStringFromFeedbackType(mergedAnomaly.getFeedback().getFeedbackType()));
}
anomalyDetails.setExternalUrl(externalUrl);
return anomalyDetails;
}
use of com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO 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 com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO 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;
}
Aggregations