|
|
|
@ -631,44 +631,10 @@ export async function getHSR(
|
|
|
|
|
try { |
|
|
|
|
const grafanaUrl = getGrafanaUrl(analyticUnit.grafanaUrl); |
|
|
|
|
const data = await queryByMetric(analyticUnit.metric, grafanaUrl, from, to, HASTIC_API_KEY); |
|
|
|
|
let resultSeries = { |
|
|
|
|
hsr: data |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(analyticUnit.detectorType === AnalyticUnit.DetectorType.THRESHOLD) { |
|
|
|
|
let cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
|
if( |
|
|
|
|
cache === null || |
|
|
|
|
cache.data.alpha !== (analyticUnit as AnalyticUnit.ThresholdAnalyticUnit).value || |
|
|
|
|
cache.data.confidence !== (analyticUnit as AnalyticUnit.ThresholdAnalyticUnit).condition |
|
|
|
|
) { |
|
|
|
|
await runLearning(analyticUnit.id, from, to); |
|
|
|
|
cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
|
if(analyticUnit.detectorType !== AnalyticUnit.DetectorType.ANOMALY) { |
|
|
|
|
return { hsr: data }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
let cache = await AnalyticUnitCache.findById(analyticUnit.id); |
|
|
|
|
if( |
|
|
|
|
cache === null || |
|
|
|
@ -696,6 +662,10 @@ export async function getHSR(
|
|
|
|
|
throw new Error(`Data processing error: ${result.error}`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let resultSeries = { |
|
|
|
|
hsr: data |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(result.payload.lowerBound !== undefined) { |
|
|
|
|
resultSeries['lowerBound'] = { values: result.payload.lowerBound, columns: data.columns }; |
|
|
|
|
} |
|
|
|
@ -703,7 +673,6 @@ export async function getHSR(
|
|
|
|
|
if(result.payload.upperBound !== undefined) { |
|
|
|
|
resultSeries['upperBound'] = { values: result.payload.upperBound, columns: data.columns }; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return resultSeries; |
|
|
|
|
} catch (err) { |
|
|
|
|