-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: master
Are you sure you want to change the base?
Conversation
This allows querying of the host results, which can be used in the UI or otherwise.
There was a problem hiding this 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.
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]); |
There was a problem hiding this comment.
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}`);
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
andhandleSuccess
Hope it helps
const STATUS_ICONS = { | ||
'ok': 'pficon-ok status-ok', | ||
'warning': 'pficon-info status-warn', | ||
'critical': 'pficon-error-circle-o status-error', | ||
} |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}` });
};
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 |
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? |
There was a problem hiding this 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!
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.