-
Notifications
You must be signed in to change notification settings - Fork 13
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
Serve the execution results through an endpoint #40
Conversation
04a42f4
to
6832695
Compare
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.
So far so good! I have noted some comments.
Could we add controller tests for the new endpoint?
items_per_page = Map.get(params, :items_per_page, 10) | ||
group_id = Map.get(params, :group_id) | ||
|
||
results = Results.get_execution_results(group_id, page, items_per_page) |
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.
Should we directly send the database representation of the result in the data field here?
I would expect some sort of transformation/mapping to send something more domain related.
I would maybe convert the ExecutionResult
(which is the database mode) to the Result
struct or something new. Something that we really need in the frontend, tailored for it.
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.
we have views for that, i think we can iterate adding the views in a new PR.
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.
@arbulu89 I'm super glad you noticed that, yeah it's something we have to do but I'd like to do that in a follow-up PR because I was afraid this PR was getting really huge
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.
@dottorblaster Fine for me them! We can follow up.
group_id = Map.get(params, :group_id) | ||
|
||
results = Results.get_execution_results(group_id, page, items_per_page) | ||
json(conn, %{page: page, items_per_page: items_per_page, data: results}) |
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 don't really understand why we send back the page
and item_per_page
. They are coming directly from the request, so the user already know them.
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.
+1 to remove them and maybe iterate to add the total count.
See for instance GH APi: https://api.github.com/search/repositories?q=tetris+language:assembly&sort=stars&order=desc&page=1&per_page=10
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.
Can't we take inspiration from HTTP 206 (RFC 9110)?
I like how it proposed to send data on the HTTP header about the position of the served content, see here
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.
Not suggesting do it on the header, just that I like the way it describes the range and total count
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.
Some comments to be addressed and controller tests are missing, we need to test that the return json is in the format we specified in the open API spex.
Refer to this: https://github.com/open-api-spex/open_api_spex#validate-responses
We could use factory to generate a list of results.
@@ -0,0 +1,24 @@ | |||
defmodule WandaWeb.ApiSpec do |
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.
In trento web we faced a similar situation in relation to apis/openapi/openapispex, see here
Let's consider If there's some valuable learning we can bring here - even on what not to do 😅
description: "A single execution of checks", | ||
type: :object, | ||
properties: %{ | ||
execution_id: %Schema{type: :string, description: "Execution ID"}, |
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.
We could add a format: :uuid
to execution_id
and group_id
, for a friendlier representation on the api doc.
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 tried but I got an error, i googled a lot but I didn't find a solution that wasn't "create your own format with a huge regex"
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.
Not talking about validation, no need for regex 😄
Just really a silly thing like we do here for example https://github.com/trento-project/web/blob/main/lib/trento_web/openapi/schema/host.ex#L37
%Schema{type: :string, description: "Execution ID", format: :uuid},
It would take care of giving that information in the swagger ui and it generate uuid samples.
If it is causing troubles feel free to skip.
properties: %{ | ||
execution_id: %Schema{type: :string, description: "Execution ID"}, | ||
group_id: %Schema{type: :string, description: "Group ID"}, | ||
payload: %Schema{type: :object, description: "Payload of the check execution"} |
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.
Probably you already thought of this.
What is the plan about the shape of the payload object
?
As an API consumer, even if at the moment is just us 😄, I would find it useful to know that shape.
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.
Does it have a fixed shape? I thought it was something that can really vary, therefore I didn't want to get stuck writing that schema right now, but it's material for a followup for sure
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.
Well, it does have a shape, and that shape is Wanda.Execution.Result
without :execution_id
and :group_id
.
Does it have a fixed shape? I thought it was something that can really vary
Until we change it 😄
The point to me is more
how stable do we think it is in relation to the needs?
What significant changes do we foresee to that representation in the upcoming iterations?
However, I understand it might be a tedious job, moreover if things change so fast that updating the documentation becomes a burden, yet if that happens there might be another kind of issue to tackle (coupling for instance, but let's leave it out)
Bottom line: if not planned to add that missing piece in this or following PRs, then I'd find it wise to track debt.
How does it sound?
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.
Sounds good, I collected a followup task to better define that shape
d5f1a36
to
8afaf7e
Compare
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.
Hey @dottorblaster ,
It looks good to me now. I have added some other minor comments. But feel free to omit them.
description: "Check execution listing response", | ||
type: :object, | ||
properties: %{ | ||
page: %Schema{type: :string, description: "Current page"}, |
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.
It looks like this got outdated
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.
Damn you're right, thanks
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.
LGTM, please track the debt and the leftovers
e359999
to
7c8cb88
Compare
As above, we're exposing an API to look into historical execution results.