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

UI: Expose hooks that retrieve the highest alerts for each entity #3275

Conversation

ChengYanJin
Copy link
Contributor

@ChengYanJin ChengYanJin commented Apr 7, 2021

Component: ui, alerts

Context:
Provide hooks to fetch the highest severity alerts for each entity to display the health.

 useNodesAlert(): Alert?
 useVolumesAlert(): Alert?
 useServiceAlert(): Alert?
 useNetworkAlert(): Alert?
 getNodesCountQuery(): Query // type Query = {cacheKey, queryFn, options} from react-query
 getVolumesCountQuery(): Query // type Query = {cacheKey, queryFn, options} from react-query

Summary:

const nodesAlerts = useHighestSeverityAlerts(getNodesAlertName());
const volumesAlerts = useHighestSeverityAlerts(getVolumesAlertName());
const volumesAlerts = useHighestSeverityAlerts(getNetworksAlertName());
const volumesAlerts = useHighestSeverityAlerts(getServicesAlertName());
const coutNodes = getNodesCountQuery();
const coutVolumes = getVolumesCountQuery();

As discussed with @JBWatenbergScality, we will eventually remove the AlertProvider from Metalk8s UI.

Acceptance criteria:


Closes: #3257

@bert-e
Copy link
Contributor

bert-e commented Apr 7, 2021

Hello chengyanjin,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Status report is not available.

@bert-e
Copy link
Contributor

bert-e commented Apr 7, 2021

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • one peer

Peer approvals must include at least 1 approval from the following list:

@ChengYanJin ChengYanJin changed the title UI: Expose hooks that retrieve the highest alerts for each entity or alertname UI: Expose hooks that retrieve the highest alerts for each entity Apr 7, 2021
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch 3 times, most recently from 98932fd to 8847337 Compare April 8, 2021 07:30
@ChengYanJin ChengYanJin marked this pull request as ready for review April 8, 2021 07:36
@ChengYanJin ChengYanJin requested a review from a team as a code owner April 8, 2021 07:36
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch 2 times, most recently from abefd0d to 223c978 Compare April 8, 2021 07:57
ui/src/services/alertHooks.js Outdated Show resolved Hide resolved
ui/src/containers/AlertProvider.js Outdated Show resolved Hide resolved
ui/src/services/alertHooks.js Outdated Show resolved Hide resolved
ui/src/services/alertHooks.js Outdated Show resolved Hide resolved
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch 6 times, most recently from b32f9c6 to 1940c5f Compare April 14, 2021 10:19
@ChengYanJin ChengYanJin changed the base branch from development/2.9 to improvement/shell-ui-alert-provider April 14, 2021 10:20
ChengYanJin added a commit that referenced this pull request Apr 14, 2021
Check if the k8s call carry the id_token, othewise listen to the
navbarElement AUTHENTICATED event

Refs: #3275
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch from 1940c5f to c35493f Compare April 14, 2021 10:22
ChengYanJin added a commit that referenced this pull request Apr 14, 2021
Check if the k8s call carry the `id_token`, otherwise listen to the
navbarElement AUTHENTICATED_EVENT

Refs: #3275
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch from c35493f to 92ec079 Compare April 14, 2021 10:25
@JBWatenbergScality JBWatenbergScality force-pushed the improvement/shell-ui-alert-provider branch from 0625ea3 to 741b8fb Compare April 14, 2021 19:07
ChengYanJin added a commit that referenced this pull request Apr 14, 2021
Check if the k8s call carry the `id_token`, otherwise listen to the
navbarElement AUTHENTICATED_EVENT

Refs: #3275
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch from 92ec079 to bcfa1a0 Compare April 14, 2021 19:33
Check if the k8s call carry the `id_token`, otherwise listen to the
navbarElement AUTHENTICATED_EVENT

Refs: #3275
@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch from bcfa1a0 to 1878730 Compare April 14, 2021 19:36
.then((res) => {
return res.items.length;
}),
options: { refetchInterval: 10000 },
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 it is missing enabled options :

Suggested change
options: { refetchInterval: 10000 },
options: { refetchInterval: 10000, enabled: token },

this will only triggers the query if the token is provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I've checked the doc, the enabled is a boolean, so maybe the following one is more correct
options: { refetchInterval: 10000, enabled: token ? true : false },

Copy link
Contributor

Choose a reason for hiding this comment

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

JS is automatically casting this to a boolean so token ? true : false is strictly equivalent to token. Actually in token ? true : false you are also casting token as a boolean for the ternary condition

Copy link
Contributor Author

@ChengYanJin ChengYanJin Apr 15, 2021

Choose a reason for hiding this comment

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

For some reason, the tests won't execute by enabled: token. So I have to switch back to enabled: token ? true : false

shell-ui/src/platform/service/k8s.js Outdated Show resolved Hide resolved
shell-ui/src/platform/service/k8s.js Outdated Show resolved Hide resolved
shell-ui/src/platform/service/k8s.js Outdated Show resolved Hide resolved
shell-ui/src/platform/service/k8s.js Show resolved Hide resolved
shell-ui/src/platform/service/k8s.js Show resolved Hide resolved
Copy link
Contributor

@JBWatenbergScality JBWatenbergScality left a comment

Choose a reason for hiding this comment

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

@JBWatenbergScality JBWatenbergScality dismissed their stale review April 14, 2021 20:28

incorrect approval

@JBWatenbergScality
Copy link
Contributor

Cannot find module 'axios' from 'src/platform/service/k8s.js'

Axios is not available in shell-ui. I think we can simply use fetch as it is available in the browser we target

@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch 2 times, most recently from d90bd0e to d6a94e3 Compare April 15, 2021 08:21
@JBWatenbergScality
Copy link
Contributor

I think you can merge this manually in my branch improvement/shell-ui-alert-provider

.then((res) => {
return res.items.length;
}),
options: { refetchInterval: 10000, enabled: token },
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure about this options to be checked

@ChengYanJin ChengYanJin force-pushed the improvement/3257-hooks-to-export-the-health-of-the-entities branch from d6a94e3 to 586e812 Compare April 15, 2021 15:45
To disable the query if token is not provided

Refs: #3257
@ChengYanJin ChengYanJin merged commit 01f46e6 into improvement/shell-ui-alert-provider Apr 15, 2021
@ChengYanJin ChengYanJin deleted the improvement/3257-hooks-to-export-the-health-of-the-entities branch April 15, 2021 19:11
JBWatenbergScality pushed a commit that referenced this pull request Apr 16, 2021
Check if the k8s call carry the `id_token`, otherwise listen to the
navbarElement AUTHENTICATED_EVENT

Refs: #3275
JBWatenbergScality pushed a commit that referenced this pull request Apr 16, 2021
Check if the k8s call carry the `id_token`, otherwise listen to the
navbarElement AUTHENTICATED_EVENT

Refs: #3275
ChengYanJin added a commit that referenced this pull request Apr 20, 2021
Check if the k8s call carry the `id_token`, otherwise listen to the
navbarElement AUTHENTICATED_EVENT

Refs: #3275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI: Implements hooks to retrieve the health of entities(Volume/Node/Service/Network)
3 participants