-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service cleanup #184
base: master
Are you sure you want to change the base?
Service cleanup #184
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ async def version(self, request): | |
tags: | ||
- Admin | ||
produces: | ||
- 'text/plain' | ||
- text/plain | ||
responses: | ||
"200": | ||
description: successful operation. Return the version number | ||
|
@@ -46,7 +46,7 @@ async def ping(self, request): | |
tags: | ||
- Admin | ||
produces: | ||
- 'text/plain' | ||
- text/plain | ||
responses: | ||
"202": | ||
description: successful operation. Return "pong" text | ||
|
@@ -64,7 +64,7 @@ async def healthcheck(self, request): | |
tags: | ||
- Admin | ||
produces: | ||
- 'application/json' | ||
- application/json | ||
responses: | ||
"202": | ||
description: successful operation. | ||
|
@@ -96,11 +96,11 @@ async def healthcheck(self, request): | |
async def get_authorization_token(self, request): | ||
""" | ||
--- | ||
description: this is used exclusively for sandbox auth | ||
description: This endpoint is used exclusively for sandbox auth | ||
tags: | ||
- Auth | ||
produces: | ||
- text/plain | ||
- application/json | ||
responses: | ||
"200": | ||
description: successfully returned certs | ||
|
@@ -139,5 +139,5 @@ async def get_authorization_token(self, request): | |
|
||
return web.Response(status=200, body=json.dumps(credentials)) | ||
except Exception as ex: | ||
body = {"err_msg": str(ex), "traceback": get_traceback_str()} | ||
body = {"message": str(ex), "traceback": get_traceback_str()} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the expected body for the authorization route? the http_500 helper only has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am trying to make them all consistent. Still working on it. After I pushed this, I realized I missed af ew things. |
||
return web.Response(status=500, body=json.dumps(body)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from aiohttp import web | ||
from services.data.postgres_async_db import AsyncPostgresDB | ||
from services.data.db_utils import filter_artifacts_by_attempt_id_for_tasks | ||
from services.utils import read_body | ||
from services.data.db_utils import DBResponse, filter_artifacts_by_attempt_id_for_tasks | ||
from services.metadata_service.api.utils import format_response, \ | ||
handle_exceptions | ||
import json | ||
|
@@ -43,12 +42,12 @@ def __init__(self, app): | |
self._async_table = AsyncPostgresDB.get_instance().artifact_table_postgres | ||
self._db = AsyncPostgresDB.get_instance() | ||
|
||
@format_response | ||
@handle_exceptions | ||
@format_response | ||
async def get_artifact(self, request): | ||
""" | ||
--- | ||
description: get all artifacts associated with the specified task. | ||
description: get a specific artifact | ||
tags: | ||
- Artifacts | ||
parameters: | ||
|
@@ -78,10 +77,12 @@ async def get_artifact(self, request): | |
required: true | ||
type: "string" | ||
produces: | ||
- text/plain | ||
- application/json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the comment above. |
||
responses: | ||
"200": | ||
description: successful operation | ||
"404": | ||
description: no such artifact | ||
"405": | ||
description: invalid HTTP Method | ||
""" | ||
|
@@ -95,6 +96,8 @@ async def get_artifact(self, request): | |
flow_name, run_number, step_name, task_id, artifact_name | ||
) | ||
|
||
@handle_exceptions | ||
@format_response | ||
async def get_artifacts_by_task(self, request): | ||
""" | ||
--- | ||
|
@@ -123,7 +126,7 @@ async def get_artifacts_by_task(self, request): | |
required: true | ||
type: "string" | ||
produces: | ||
- text/plain | ||
- application/json | ||
responses: | ||
"200": | ||
description: successful operation | ||
|
@@ -138,17 +141,17 @@ async def get_artifacts_by_task(self, request): | |
artifacts = await self._async_table.get_artifact_in_task( | ||
flow_name, run_number, step_name, task_id | ||
) | ||
if artifacts.response_code == 200: | ||
artifacts.body = filter_artifacts_by_attempt_id_for_tasks( | ||
artifacts.body) | ||
return artifacts | ||
|
||
filtered_body = filter_artifacts_by_attempt_id_for_tasks( | ||
artifacts.body) | ||
return web.Response( | ||
status=artifacts.response_code, body=json.dumps(filtered_body) | ||
) | ||
|
||
@handle_exceptions | ||
@format_response | ||
async def get_artifacts_by_step(self, request): | ||
""" | ||
--- | ||
description: get all artifacts associated with the specified task. | ||
description: get all artifacts associated with a given step | ||
tags: | ||
- Artifacts | ||
parameters: | ||
|
@@ -168,7 +171,7 @@ async def get_artifacts_by_step(self, request): | |
required: true | ||
type: "string" | ||
produces: | ||
- text/plain | ||
- application/json | ||
responses: | ||
"200": | ||
description: successful operation | ||
|
@@ -183,16 +186,17 @@ async def get_artifacts_by_step(self, request): | |
flow_name, run_number, step_name | ||
) | ||
|
||
filtered_body = filter_artifacts_by_attempt_id_for_tasks( | ||
artifacts.body) | ||
return web.Response( | ||
status=artifacts.response_code, body=json.dumps(filtered_body) | ||
) | ||
if artifacts.response_code == 200: | ||
artifacts.body = filter_artifacts_by_attempt_id_for_tasks( | ||
artifacts.body) | ||
return artifacts | ||
|
||
@handle_exceptions | ||
@format_response | ||
async def get_artifacts_by_run(self, request): | ||
""" | ||
--- | ||
description: get all artifacts associated with the specified task. | ||
description: get all artifacts associated with the specified run. | ||
tags: | ||
- Artifacts | ||
parameters: | ||
|
@@ -207,7 +211,7 @@ async def get_artifacts_by_run(self, request): | |
required: true | ||
type: "string" | ||
produces: | ||
- text/plain | ||
- application/json | ||
responses: | ||
"200": | ||
description: successful operation | ||
|
@@ -218,16 +222,18 @@ async def get_artifacts_by_run(self, request): | |
run_number = request.match_info.get("run_number") | ||
|
||
artifacts = await self._async_table.get_artifacts_in_runs(flow_name, run_number) | ||
filtered_body = filter_artifacts_by_attempt_id_for_tasks( | ||
artifacts.body) | ||
return web.Response( | ||
status=artifacts.response_code, body=json.dumps(filtered_body) | ||
) | ||
|
||
if artifacts.response_code == 200: | ||
artifacts.body = filter_artifacts_by_attempt_id_for_tasks( | ||
artifacts.body) | ||
return artifacts | ||
|
||
@handle_exceptions | ||
@format_response | ||
async def create_artifacts(self, request): | ||
""" | ||
--- | ||
description: This end-point allow to test that service is up. | ||
description: Registers artifacts with the service | ||
tags: | ||
- Artifacts | ||
parameters: | ||
|
@@ -277,7 +283,7 @@ async def create_artifacts(self, request): | |
system_tags: | ||
type: object | ||
produces: | ||
- 'text/plain' | ||
- application/json | ||
responses: | ||
"202": | ||
description: successful operation. | ||
|
@@ -306,16 +312,18 @@ async def create_artifacts(self, request): | |
run_number = request.match_info.get("run_number") | ||
step_name = request.match_info.get("step_name") | ||
task_id = request.match_info.get("task_id") | ||
body = await read_body(request.content) | ||
body = await request.json() | ||
count = 0 | ||
|
||
try: | ||
run_number, run_id = await self._db.get_run_ids(flow_name, run_number) | ||
task_id, task_name = await self._db.get_task_ids(flow_name, run_number, | ||
step_name, task_id) | ||
except Exception: | ||
return web.Response(status=400, body=json.dumps( | ||
{"message": "need to register run_id and task_id first"})) | ||
run = await self._db.get_run_ids(flow_name, run_number) | ||
task = await self._db.get_task_ids(flow_name, run_number, | ||
step_name, task_id) | ||
if run.response_code != 200 or task.response_code != 200: | ||
return DBResponse(400, {"message": "need to register run_id and task_id first"}) | ||
Comment on lines
+318
to
+322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more generic thought and not a blocker for merging the cleanup, but is there a reason why this kind of integrity check is not covered by a foreign key constraint in the table? also affects the metadata create handler There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is covered I think; the issue is that it used to be silent (ie: the db would raise the error but it could silently make it through. |
||
run_id = run.body['run_id'] | ||
run_number = run.body['run_number'] | ||
task_id = task.body['task_id'] | ||
task_name = task.body['task_name'] | ||
|
||
# todo change to bulk insert | ||
for artifact in body: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified that this change wouldn't affect the sandbox? We have a similar issue where the
heartbeat
endpoint returns an actual JSON but is tagged astext/plain
which has caused issues in the metaflow codebase before.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to rework things and push a PR to make it so that everything works on application/json. I will also check with Ferras if there was a reason for the string only implementation.