Browse Source

improve logging (#344)

improve analytic's logging about incoming task, logging on server side about incoming detection results
pull/1/head
Evgeny Smyshlyaev 6 years ago committed by GitHub
parent
commit
54137d5f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      analytics/bin/server
  2. 10
      server/src/controllers/analytics_controller.ts

10
analytics/bin/server

@ -40,24 +40,24 @@ root.addHandler(logging_handler)
async def handle_task(task: object): async def handle_task(task: object):
try: try:
task_type = task['type']
logger.info("Command is OK") logger.info("Got {} task with id {}, analyticUnitId {}".format(task_type, task['_id'], task['analyticUnitId']))
task_result_payload = { task_result_payload = {
'_id': task['_id'], '_id': task['_id'],
'task': task['type'], 'task': task_type,
'analyticUnitId': task['analyticUnitId'], 'analyticUnitId': task['analyticUnitId'],
'status': "IN_PROGRESS" 'status': "IN_PROGRESS"
} }
if not task['type'] == 'PUSH': if not task_type == 'PUSH':
message = services.server_service.ServerMessage('TASK_RESULT', task_result_payload) message = services.server_service.ServerMessage('TASK_RESULT', task_result_payload)
await server_service.send_message(message) await server_service.send_message(message)
res = await analytic_unit_manager.handle_analytic_task(task) res = await analytic_unit_manager.handle_analytic_task(task)
res['_id'] = task['_id'] res['_id'] = task['_id']
if not task['type'] == 'PUSH': if not task_type == 'PUSH':
message = services.server_service.ServerMessage('TASK_RESULT', res) message = services.server_service.ServerMessage('TASK_RESULT', res)
await server_service.send_message(message) await server_service.send_message(message)

10
server/src/controllers/analytics_controller.ts

@ -299,6 +299,7 @@ async function processDetectionResult(analyticUnitId: AnalyticUnit.AnalyticUnitI
`Missing lastDetectionTime in result or it is corrupted: ${JSON.stringify(detectionResult)}` `Missing lastDetectionTime in result or it is corrupted: ${JSON.stringify(detectionResult)}`
); );
} }
console.debug(`got detection result with ${detectionResult.segments.length} segments`);
const segments = detectionResult.segments.map( const segments = detectionResult.segments.map(
segment => new Segment.Segment(analyticUnitId, segment.from, segment.to, false, false) segment => new Segment.Segment(analyticUnitId, segment.from, segment.to, false, false)
@ -311,7 +312,14 @@ async function processDetectionResult(analyticUnitId: AnalyticUnit.AnalyticUnitI
console.error(`error while sending webhook: ${err.message}`); console.error(`error while sending webhook: ${err.message}`);
} }
} else { } else {
console.debug(`skip sending webhook for ${analyticUnitId}`); let reasons = [];
if(!analyticUnit.alert) {
reasons.push('alerting disabled');
}
if(_.isEmpty(segments)) {
reasons.push('segments empty');
}
console.debug(`skip sending webhook for ${analyticUnit.id}, ${reasons.join(', ')}`);
} }
return { return {
lastDetectionTime: detectionResult.lastDetectionTime, lastDetectionTime: detectionResult.lastDetectionTime,

Loading…
Cancel
Save