Browse Source

feat(debug): debugging info for interpolation service

pull/1128/merge
Peter Johnson 6 years ago
parent
commit
fa8257cd06
  1. 6
      middleware/interpolate.js
  2. 8
      service/configurations/Interpolation.js

6
middleware/interpolate.js

@ -3,6 +3,8 @@ const logger = require( 'pelias-logger' ).get( 'api' );
const source_mapping = require('../helper/type_mapping').source_mapping; const source_mapping = require('../helper/type_mapping').source_mapping;
const _ = require('lodash'); const _ = require('lodash');
const stable = require('stable'); const stable = require('stable');
const Debug = require('../helper/debug');
const debugLog = new Debug('middleware:interpolate');
/** /**
example response from interpolation web service: example response from interpolation web service:
@ -57,6 +59,7 @@ function setup(service, should_execute) {
// perform interpolations asynchronously for all relevant hits // perform interpolations asynchronously for all relevant hits
const start = (new Date()).getTime(); const start = (new Date()).getTime();
const initialTime = debugLog.beginTimer(req);
logger.info(`[interpolation] [street_results] count=${street_results.length}`); logger.info(`[interpolation] [street_results] count=${street_results.length}`);
@ -71,12 +74,14 @@ function setup(service, should_execute) {
// note: leave this hit unmodified // note: leave this hit unmodified
if (!_.has(interpolation_result, 'properties')) { if (!_.has(interpolation_result, 'properties')) {
logger.debug(`[interpolation] [miss] ${req.clean.parsed_text}`); logger.debug(`[interpolation] [miss] ${req.clean.parsed_text}`);
debugLog.push(req, 'miss');
return; return;
} }
// the interpolation service returned a valid result, debug log for posterity // the interpolation service returned a valid result, debug log for posterity
// note: we now merge those values with the existing 'street' record // note: we now merge those values with the existing 'street' record
logger.debug(`[interpolation] [hit] ${req.clean.parsed_text} ${JSON.stringify(interpolation_result)}`); logger.debug(`[interpolation] [hit] ${req.clean.parsed_text} ${JSON.stringify(interpolation_result)}`);
debugLog.push(req, interpolation_result);
// -- metadata -- // -- metadata --
source_result.layer = 'address'; source_result.layer = 'address';
@ -126,6 +131,7 @@ function setup(service, should_execute) {
// log the execution time, continue // log the execution time, continue
logger.info( `[interpolation] [took] ${(new Date()).getTime() - start} ms`); logger.info( `[interpolation] [took] ${(new Date()).getTime() - start} ms`);
debugLog.stopTimer(req, initialTime);
next(); next();
}); });

8
service/configurations/Interpolation.js

@ -1,6 +1,7 @@
const url = require('url'); const url = require('url');
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('interpolation:request');
const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration; const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfiguration;
@ -10,13 +11,16 @@ class Language extends ServiceConfiguration {
} }
getParameters(req, hit) { getParameters(req, hit) {
return { let params = {
number: req.clean.parsed_text.number, number: req.clean.parsed_text.number,
street: hit.address_parts.street || req.clean.parsed_text.street, street: hit.address_parts.street || req.clean.parsed_text.street,
lat: hit.center_point.lat, lat: hit.center_point.lat,
lon: hit.center_point.lon lon: hit.center_point.lon
}; };
debugLog.push(req, params);
return params;
} }
getUrl(req) { getUrl(req) {

Loading…
Cancel
Save