Added metrics

This commit is contained in:
antoniocarlon 2018-09-06 13:47:50 +02:00
parent 04a5a25d06
commit 603d691017
10 changed files with 34 additions and 21 deletions

View File

@ -19,7 +19,7 @@ RETURNS cdb_dataservices_server.simple_route AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
params = {'origin': origin, 'destination': destination, 'mode': mode, 'options': options, 'units': units} params = {'username': username, 'orgname': orgname, 'appname': appname, 'origin': origin, 'destination': destination, 'mode': mode, 'options': options, 'units': units}
with metrics('cdb_route_with_point', user_routing_config, logger, params): with metrics('cdb_route_with_point', user_routing_config, logger, params):
waypoints = [origin, destination] waypoints = [origin, destination]
@ -61,7 +61,7 @@ RETURNS cdb_dataservices_server.simple_route AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
params = {'waypoints': waypoints, 'mode': mode, 'options': options, 'units': units} params = {'username': username, 'orgname': orgname, 'appname': appname, 'waypoints': waypoints, 'mode': mode, 'options': options, 'units': units}
with metrics('cdb_route_with_waypoints', user_routing_config, logger, params): with metrics('cdb_route_with_waypoints', user_routing_config, logger, params):
if user_routing_config.mapzen_provider: if user_routing_config.mapzen_provider:

View File

@ -12,7 +12,7 @@ RETURNS Geometry AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
params = {'searchtext': searchtext, 'city': city, 'state_province': state_province, 'country': country} params = {'username': username, 'orgname': orgname, 'appname': appname, 'searchtext': searchtext, 'city': city, 'state_province': state_province, 'country': country}
with metrics('cdb_geocode_street_point', user_geocoder_config, logger, params): with metrics('cdb_geocode_street_point', user_geocoder_config, logger, params):
if user_geocoder_config.heremaps_geocoder: if user_geocoder_config.heremaps_geocoder:

View File

@ -20,7 +20,7 @@ RETURNS SETOF cdb_dataservices_server.geocoding AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
params = {'searches': searches} params = {'username': username, 'orgname': orgname, 'appname': appname, 'searches': searches}
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params): with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
if user_geocoder_config.google_geocoder: if user_geocoder_config.google_geocoder:

View File

@ -14,7 +14,10 @@ RETURNS Geometry AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
quota_service = QuotaService(user_geocoder_config, redis_conn) quota_service = QuotaService(user_geocoder_config, redis_conn)
with metrics('cdb_geocode_admin0_polygon', user_geocoder_config, logger):
params = {'username': username, 'orgname': orgname, 'appname': appname, 'country_name': country_name}
with metrics('cdb_geocode_admin0_polygon', user_geocoder_config, logger, params):
try: try:
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"]) plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"])
rv = plpy.execute(plan, [country_name], 1) rv = plpy.execute(plan, [country_name], 1)

View File

@ -16,7 +16,9 @@ RETURNS Geometry AS $$
logger = Logger(logger_config) logger = Logger(logger_config)
quota_service = QuotaService(user_geocoder_config, redis_conn) quota_service = QuotaService(user_geocoder_config, redis_conn)
with metrics('cdb_geocode_admin1_polygon', user_geocoder_config, logger): params = {'username': username, 'orgname': orgname, 'appname': appname, 'admin1_name': admin1_name}
with metrics('cdb_geocode_admin1_polygon', user_geocoder_config, logger, params):
try: try:
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"]) plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"])
rv = plpy.execute(plan, [admin1_name], 1) rv = plpy.execute(plan, [admin1_name], 1)

View File

@ -14,8 +14,8 @@ RETURNS Geometry AS $$
except spiexceptions.ExternalRoutineException as e: except spiexceptions.ExternalRoutineException as e:
import sys import sys
logger.error('Error geocoding namedplace using geocode street point, falling back to internal geocoder', sys.exc_info(), data={"username": username, "orgname": orgname}) logger.error('Error geocoding namedplace using geocode street point, falling back to internal geocoder', sys.exc_info(), data={"username": username, "orgname": orgname})
internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3) as point;", ["text", "text", "text"]) internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, $4) as point;", ["text", "text", "text", "text"])
return plpy.execute(internal_plan, [username, orgname, city_name])[0]['point'] return plpy.execute(internal_plan, [username, orgname, appname, city_name])[0]['point']
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
---- cdb_geocode_namedplace_point(city_name text, country_name text) ---- cdb_geocode_namedplace_point(city_name text, country_name text)
@ -29,13 +29,13 @@ RETURNS Geometry AS $$
logger = Logger(logger_config) logger = Logger(logger_config)
try: try:
street_point = plpy.prepare("SELECT cdb_dataservices_server.cdb_geocode_street_point($1, $2, $3, NULL, NULL, $4) as point;", ["text", "text", "text", "text"]) street_point = plpy.prepare("SELECT cdb_dataservices_server.cdb_geocode_street_point($1, $2, $3, $4, NULL, NULL, $5) as point;", ["text", "text", "text", "text", "text"])
return plpy.execute(street_point, [username, orgname, city_name, country_name])[0]['point'] return plpy.execute(street_point, [username, orgname, appname, city_name, country_name])[0]['point']
except spiexceptions.ExternalRoutineException as e: except spiexceptions.ExternalRoutineException as e:
import sys import sys
logger.error('Error geocoding namedplace using geocode street point, falling back to internal geocoder', sys.exc_info(), data={"username": username, "orgname": orgname}) logger.error('Error geocoding namedplace using geocode street point, falling back to internal geocoder', sys.exc_info(), data={"username": username, "orgname": orgname})
internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, NULL, $4) as point;", ["text", "text", "text", "text"]) internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, $4, NULL, $5) as point;", ["text", "text", "text", "text", "text"])
return plpy.execute(internal_plan, [username, orgname, city_name, country_name])[0]['point'] return plpy.execute(internal_plan, [username, orgname, appname, city_name, country_name])[0]['point']
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) ---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text)
@ -49,16 +49,16 @@ RETURNS Geometry AS $$
logger = Logger(logger_config) logger = Logger(logger_config)
try: try:
street_point = plpy.prepare("SELECT cdb_dataservices_server.cdb_geocode_street_point($1, $2, $3, NULL, $4, $5) as point;", ["text", "text", "text", "text", "text"]) street_point = plpy.prepare("SELECT cdb_dataservices_server.cdb_geocode_street_point($1, $2, $3, $4, NULL, $5, $6) as point;", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(street_point, [username, orgname, city_name, admin1_name, country_name])[0]['point'] return plpy.execute(street_point, [username, orgname, appname, city_name, admin1_name, country_name])[0]['point']
except spiexceptions.ExternalRoutineException as e: except spiexceptions.ExternalRoutineException as e:
import sys import sys
logger.error('Error geocoding namedplace using geocode street point, falling back to internal geocoder', sys.exc_info(), data={"username": username, "orgname": orgname}) logger.error('Error geocoding namedplace using geocode street point, falling back to internal geocoder', sys.exc_info(), data={"username": username, "orgname": orgname})
internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, $4, $5) as point;", ["text", "text", "text", "text", "text"]) internal_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_internal_geocode_namedplace($1, $2, $3, $4, $5, $6) as point;", ["text", "text", "text", "text", "text", "text"])
return plpy.execute(internal_plan, [username, orgname, city_name, admin1_name, country_name])[0]['point'] return plpy.execute(internal_plan, [username, orgname, appname, city_name, admin1_name, country_name])[0]['point']
$$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED;
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_internal_geocode_namedplace(username text, orgname text, city_name text, admin1_name text DEFAULT NULL, country_name text DEFAULT NULL) CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_internal_geocode_namedplace(username text, orgname text, appname text, city_name text, admin1_name text DEFAULT NULL, country_name text DEFAULT NULL)
RETURNS Geometry AS $$ RETURNS Geometry AS $$
from cartodb_services.metrics import QuotaService from cartodb_services.metrics import QuotaService
from cartodb_services.metrics import InternalGeocoderConfig, metrics from cartodb_services.metrics import InternalGeocoderConfig, metrics
@ -74,7 +74,9 @@ RETURNS Geometry AS $$
logger = Logger(logger_config) logger = Logger(logger_config)
quota_service = QuotaService(user_geocoder_config, redis_conn) quota_service = QuotaService(user_geocoder_config, redis_conn)
with metrics('cdb_geocode_namedplace_point', user_geocoder_config, logger): params = {'username': username, 'orgname': orgname, 'appname': appname, 'city_name': city_name, 'admin1_name': admin1_name, 'country_name': country_name}
with metrics('cdb_geocode_namedplace_point', user_geocoder_config, logger, params):
try: try:
if admin1_name and country_name: if admin1_name and country_name:
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2), trim($3)) AS mypoint", ["text", "text", "text"]) plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2), trim($3)) AS mypoint", ["text", "text", "text"])

View File

@ -14,7 +14,10 @@ RETURNS Geometry AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
quota_service = QuotaService(user_geocoder_config, redis_conn) quota_service = QuotaService(user_geocoder_config, redis_conn)
with metrics('cdb_geocode_postalcode_point', user_geocoder_config, logger):
params = {'username': username, 'orgname': orgname, 'appname': appname, 'code': code}
with metrics('cdb_geocode_postalcode_point', user_geocoder_config, logger, params):
try: try:
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"]) plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"])
rv = plpy.execute(plan, [code], 1) rv = plpy.execute(plan, [code], 1)

View File

@ -14,6 +14,9 @@ RETURNS Geometry AS $$
logger_config = GD["logger_config"] logger_config = GD["logger_config"]
logger = Logger(logger_config) logger = Logger(logger_config)
quota_service = QuotaService(user_geocoder_config, redis_conn) quota_service = QuotaService(user_geocoder_config, redis_conn)
params = {'username': username, 'orgname': orgname, 'appname': appname, 'ip': ip}
with metrics('cdb_geocode_ipaddress_point', user_geocoder_config, logger): with metrics('cdb_geocode_ipaddress_point', user_geocoder_config, logger):
try: try:
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"]) plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"])

View File

@ -14,7 +14,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
if user_isolines_config.google_services_user: if user_isolines_config.google_services_user:
raise Exception('This service is not available for google service users.') raise Exception('This service is not available for google service users.')
params = {'source': source, 'mode': mode, 'range': range, 'options': options} params = {'username': username, 'orgname': orgname, 'appname': appname, 'source': source, 'mode': mode, 'range': range, 'options': options}
with metrics('cdb_isodistance', user_isolines_config, logger, params): with metrics('cdb_isodistance', user_isolines_config, logger, params):
if user_isolines_config.heremaps_provider: if user_isolines_config.heremaps_provider:

View File

@ -14,7 +14,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
if user_isolines_config.google_services_user: if user_isolines_config.google_services_user:
raise Exception('This service is not available for google service users.') raise Exception('This service is not available for google service users.')
params = {'source': source, 'mode': mode, 'range': range, 'options': options} params = {'username': username, 'orgname': orgname, 'appname': appname, 'source': source, 'mode': mode, 'range': range, 'options': options}
with metrics('cdb_isochrone', user_isolines_config, logger, params): with metrics('cdb_isochrone', user_isolines_config, logger, params):
if user_isolines_config.heremaps_provider: if user_isolines_config.heremaps_provider: