From ec3b99f2580ad5377c036b154663995356b1863f Mon Sep 17 00:00:00 2001 From: piensaenpixel Date: Wed, 11 Jan 2017 12:43:51 +0100 Subject: [PATCH 1/5] Update quota_information.md --- doc/quota_information.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/quota_information.md b/doc/quota_information.md index 3607542..e7bca4a 100644 --- a/doc/quota_information.md +++ b/doc/quota_information.md @@ -56,7 +56,7 @@ SELECT * FROM cdb_service_quota_info(); Result: -``` +```sql service | monthly_quota | used_quota | soft_limit | provider ----------------+---------------+------------+------------+------------------ isolines | 100 | 0 | f | mapzen @@ -102,7 +102,7 @@ SELECT COUNT(*) FROM {tablename} WHERE {street_name_column} IS NOT NULL; Result: here's a sample result of 10000 records: -``` +```sql count ------- 10000 @@ -118,7 +118,7 @@ SELECT cdb_enough_quota('hires_geocoder', {number_of_records}); The result is similar to the following: -``` +```sql cdb_enough_quota ------------------ t From 435a84f294e7d90e92dc33929b891f9bb4efdf85 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Mon, 6 Feb 2017 10:44:02 +0100 Subject: [PATCH 2/5] OBS_GetData functions shall increase the DO quota usage --- NEWS.md | 6 +++++ ...db_dataservices_server--0.20.0--0.21.0.sql | 22 +++++++++++++++++++ .../cdb_dataservices_server--0.21.0.sql | 22 +++++++++++++++++++ .../sql/110_data_observatory_augmentation.sql | 22 +++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/NEWS.md b/NEWS.md index c3b9bb0..78f590f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +February 2st, 2017 +=================== +* Version 0.21.0 of the server and version 0.15.0 of the client + * Added functions `OBS_GetData` and `OBS_GetMeta` + * Default isolines provider changed to `mapzen` instead of `heremaps` + November 29st, 2016 =================== * Version 0.20.0 of the server and version 0.12.0 of the python library diff --git a/server/extension/cdb_dataservices_server--0.20.0--0.21.0.sql b/server/extension/cdb_dataservices_server--0.20.0--0.21.0.sql index fc228e1..7f286b9 100644 --- a/server/extension/cdb_dataservices_server--0.20.0--0.21.0.sql +++ b/server/extension/cdb_dataservices_server--0.20.0--0.21.0.sql @@ -28,6 +28,7 @@ RETURNS TABLE ( data JSON ) AS $$ from cartodb_services.metrics import metrics + from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger,LoggerConfig plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) @@ -38,19 +39,29 @@ RETURNS TABLE ( plpy.execute("SELECT cdb_dataservices_server._get_logger_config()") logger_config = GD["logger_config"] logger = Logger(logger_config) + quota_service = QuotaService(user_obs_config, redis_conn) + if not quota_service.check_user_quota(): + raise Exception('You have reached the limit of your quota') with metrics('obs_getdata', user_obs_config, logger): try: obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"]) result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge]) + empty_results = len(geomvals) - len(result) + if empty_results > 0: + quota_service.increment_empty_service_use(empty_results) if result: + quota_service.increment_success_service_use(len(result)) return result else: return None except BaseException as e: import sys + quota_service.increment_failed_service_use(len(geomvals)) logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetData') + finally: + quota_service.increment_total_service_use(len(geomvals)) $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData( @@ -76,6 +87,7 @@ RETURNS TABLE ( data JSON ) AS $$ from cartodb_services.metrics import metrics + from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger,LoggerConfig plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) @@ -86,21 +98,31 @@ RETURNS TABLE ( plpy.execute("SELECT cdb_dataservices_server._get_logger_config()") logger_config = GD["logger_config"] logger = Logger(logger_config) + quota_service = QuotaService(user_obs_config, redis_conn) + if not quota_service.check_user_quota(): + raise Exception('You have reached the limit of your quota') with metrics('obs_getdata', user_obs_config, logger): try: obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"]) result = plpy.execute(obs_plan, [username, orgname, geomrefs, params]) + empty_results = len(geomrefs) - len(result) + if empty_results > 0: + quota_service.increment_empty_service_use(empty_results) if result: + quota_service.increment_success_service_use(len(result)) return result else: return None except BaseException as e: import sys + quota_service.increment_failed_service_use(len(geomrefs)) exc_info = sys.exc_info() logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2])) logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetData') + finally: + quota_service.increment_total_service_use(len(geomrefs)) $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta( diff --git a/server/extension/cdb_dataservices_server--0.21.0.sql b/server/extension/cdb_dataservices_server--0.21.0.sql index b96ef0a..3e714d1 100644 --- a/server/extension/cdb_dataservices_server--0.21.0.sql +++ b/server/extension/cdb_dataservices_server--0.21.0.sql @@ -730,6 +730,7 @@ RETURNS TABLE ( data JSON ) AS $$ from cartodb_services.metrics import metrics + from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger,LoggerConfig plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) @@ -740,19 +741,29 @@ RETURNS TABLE ( plpy.execute("SELECT cdb_dataservices_server._get_logger_config()") logger_config = GD["logger_config"] logger = Logger(logger_config) + quota_service = QuotaService(user_obs_config, redis_conn) + if not quota_service.check_user_quota(): + raise Exception('You have reached the limit of your quota') with metrics('obs_getdata', user_obs_config, logger): try: obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"]) result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge]) + empty_results = len(geomvals) - len(result) + if empty_results > 0: + quota_service.increment_empty_service_use(empty_results) if result: + quota_service.increment_success_service_use(len(result)) return result else: return None except BaseException as e: import sys + quota_service.increment_failed_service_use(len(geomvals)) logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetData') + finally: + quota_service.increment_total_service_use(len(geomvals)) $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData( @@ -778,6 +789,7 @@ RETURNS TABLE ( data JSON ) AS $$ from cartodb_services.metrics import metrics + from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger,LoggerConfig plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) @@ -788,21 +800,31 @@ RETURNS TABLE ( plpy.execute("SELECT cdb_dataservices_server._get_logger_config()") logger_config = GD["logger_config"] logger = Logger(logger_config) + quota_service = QuotaService(user_obs_config, redis_conn) + if not quota_service.check_user_quota(): + raise Exception('You have reached the limit of your quota') with metrics('obs_getdata', user_obs_config, logger): try: obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"]) result = plpy.execute(obs_plan, [username, orgname, geomrefs, params]) + empty_results = len(geomrefs) - len(result) + if empty_results > 0: + quota_service.increment_empty_service_use(empty_results) if result: + quota_service.increment_success_service_use(len(result)) return result else: return None except BaseException as e: import sys + quota_service.increment_failed_service_use(len(geomrefs)) exc_info = sys.exc_info() logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2])) logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetData') + finally: + quota_service.increment_total_service_use(len(geomrefs)) $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta( diff --git a/server/extension/sql/110_data_observatory_augmentation.sql b/server/extension/sql/110_data_observatory_augmentation.sql index a2ca4a2..e578b28 100644 --- a/server/extension/sql/110_data_observatory_augmentation.sql +++ b/server/extension/sql/110_data_observatory_augmentation.sql @@ -593,6 +593,7 @@ RETURNS TABLE ( data JSON ) AS $$ from cartodb_services.metrics import metrics + from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger,LoggerConfig plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) @@ -603,19 +604,29 @@ RETURNS TABLE ( plpy.execute("SELECT cdb_dataservices_server._get_logger_config()") logger_config = GD["logger_config"] logger = Logger(logger_config) + quota_service = QuotaService(user_obs_config, redis_conn) + if not quota_service.check_user_quota(): + raise Exception('You have reached the limit of your quota') with metrics('obs_getdata', user_obs_config, logger): try: obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"]) result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge]) + empty_results = len(geomvals) - len(result) + if empty_results > 0: + quota_service.increment_empty_service_use(empty_results) if result: + quota_service.increment_success_service_use(len(result)) return result else: return None except BaseException as e: import sys + quota_service.increment_failed_service_use(len(geomvals)) logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetData') + finally: + quota_service.increment_total_service_use(len(geomvals)) $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData( @@ -641,6 +652,7 @@ RETURNS TABLE ( data JSON ) AS $$ from cartodb_services.metrics import metrics + from cartodb_services.metrics import QuotaService from cartodb_services.tools import Logger,LoggerConfig plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) @@ -651,21 +663,31 @@ RETURNS TABLE ( plpy.execute("SELECT cdb_dataservices_server._get_logger_config()") logger_config = GD["logger_config"] logger = Logger(logger_config) + quota_service = QuotaService(user_obs_config, redis_conn) + if not quota_service.check_user_quota(): + raise Exception('You have reached the limit of your quota') with metrics('obs_getdata', user_obs_config, logger): try: obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"]) result = plpy.execute(obs_plan, [username, orgname, geomrefs, params]) + empty_results = len(geomrefs) - len(result) + if empty_results > 0: + quota_service.increment_empty_service_use(empty_results) if result: + quota_service.increment_success_service_use(len(result)) return result else: return None except BaseException as e: import sys + quota_service.increment_failed_service_use(len(geomrefs)) exc_info = sys.exc_info() logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2])) logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname}) raise Exception('Error trying to OBS_GetData') + finally: + quota_service.increment_total_service_use(len(geomrefs)) $$ LANGUAGE plpythonu; CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta( From 64c24628a03dfa95e74385a1de5bdd09da5f34a2 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Tue, 28 Feb 2017 12:16:14 +0100 Subject: [PATCH 3/5] Stop using git:// protocol ## Context `https://` protocol [is prefered](https://help.github.com/articles/which-remote-url-should-i-use/#cloning-with-https-urls-recommended), plus using `git://` is messier in terms of permissions. Please consider changing your guide. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5e6636..221ad12 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Steps to deploy a new Data Services API version : - install data services geocoder extension ``` - git clone git@github.com:CartoDB/data-services.git + git clone https://github.com/CartoDB/data-services.git cd data-services/geocoder/extension sudo make install ``` @@ -34,7 +34,7 @@ Steps to deploy a new Data Services API version : - install observatory extension ``` - git clone git@github.com:CartoDB/observatory-extension.git + git clone https://github.com/CartoDB/observatory-extension.git cd observatory sudo make install ``` From dde86e985c61f7e7c332d4ee0e8aa3811f7d3530 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Tue, 28 Feb 2017 12:41:27 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 221ad12..db0fecd 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Steps to deploy a new Data Services API version : - install server and client extensions ``` + # in data-services repo root path: cd client && sudo make install cd server/extension && sudo make install ``` @@ -49,7 +50,8 @@ Steps to deploy a new Data Services API version : - install python library ``` - cd server/lib/python/cartodb_services && sudo pip install --upgrade . + # in data-services repo root path: + cd server/lib/python/cartodb_services && sudo pip install -r requirements.txt --upgrade . ``` - install extensions in user database From 457858a49088f27d16f89c6afa397d270fd5bba8 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Tue, 28 Feb 2017 18:24:19 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db0fecd..a9df9fe 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Steps to deploy a new Data Services API version : ``` # in data-services repo root path: - cd server/lib/python/cartodb_services && sudo pip install -r requirements.txt --upgrade . + cd server/lib/python/cartodb_services && sudo pip install . --upgrade ``` - install extensions in user database