From 443c1f67fd9156175a8dcc27dcbee676f716d312 Mon Sep 17 00:00:00 2001 From: ikethecoder Date: Mon, 29 Nov 2021 21:52:38 -0800 Subject: [PATCH 1/3] add generic exception logging --- microservices/gatewayApi/app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microservices/gatewayApi/app.py b/microservices/gatewayApi/app.py index 0789987..1726229 100644 --- a/microservices/gatewayApi/app.py +++ b/microservices/gatewayApi/app.py @@ -113,6 +113,12 @@ def expired_token(error): content = jsonify({"error":"Token Expired"}) return make_response(content, HTTPStatus.UNAUTHORIZED) + @app.errorhandler(Exception) + def other_exception(error): + log.error(error) + content = jsonify({"error":"Unexpected Error"}) + return make_response(content, HTTPStatus.BAD_REQUEST) + @app.route('/', methods=['GET'], strict_slashes=False) def index(): """ From 29a9730d89b40c1898b3b39a65e5eb39c460ca8f Mon Sep 17 00:00:00 2001 From: ikethecoder Date: Mon, 29 Nov 2021 21:52:57 -0800 Subject: [PATCH 2/3] add some logging to the namespace v1 api --- microservices/gatewayApi/v1/routes/namespaces.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/microservices/gatewayApi/v1/routes/namespaces.py b/microservices/gatewayApi/v1/routes/namespaces.py index e2faeb5..e0906b4 100644 --- a/microservices/gatewayApi/v1/routes/namespaces.py +++ b/microservices/gatewayApi/v1/routes/namespaces.py @@ -71,10 +71,13 @@ def update_namespace(namespace: str) -> object: log.error("Namespace validation failed %s", namespace) abort(make_response(jsonify(error="Namespace name validation failed. Reference regular expression '%s'." % namespace_validation_rule), 400)) + log.info("Updating namespace %s" % namespace) + try: svc = NamespaceService() ns_group = svc.get_namespace (namespace) + log.info("-> Found %s" % ns_group) svc.update_ns_attributes (ns_group, params) From 1cd535eba6441bcd13021a6db07a02e141fb7cb3 Mon Sep 17 00:00:00 2001 From: Nithin Shekar Kuruba Date: Tue, 30 Nov 2021 13:13:39 -0800 Subject: [PATCH 3/3] updated get_routes function to support paging and fetch all the routes --- microservices/gatewayJobScheduler/main.py | 30 ++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/microservices/gatewayJobScheduler/main.py b/microservices/gatewayJobScheduler/main.py index e0b4f92..9809e3c 100644 --- a/microservices/gatewayJobScheduler/main.py +++ b/microservices/gatewayJobScheduler/main.py @@ -40,17 +40,26 @@ def get_namespace_attributes(self, namespace): def get_routes(): try: - p1 = Popen(shlex.split("curl %s/routes" % os.getenv('KONG_ADMIN_API_URL')), stdout=PIPE) - run = Popen(shlex.split( - "jq '.data'"), stdin=p1.stdout, stdout=PIPE, stderr=PIPE) - out, err = run.communicate() + endpoint = "/routes" + routes_list = [] + while True: + p1 = Popen(shlex.split("curl %s%s" % (os.getenv('KONG_ADMIN_API_URL'), endpoint)), stdout=PIPE) + run = Popen(shlex.split( + "jq ."), stdin=p1.stdout, stdout=PIPE, stderr=PIPE) + out, err = run.communicate() + + if run.returncode != 0: + logger.error("Failed to get existing routes - %s - %s", out, err) + clear('sync-routes') + exit(1) + + result = json.loads(out) + routes_list = routes_list + result['data'] + + if result['next'] == None: + return routes_list + endpoint = result['next'] - if run.returncode != 0: - logger.error("Failed to get existing routes - %s - %s", out, err) - clear('sync-routes') - exit(1) - - return json.loads(out) except: traceback.print_exc() logger.error('Failed to get existing routes - %s' % (exc_info()[0])) @@ -66,7 +75,6 @@ def sync_routes(): 'content-type': 'application/json' } data = transform_data_by_ns(get_routes()) - for ns in data: url = os.getenv('KUBE_API_URL') + '/namespaces/%s/routes/sync' % ns response = requests.post(url, headers=headers, json=data[ns], auth=(