Skip to content

Commit

Permalink
[Stack Monitoring] Convert node roles into array (#167628)
Browse files Browse the repository at this point in the history
## πŸ““ Summary

When the `elasticsearch.node.roles` property is set to a single role,
the API returns a single string instead of a list, failing when
computing the role list client side and resulting in an empty list.

This fix is to parse the node roles into a list if the API returns a
single role string and correctly displays the roles.

E.g. Assuming we have the following roles configuration
```
[
      {
        "_source": {
          "elasticsearch": {
            "node": {
              "roles": [
                "data",
                "master"
              ]
            }
          }
        }
      },
      {
        "_source": {
          "elasticsearch": {
            "node": {
              "roles": "master"
            }
          }
        }
      }
    ]

```

It would fail at parsing the second node roles and fall back into the
"coordinating only" default.

<img width="814" alt="Screenshot 2023-09-29 at 13 05 14"
src="https://github.com/elastic/kibana/assets/34506779/bf49a974-650a-44cc-827b-b3dc834d6cee">

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
  • Loading branch information
tonyghiani and Marco Antonio Ghiani committed Oct 4, 2023
1 parent 7baab02 commit a69957e
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -186,15 +186,17 @@ export const ElasticsearchNodesPage: React.FC<ComponentProps> = ({ clusters }) =
);
};

function sortNodeRoles(roles: string[] | undefined): string[] | undefined {
function sortNodeRoles(roles: string[] | string | undefined): string[] | undefined {
if (!roles) {
return undefined;
}

if (roles.length === 0) {
const rolesList = Array.isArray(roles) ? roles : [roles];

if (rolesList.length === 0) {
return [];
}

const rolesAsSet = new Set(roles);
const rolesAsSet = new Set(rolesList);
return rolesByImportance.filter((role) => rolesAsSet.has(role));
}

0 comments on commit a69957e

Please sign in to comment.