diff --git a/server/extension/sql/105_route_between_points.sql b/server/extension/sql/105_route_between_points.sql index 24fc7ea..e6cede3 100644 --- a/server/extension/sql/105_route_between_points.sql +++ b/server/extension/sql/105_route_between_points.sql @@ -19,7 +19,7 @@ RETURNS cdb_dataservices_server.simple_route AS $$ logger_config = GD["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): waypoints = [origin, destination] @@ -61,7 +61,7 @@ RETURNS cdb_dataservices_server.simple_route AS $$ logger_config = GD["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): if user_routing_config.mapzen_provider: diff --git a/server/extension/sql/20_geocode_street.sql b/server/extension/sql/20_geocode_street.sql index 642f8e1..30155a1 100644 --- a/server/extension/sql/20_geocode_street.sql +++ b/server/extension/sql/20_geocode_street.sql @@ -12,7 +12,7 @@ RETURNS Geometry AS $$ logger_config = GD["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): if user_geocoder_config.heremaps_geocoder: diff --git a/server/extension/sql/21_bulk_geocode_street.sql b/server/extension/sql/21_bulk_geocode_street.sql index f6d085b..934abe3 100644 --- a/server/extension/sql/21_bulk_geocode_street.sql +++ b/server/extension/sql/21_bulk_geocode_street.sql @@ -20,7 +20,7 @@ RETURNS SETOF cdb_dataservices_server.geocoding AS $$ logger_config = GD["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): if user_geocoder_config.google_geocoder: diff --git a/server/extension/sql/30_admin0.sql b/server/extension/sql/30_admin0.sql index a1f3496..6e670ab 100644 --- a/server/extension/sql/30_admin0.sql +++ b/server/extension/sql/30_admin0.sql @@ -14,7 +14,10 @@ RETURNS Geometry AS $$ logger_config = GD["logger_config"] logger = Logger(logger_config) 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: plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"]) rv = plpy.execute(plan, [country_name], 1) diff --git a/server/extension/sql/40_admin1.sql b/server/extension/sql/40_admin1.sql index daa381b..99e28b4 100644 --- a/server/extension/sql/40_admin1.sql +++ b/server/extension/sql/40_admin1.sql @@ -16,7 +16,9 @@ RETURNS Geometry AS $$ logger = Logger(logger_config) 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: plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"]) rv = plpy.execute(plan, [admin1_name], 1) diff --git a/server/extension/sql/50_namedplaces.sql b/server/extension/sql/50_namedplaces.sql index 14975b5..07a18f0 100644 --- a/server/extension/sql/50_namedplaces.sql +++ b/server/extension/sql/50_namedplaces.sql @@ -14,8 +14,8 @@ RETURNS Geometry AS $$ except spiexceptions.ExternalRoutineException as e: import sys 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"]) - return plpy.execute(internal_plan, [username, orgname, city_name])[0]['point'] + 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, appname, city_name])[0]['point'] $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; ---- cdb_geocode_namedplace_point(city_name text, country_name text) @@ -29,13 +29,13 @@ RETURNS Geometry AS $$ logger = Logger(logger_config) 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"]) - return plpy.execute(street_point, [username, orgname, city_name, country_name])[0]['point'] + 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, appname, city_name, country_name])[0]['point'] except spiexceptions.ExternalRoutineException as e: import sys 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"]) - return plpy.execute(internal_plan, [username, orgname, city_name, country_name])[0]['point'] + 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, appname, city_name, country_name])[0]['point'] $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; ---- cdb_geocode_namedplace_point(city_name text, admin1_name text, country_name text) @@ -49,16 +49,16 @@ RETURNS Geometry AS $$ logger = Logger(logger_config) 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"]) - return plpy.execute(street_point, [username, orgname, city_name, admin1_name, country_name])[0]['point'] + 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, appname, city_name, admin1_name, country_name])[0]['point'] except spiexceptions.ExternalRoutineException as e: import sys 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"]) - return plpy.execute(internal_plan, [username, orgname, city_name, admin1_name, country_name])[0]['point'] + 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, appname, city_name, admin1_name, country_name])[0]['point'] $$ 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 $$ from cartodb_services.metrics import QuotaService from cartodb_services.metrics import InternalGeocoderConfig, metrics @@ -74,7 +74,9 @@ RETURNS Geometry AS $$ logger = Logger(logger_config) 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: 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"]) diff --git a/server/extension/sql/60_postalcodes.sql b/server/extension/sql/60_postalcodes.sql index f40f807..8390e71 100644 --- a/server/extension/sql/60_postalcodes.sql +++ b/server/extension/sql/60_postalcodes.sql @@ -14,7 +14,10 @@ RETURNS Geometry AS $$ logger_config = GD["logger_config"] logger = Logger(logger_config) 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: plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"]) rv = plpy.execute(plan, [code], 1) diff --git a/server/extension/sql/70_ips.sql b/server/extension/sql/70_ips.sql index 97f935c..7eb16e3 100644 --- a/server/extension/sql/70_ips.sql +++ b/server/extension/sql/70_ips.sql @@ -14,6 +14,9 @@ RETURNS Geometry AS $$ logger_config = GD["logger_config"] logger = Logger(logger_config) 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): try: plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"]) diff --git a/server/extension/sql/85_isodistance.sql b/server/extension/sql/85_isodistance.sql index bbce02e..3fb7feb 100644 --- a/server/extension/sql/85_isodistance.sql +++ b/server/extension/sql/85_isodistance.sql @@ -14,7 +14,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ if user_isolines_config.google_services_user: 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): if user_isolines_config.heremaps_provider: diff --git a/server/extension/sql/90_isochrone.sql b/server/extension/sql/90_isochrone.sql index 725cf85..5a06268 100644 --- a/server/extension/sql/90_isochrone.sql +++ b/server/extension/sql/90_isochrone.sql @@ -14,7 +14,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ if user_isolines_config.google_services_user: 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): if user_isolines_config.heremaps_provider: