Browse Source

Data kit error status code 400 #300 (#711)

pull/1/head
Evgeny Smyshlyaev 5 years ago committed by GitHub
parent
commit
7f8597636d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      server/src/controllers/analytics_controller.ts
  2. 4
      server/src/routes/detections_router.ts
  3. 12
      server/src/services/data_puller.ts

11
server/src/controllers/analytics_controller.ts

@ -75,15 +75,6 @@ async function onPushDetect(detectionResult: DetectionResult) {
} catch(err) {
console.error(`error while sending webhook: ${err.message}`);
}
} else {
let reasons = [];
if(!analyticUnit.alert) {
reasons.push('alerting disabled');
}
if(_.isEmpty(detectionResult.segments)) {
reasons.push('segments empty');
}
console.log(`skip sending webhook for ${analyticUnit.id}, ${reasons.join(', ')}`);
}
await onDetect(detectionResult);
}
@ -377,7 +368,7 @@ export async function runDetect(id: AnalyticUnit.AnalyticUnitId, from?: number,
await Promise.all([
Segment.insertSegments(payload.segments),
AnalyticUnitCache.setData(id, payload.cache),
AnalyticUnit.setDetectionTime(id, payload.lastDetectionTime),
AnalyticUnit.setDetectionTime(id, range.to - intersection),
]);
await AnalyticUnit.setStatus(id, AnalyticUnit.AnalyticUnitStatus.READY);
await Detection.insertSpan(

4
server/src/routes/detections_router.ts

@ -24,6 +24,10 @@ export async function getDetectionSpans(ctx: Router.IRouterContext) {
throw new Error(`to is missing or corrupted (got ${ctx.request.query.to})`);
}
if(from >= to) {
throw new Error(`'from' timestamp ${from} must be less than 'to' timestamp ${to}`);
}
let response: DetectionSpansResponse = { spans: [] };
// TODO: invalidate
response.spans = await AnalyticsController.getDetectionSpans(id, from, to);

12
server/src/services/data_puller.ts

@ -94,8 +94,7 @@ export class DataPuller {
private async _runAnalyticUnitPuller(analyticUnit: AnalyticUnit.AnalyticUnit) {
console.log(`run data puller for analytic unit ${analyticUnit.id}`);
// TODO: lastDetectionTime can be in ns
const time = analyticUnit.lastDetectionTime + 1 || Date.now();
const time = Date.now();
this._unitTimes[analyticUnit.id] = time;
const dataGenerator = this.getDataGenerator(
@ -150,6 +149,15 @@ export class DataPuller {
throw new Error(`Analytic unit ${analyticUnit.id} is deleted from puller`);
}
const now = Date.now();
if(time >= now) {
// TODO: probably we should have ability to set PULL_PERIOD_MS or get it from metric as time step between points
return {
columns: [],
values: []
};
}
const res = await this.pullData(analyticUnit, time, now);
this._grafanaAvailableConsoleReporter(true);
this.alertService.sendGrafanaAvailableWebhook();

Loading…
Cancel
Save