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 a monitoring tab on the modern host details page #94

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Dec 22, 2023

This first introduces a REST API to get the monitoring results for a host. That is then shown as a tab on the host details page.

I debated a card in the details tab, but this leaves space for more complex items, such as downtime selection.

Some review needs to be done on the exact representation. I chose for a simple table, but perhaps we want to show more columns that also indicates downtime and acknowledgements.

This allows querying of the host results, which can be used in the UI or
otherwise.
@ekohl ekohl linked an issue Dec 22, 2023 that may be closed by this pull request
@ekohl ekohl mentioned this pull request Dec 22, 2023
Copy link
Member

@Ron-Lavi Ron-Lavi left a comment

Choose a reason for hiding this comment

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

Nice work @ekohl!
I left a couple of suggestions.

Comment on lines 33 to 58
const dispatch = useDispatch();
const API_KEY = `get-monitoring-results-{hostId}`;
const status = useSelector(state => selectAPIStatus(state, API_KEY));
const { results, itemCount, response } = useSelector(state =>
selectAPIResponse(state, API_KEY)
);

const fetchResults = useCallback(
() => {
if (!hostId) return;
dispatch(
get({
key: API_KEY,
url: `/api/hosts/${hostId}/monitoring/results`,
params: {
per_page: 'all',
},
})
);
},
[API_KEY, dispatch, hostId],
);

useEffect(() => {
fetchResults();
}, [fetchResults]);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use useAPI instead?

e.g.:

const {
    response: { results },
    status,
  } = useAPI('get', `/api/hosts/${hostId}/monitoring/results`, `get-monitoring-results-{hostId}`);

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied it from #94 so I wonder why that doesn't use useAPI.

Copy link
Member Author

Choose a reason for hiding this comment

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

After playing with this for a while I think useAPI is an awkward API if you want to handle the error properly (like display Permission Denied). The response object is suddenly an instance of Error (from axios) that has a property response, which is not obvious.

Speaking of error handling, I wish there was some generic way to show an error.

Copy link
Member

Choose a reason for hiding this comment

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

we are indeed not very consistent across the app,
though basically useAPI came to make things simpler, you can see it's less lines, imports and complexity..
it's implementation is basically what you did here which is also fine.

you can pass to the useAPI some options including:

  • errorToast: callback function that will trigger a toast notification with a message that you can set based on the error. e.g: errorToast: error => error
  • handleError: also a callback that you can choose what to do with.
  • same also for successToast and handleSuccess

Hope it helps

Comment on lines 22 to 26
const STATUS_ICONS = {
'ok': 'pficon-ok status-ok',
'warning': 'pficon-info status-warn',
'critical': 'pficon-error-circle-o status-error',
}
Copy link
Member

Choose a reason for hiding this comment

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

instead of using classnames, can you use the icons from PF4?

import {
  ExclamationTriangleIcon,
  CheckCircleIcon,
  ExclamationCircleIcon,
} from '@patternfly/react-icons';
const STATUS_ICONS = {
  ok: CheckCircleIcon,
  warning: ExclamationTriangleIcon,
  critical: ExclamationCircleIcon,
}

later I believe you can use it this way:

<Td>{STATUS_ICONS[result.status]} {result.status_label}</Td>

Copy link
Member Author

Choose a reason for hiding this comment

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

That is much nicer. My university programming professor would have yelled at me for using hardcoded strings instead of constants.

Copy link
Member Author

Choose a reason for hiding this comment

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

This worked for me:

const STATUS_ICONS = {
  'ok': CheckCircleIcon,
  'warning': ExclamationTriangleIcon,
  'critical': ExclamationCircleIcon,
};

const STATUS_STYLES = {
  'ok': 'ok',
  'warning': 'warn',
  'critical': 'critical',
};

const status_icon = (result_status) => {
  const cls = STATUS_ICONS[result_status] || QuestionCircleIcon;
  const style = STATUS_STYLES[result_status] || 'question';
  return createElement(cls, { className: `status-${style}` });
};

Copy link
Member

Choose a reason for hiding this comment

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

looks good,
do you still need to use the style?

if you do, there's an option to pass the className into the Icon component, so no need for the createElement

Copy link
Member Author

Choose a reason for hiding this comment

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

I certainly needed createElement because the imported item is a class that you need to instantiate.

The style provides a color

@ekohl
Copy link
Member Author

ekohl commented Dec 25, 2023

I appreciate the review. This really was me trying to figure all this stuff out by reading existing code. I'll try to get back to it after the holidays

@sbernhard
Copy link

For which hosts is this shown? I would expect, that it is only shown for monitored hosts?

@ekohl
Copy link
Member Author

ekohl commented Dec 28, 2023

For which hosts is this shown? I would expect, that it is only shown for monitored hosts?

The tab is shown for all hosts, but the table with services is only rendered if there's a monitoring proxy assigned.

@sbernhard
Copy link

For which hosts is this shown? I would expect, that it is only shown for monitored hosts?

The tab is shown for all hosts, but the table with services is only rendered if there's a monitoring proxy assigned.

Would it be possible to hide it for hosts, which are not monitored?

Copy link
Member

@Ron-Lavi Ron-Lavi left a comment

Choose a reason for hiding this comment

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

Thanks @ekohl! thanks for the quick responses, now enjoy your holidays :D Happy new year!

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

Successfully merging this pull request may close these issues.

Compatibility with the new host detail page
3 participants