|
|
@ -631,78 +631,47 @@ export async function getHSR( |
|
|
|
try { |
|
|
|
try { |
|
|
|
const grafanaUrl = getGrafanaUrl(analyticUnit.grafanaUrl); |
|
|
|
const grafanaUrl = getGrafanaUrl(analyticUnit.grafanaUrl); |
|
|
|
const data = await queryByMetric(analyticUnit.metric, grafanaUrl, from, to, HASTIC_API_KEY); |
|
|
|
const data = await queryByMetric(analyticUnit.metric, grafanaUrl, from, to, HASTIC_API_KEY); |
|
|
|
let resultSeries = { |
|
|
|
|
|
|
|
hsr: data |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(analyticUnit.detectorType === AnalyticUnit.DetectorType.THRESHOLD) { |
|
|
|
if(analyticUnit.detectorType !== AnalyticUnit.DetectorType.ANOMALY) { |
|
|
|
let cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
return { hsr: data }; |
|
|
|
if( |
|
|
|
} |
|
|
|
cache === null || |
|
|
|
let cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
cache.data.alpha !== (analyticUnit as AnalyticUnit.ThresholdAnalyticUnit).value || |
|
|
|
if( |
|
|
|
cache.data.confidence !== (analyticUnit as AnalyticUnit.ThresholdAnalyticUnit).condition |
|
|
|
cache === null || |
|
|
|
) { |
|
|
|
cache.data.alpha !== (analyticUnit as AnalyticUnit.AnomalyAnalyticUnit).alpha || |
|
|
|
await runLearning(analyticUnit.id, from, to); |
|
|
|
cache.data.confidence !== (analyticUnit as AnalyticUnit.AnomalyAnalyticUnit).confidence |
|
|
|
cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
) { |
|
|
|
} |
|
|
|
await runLearning(analyticUnit.id, from, to); |
|
|
|
|
|
|
|
cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
cache = cache.data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const analyticUnitType = analyticUnit.type; |
|
|
|
|
|
|
|
const detector = analyticUnit.detectorType; |
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
|
|
|
data: data.values, |
|
|
|
|
|
|
|
analyticUnitType, |
|
|
|
|
|
|
|
detector, |
|
|
|
|
|
|
|
cache |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const processingTask = new AnalyticsTask(analyticUnit.id, AnalyticsTaskType.PROCESS, payload); |
|
|
|
|
|
|
|
const result = await runTask(processingTask); |
|
|
|
|
|
|
|
if(result.status !== AnalyticUnit.AnalyticUnitStatus.SUCCESS) { |
|
|
|
|
|
|
|
throw new Error(`Data processing error: ${result.error}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(result.payload.threshold !== undefined) { |
|
|
|
|
|
|
|
resultSeries['threshold'] = { values: result.payload.threshold, columns: data.columns }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(analyticUnit.detectorType === AnalyticUnit.DetectorType.ANOMALY) { |
|
|
|
cache = cache.data; |
|
|
|
let cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
|
|
|
|
if( |
|
|
|
|
|
|
|
cache === null || |
|
|
|
|
|
|
|
cache.data.alpha !== (analyticUnit as AnalyticUnit.AnomalyAnalyticUnit).alpha || |
|
|
|
|
|
|
|
cache.data.confidence !== (analyticUnit as AnalyticUnit.AnomalyAnalyticUnit).confidence |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
await runLearning(analyticUnit.id, from, to); |
|
|
|
|
|
|
|
cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache = cache.data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const analyticUnitType = analyticUnit.type; |
|
|
|
const analyticUnitType = analyticUnit.type; |
|
|
|
const detector = analyticUnit.detectorType; |
|
|
|
const detector = analyticUnit.detectorType; |
|
|
|
const payload = { |
|
|
|
const payload = { |
|
|
|
data: data.values, |
|
|
|
data: data.values, |
|
|
|
analyticUnitType, |
|
|
|
analyticUnitType, |
|
|
|
detector, |
|
|
|
detector, |
|
|
|
cache |
|
|
|
cache |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const processingTask = new AnalyticsTask(analyticUnit.id, AnalyticsTaskType.PROCESS, payload); |
|
|
|
|
|
|
|
const result = await runTask(processingTask); |
|
|
|
|
|
|
|
if(result.status !== AnalyticUnit.AnalyticUnitStatus.SUCCESS) { |
|
|
|
|
|
|
|
throw new Error(`Data processing error: ${result.error}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const processingTask = new AnalyticsTask(analyticUnit.id, AnalyticsTaskType.PROCESS, payload); |
|
|
|
let resultSeries = { |
|
|
|
const result = await runTask(processingTask); |
|
|
|
hsr: data |
|
|
|
if(result.status !== AnalyticUnit.AnalyticUnitStatus.SUCCESS) { |
|
|
|
} |
|
|
|
throw new Error(`Data processing error: ${result.error}`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(result.payload.lowerBound !== undefined) { |
|
|
|
if(result.payload.lowerBound !== undefined) { |
|
|
|
resultSeries['lowerBound'] = { values: result.payload.lowerBound, columns: data.columns }; |
|
|
|
resultSeries['lowerBound'] = { values: result.payload.lowerBound, columns: data.columns }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(result.payload.upperBound !== undefined) { |
|
|
|
if(result.payload.upperBound !== undefined) { |
|
|
|
resultSeries['upperBound'] = { values: result.payload.upperBound, columns: data.columns }; |
|
|
|
resultSeries['upperBound'] = { values: result.payload.upperBound, columns: data.columns }; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return resultSeries; |
|
|
|
return resultSeries; |
|
|
|