Skip to content
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

Endpoint available software updates #2415

Merged
merged 5 commits into from
Mar 19, 2024

Conversation

dottorblaster
Copy link
Contributor

Description

Adding the endpoint to get the available software updates for a given host.

How was this tested?

Automatic tests added

@dottorblaster dottorblaster added the enhancement New feature or request label Mar 13, 2024
@dottorblaster dottorblaster self-assigned this Mar 13, 2024
@dottorblaster dottorblaster force-pushed the endpoint-available-software-updates branch 2 times, most recently from 8e52317 to 8ad1c02 Compare March 13, 2024 14:54
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a first round of review, well done.
We need to keep iterating tho, mainly in the result aggregation step and more thorough testing.

Keep it up!

lib/trento/software_updates/discovery/gen.ex Show resolved Hide resolved
test/support/factory.ex Show resolved Hide resolved
lib/trento_web/controllers/v1/suse_manager_controller.ex Outdated Show resolved Hide resolved
def show(conn, %{id: host_id}) do
{:ok, system_id} = SoftwareUpdates.Discovery.get_system_id(host_id)
{:ok, relevant_patches} = SoftwareUpdates.Discovery.get_relevant_patches(system_id)
{:ok, upgradable_packages} = SoftwareUpdates.Discovery.get_upgradable_packages(system_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see room for a more robust behaviour

  • if host_id provided in the request is not one of the hosts in trento, we should get a 404
  • given the host id we need to get the relevant fqdn to get the system id. fqdn might not be there, tho
  • if we can't get a system id, because of suma failure, we do not try anything else and we should get a meaningful error (422? 503?)
  • if we can get only one between relevant patches or upgradable packages, because the other fails, we could still return a partial result. But I can live also with making the whole request fail, as long as we return something meaningful

I also would encapsulate that aggregation logic in Trento.SoftwareUpdates.
Let's also add tests for failing scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nelsonkopliku can relate. I was actually planning to returning an empty list but this would be very silent in terms of error handling and I wouldn't like that because in the end a user might have 0 upgradable packages when actually behind the scenes it's just a failing call.

So: I like your proposal, but what do you think about an FQDN that still isn't there? Still not found?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have the host given its id, but that host does not have an fqdn, maybe a 422 could work as well. It'd be consistent with what we often do.

If we return 404 in that case, it'd be great to know whether it is because the host is not in trento or because the host does not have an fqdn.

lib/trento_web/router.ex Outdated Show resolved Hide resolved
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

I guess we just need a tiny fine tune in error handling and moving aggregation logic in the relevant context. Then we're good to merge 👍

]

@spec software_updates(Plug.Conn.t(), any) :: Plug.Conn.t()
def software_updates(conn, %{id: host_id}) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A failing get_relevant_patches or get_upgradable_packages would lead to our endpoint returning a generic 500 internal_server_error.

A more graceful 422, let's say, with something like unable to retrieve software updates would give a clearer information to a client.

This aggregation logic also would perfectly fit in Trento.SoftwareUpdates, in a new function like get_host_updates/1 expecting a host id.

Copy link
Contributor

@jamie-suse jamie-suse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I only have a question about the absence of the from_arch & to_arch fields for upgradable packages but otherwise looks good

@dottorblaster
Copy link
Contributor Author

@jamie-suse in the end we decided not to include those right now because they are not in the struct that the documentation shows, also I don't think we need them since we have the arch field 👍

@dottorblaster
Copy link
Contributor Author

@nelsonkopliku I updated the fallback controller with the 422s that you requested.

About moving the aggregation from the controller to the SoftwareUpdates context, I wouldn't feel comfortable in having a function inside a given context that uses functions (like the host id fetching) coming from another context (namely Trento.Hosts).

What do you think?

@nelsonkopliku
Copy link
Member

nelsonkopliku commented Mar 18, 2024

Not sure I understand what doesn't make you feel comfortable.
If you look at what we do in Trento.Charts for instance, it's the same.

EDIT: also Trento.Discovery using Trento.{Clusters, SapSystems} and many other cross context usage of structs as well.

@dottorblaster
Copy link
Contributor Author

@nelsonkopliku I just applied the changes. 👍

@dottorblaster dottorblaster force-pushed the endpoint-available-software-updates branch from aa2be1c to 4a05833 Compare March 18, 2024 13:19
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I was expecting to have relevant tests in Trento.SoftwareUpdates.SettingsTest 😅 .
But let's not make this go too long.

LGTM. Let's see how all the things wire up together 🚀

lib/trento/software_updates.ex Outdated Show resolved Hide resolved
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@dottorblaster dottorblaster merged commit 10495ef into main Mar 19, 2024
24 checks passed
@dottorblaster dottorblaster deleted the endpoint-available-software-updates branch March 19, 2024 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

3 participants