From a69957e0fc821b9644a70df2a57ccb672fd71001 Mon Sep 17 00:00:00 2001 From: Marco Antonio Ghiani Date: Wed, 4 Oct 2023 10:50:07 +0200 Subject: [PATCH] [Stack Monitoring] Convert node roles into array (#167628) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📓 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. Screenshot 2023-09-29 at 13 05 14 Co-authored-by: Marco Antonio Ghiani --- .../public/application/pages/elasticsearch/nodes_page.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/monitoring/public/application/pages/elasticsearch/nodes_page.tsx b/x-pack/plugins/monitoring/public/application/pages/elasticsearch/nodes_page.tsx index 75dadbc2f65585..c13682800707a6 100644 --- a/x-pack/plugins/monitoring/public/application/pages/elasticsearch/nodes_page.tsx +++ b/x-pack/plugins/monitoring/public/application/pages/elasticsearch/nodes_page.tsx @@ -186,15 +186,17 @@ export const ElasticsearchNodesPage: React.FC = ({ 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)); }