mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Stack Monitoring] Convert node roles into array (#167628)
## 📓 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="bf49a974
-650a-44cc-827b-b3dc834d6cee">
Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
This commit is contained in:
parent
7baab02533
commit
a69957e0fc
1 changed files with 5 additions and 3 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue