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

Add managed field in Cluster resources #2366

Merged
merged 31 commits into from
Mar 5, 2024
Merged

Add managed field in Cluster resources #2366

merged 31 commits into from
Mar 5, 2024

Conversation

rtorrero
Copy link
Contributor

@rtorrero rtorrero commented Feb 26, 2024

Description

This PR adds:

  • The managed field for all resources in the clusters API
  • The managed column in the cluster resources (node details) view
  • An 'unmanaged' counter as a tooltip on the site details table
  • Small refactor of existing code to adapt the API for v1 (adapt_v1 function)

Frontend Preview:

Checkout storybook "Unmanaged Node Resources"

Add count of unmanaged resources when a node is online but has unmanaged resources

image

Add Managed column in Node details view

image

How was this tested?

  • Updated existing frontend tests
  • Added cypress test to check tooltip message
  • Updated view tests for API backwards compatibility
  • Updated existing policy tests to include managed field

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Some initial comments.
PD: Add UT tests for the frontend and e2e if possible

@@ -715,6 +716,9 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
end)
end

defp parse_managed(%{managed: true}), do: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't be better to include managed as required field in the payload and here simply passing that value, as we would always heve it?

@@ -20,7 +20,8 @@ defmodule TrentoWeb.OpenApi.V1.Schema.Cluster do
type: %Schema{type: :string},
role: %Schema{type: :string},
status: %Schema{type: :string},
fail_count: %Schema{type: :integer}
fail_count: %Schema{type: :integer},
managed: %Schema{type: :boolean}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to include this field in the v1.
We want to include it in the v2.
In fact, we need to remove it in the v1 in the view code

@@ -450,7 +450,8 @@ defmodule Trento.Factory do
id: Faker.Pokemon.name(),
role: "Stopped",
status: Faker.Pokemon.name(),
type: "ocf::heartbeat:Dummy"
type: "ocf::heartbeat:Dummy",
managed: Enum.random([false, true])
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a good moment to create the cluster_resource factory and use it.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this change. Here what you need to do is to use the factory itself

assets/js/pages/ClusterDetails/AttributesDetails.jsx Outdated Show resolved Hide resolved
assets/js/pages/ClusterDetails/AttributesDetails.jsx Outdated Show resolved Hide resolved
assets/js/pages/ClusterDetails/AttributesDetails.jsx Outdated Show resolved Hide resolved
@EMaksy EMaksy force-pushed the resource-managed branch 2 times, most recently from 45a0207 to 25438ca Compare February 27, 2024 09:54
@EMaksy EMaksy self-assigned this Feb 27, 2024
@EMaksy EMaksy added enhancement New feature or request javascript Pull requests that update Javascript code elixir Pull requests that update Elixir code labels Feb 27, 2024
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Hey @EMaksy
Some comments. We need to rethink some new things you did

assets/js/pages/ClusterDetails/AttributesDetails.jsx Outdated Show resolved Hide resolved
assets/js/pages/ClusterDetails/ClusterNodeName.jsx Outdated Show resolved Hide resolved
assets/js/pages/ClusterDetails/ClusterNodeName.jsx Outdated Show resolved Hide resolved
@EMaksy EMaksy force-pushed the resource-managed branch from 2cc6ad7 to 8cc7b33 Compare March 1, 2024 10:22
@EMaksy EMaksy force-pushed the resource-managed branch from 4ee353d to eba43d2 Compare March 1, 2024 15:51
@rtorrero rtorrero marked this pull request as ready for review March 1, 2024 16:39
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

@rtorrero @EMaksy
The backend part is ready for me. I did some comments, and I think it could be improved, but well, at least it is correct.
@EMaksy The frontend part could get some additional work

|> Map.put(:stopped_resources, adapt_resources(stopped_resources))
end

defp adapt_details(%{nodes: nodes} = details) do
Copy link
Contributor

Choose a reason for hiding this comment

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

@rtorrero Is this new entry needed?
I mean, the stopped_resources would be always there, so adapt_resources would return an empty list in any case.
Or do I miss something?
If you remove this, you could remove the adapt_nodes function as it is used only in one place, and we don't want to hide a simple Enum.map into a function

end

defp adapt_node(node) do
adapted_resources = adapt_resources(node[:resources] || [])
Copy link
Contributor

Choose a reason for hiding this comment

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

@rtorrero Mostly the same here. Is it not the resources field always coming?
You could get it in the function signature, and not use this ugly thing.
If it is compulsory, use Map.get(node, :resources, []) at least

@@ -450,7 +450,8 @@ defmodule Trento.Factory do
id: Faker.Pokemon.name(),
role: "Stopped",
status: Faker.Pokemon.name(),
type: "ocf::heartbeat:Dummy"
type: "ocf::heartbeat:Dummy",
managed: Enum.random([false, true])
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this change. Here what you need to do is to use the factory itself

@@ -40,6 +41,14 @@ defmodule TrentoWeb.V1.ClusterViewTest do
refute Access.get(node, :nameserver_actual_role)
refute Access.get(node, :indexserver_actual_role)
refute Access.get(node, :status)

Enum.each(details.stopped_resources, fn stopped_resource ->
refute Map.has_key?(stopped_resource, :managed)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not Access.get here? Just for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

couldn't Access.get return a falsy boolean? (causing the test to pass when it shouldn't)

A Map.has_key? seems also semantically more correct to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was more about consistency, not having Access above and Map.has_key? here.
I would be fine having has_key? in both.
Anyway, it was a detail

assets/js/pages/ClusterDetails/AttributesDetails.jsx Outdated Show resolved Hide resolved
},
{
status: 'Online',
resources: [{ managed: true }, { managed: false }],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use the clusterResourceFactory here

@@ -177,3 +192,10 @@ export const WithRunningExecution = {
lastExecution: { data: checksExecutionRunningFactory.build() },
},
};

export const WithUnmanagedResources = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really nice with the Host currently not registered, but hey...

assets/js/pages/ClusterDetails/HanaClusterDetails.test.jsx Outdated Show resolved Hide resolved
test/e2e/cypress/e2e/hana_cluster_details.cy.js Outdated Show resolved Hide resolved
@EMaksy EMaksy force-pushed the resource-managed branch 3 times, most recently from e782f8e to aa047e9 Compare March 4, 2024 21:43
expectedResource.forEach(({ key, title }) => {
expect(screen.getByText(title)).toBeInTheDocument();
resources.forEach((resource) => {
let value;
Copy link
Member

Choose a reason for hiding this comment

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

I put a let instead of const, as otherwise eslint complains about nested ternary operator. Maybe there is a better way ?

{ attributes: hanaClusterAttributes, resources: hanaClusterResources },
] = hanaClusterDetailsNodesFactory.buildList(1);

const scenarios = [
Copy link
Member

Choose a reason for hiding this comment

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

Any more ideas for additional scenarios?

Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Thank you @EMaksy @rtorrero
Ready to merge from my side 🚀

@EMaksy EMaksy force-pushed the resource-managed branch from 36f4cbc to e8626fa Compare March 5, 2024 09:02
@EMaksy EMaksy merged commit 8d0ff11 into main Mar 5, 2024
24 checks passed
@EMaksy EMaksy deleted the resource-managed branch March 5, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elixir Pull requests that update Elixir code enhancement New feature or request javascript Pull requests that update Javascript code
Development

Successfully merging this pull request may close these issues.

3 participants