Skip to content

Commit

Permalink
ARTESCA-1828: Add global health bar
Browse files Browse the repository at this point in the history
Refs: #3471
  • Loading branch information
theocerutti committed Aug 26, 2021
1 parent 0705cb1 commit 580e734
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 115 deletions.
198 changes: 94 additions & 104 deletions ui/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@fortawesome/react-fontawesome": "^0.1.14",
"@kubernetes/client-node": "github:scality/kubernetes-client-javascript.git#browser-0.10.2-63-g579d066",
"@scality/module-federation": "github:scality/module-federation.git#1.0.0",
"@scality/core-ui": "github:scality/core-ui.git#v0.19.3",
"@scality/core-ui": "github:scality/core-ui.git#bugfix/update-the-color-of-global-health-component-with-the-design",
"axios": "^0.21.1",
"formik": "2.2.5",
"jest-environment-jsdom-sixteen": "^1.0.3",
Expand Down Expand Up @@ -39,7 +39,7 @@
"uuid": "3.3.2",
"vega": "^5.17.3",
"vega-embed": "^6.0.0",
"vega-lite": "^4.17.0",
"vega-lite": "^5.0.0",
"yup": "^0.32.9"
},
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions ui/public/.well-known/runtime-app-configuration
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"url_grafana": "/grafana",
"url_doc": "/docs",
"url_alertmanager": "/api/alertmanager",
"url_loki": "/api/loki",
"flags": [],
"ui_base_path":"/",
"url_support": "https://github.com/scality/metalk8s/discussions/new"
Expand Down
1 change: 1 addition & 0 deletions ui/public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"url_grafana": "/grafana",
"url_doc": "/docs",
"url_alertmanager": "/api/alertmanager",
"url_loki": "/api/loki",
"flags": [],
"url_navbar": "/shell/solution-ui-navbar.1.0.0.js",
"url_alerts": "/shell/alerts.1.0.0.js",
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/DashboardGlobalHealth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import styled from 'styled-components';
import { spacing } from '@scality/core-ui/dist/style/theme';
import DashboardAlerts from './DashboardAlerts';
import DashboardHealthBar from './DashboardHealthBar';

const GlobalHealthContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -31,7 +32,9 @@ const GlobalHealthContainer = styled.div`
const DashboardGlobalHealth = () => {
return (
<GlobalHealthContainer>
<div className="healthbar">GlobalHealth</div>
<div className="healthbar">
<DashboardHealthBar />
</div>
<div className="alerts">
<DashboardAlerts />
</div>
Expand Down
122 changes: 122 additions & 0 deletions ui/src/components/DashboardHealthBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import React, { useCallback } from 'react';
import { GlobalHealthBar, Tooltip, Loader } from '@scality/core-ui';
import styled from 'styled-components';
import { useIntl } from 'react-intl';
import { spacing } from '@scality/core-ui/dist/style/theme';
import { getAlertsLoki, isLokiReady } from '../services/loki/api';
import { useQuery } from 'react-query';
import { REFRESH_GLOBAL_HEALTH_BAR } from '../constants';
import { useMetricsTimeSpan } from '../hooks';
import {
highestAlertToStatus,
useAlertLibrary,
useHighestSeverityAlerts,
} from '../containers/AlertProvider';

const GlobalHealthContainer = styled.div`
display: flex;
flex-direction: column;
`;

const TitleContainer = styled.div`
display: flex;
& > div {
margin-right: ${spacing.sp16};
}
i {
color: ${(props) => props.theme.buttonSecondary};
}
`;

const HealthCircle = styled.div`
height: ${(props) => props.size};
width: ${(props) => props.size};
background-color: ${(props) =>
props.theme[
'status' + props.variant.replace(/^\w/, (c) => c.toUpperCase())
]};
border-radius: 50%;
display: inline-block;
`;

const DashboardHealthBar = () => {
const intl = useIntl();
const alertsLibrary = useAlertLibrary();
const platformAlerts = useHighestSeverityAlerts(
alertsLibrary.getPlatformAlertSelectors(),
);
const [metricsTimeSpan] = useMetricsTimeSpan();
const start = new Date(
new Date().getTime() - metricsTimeSpan * 1000,
).toISOString();
const end = new Date().toISOString();

const { data, isLoading } = useQuery(
['dashboardHealthBar', metricsTimeSpan],
useCallback(async () => {
if (await isLokiReady()) return getAlertsLoki(start, end);
else return [];
// Can't add start/end to dependencies because these dates are modified on every render
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [metricsTimeSpan]),
{
refetchOnMount: false,
refetchOnWindowFocus: false,
refetchInterval: REFRESH_GLOBAL_HEALTH_BAR,
refetchIntervalInBackground: true,
},
);

return (
<GlobalHealthContainer>
<TitleContainer>
<div>{intl.formatMessage({ id: 'global_health' })}</div>
<Tooltip
overlay={
<div style={{ width: '300px' }}>
The Global Health is the overall status of your Platform over a
specific period.
<br />
<br />
The statuses of the Volumes and Nodes, the Network and the
Services are monitored.
<br />
<br />
<HealthCircle size={spacing.sp8} variant="healthy" /> OK, the
Platform is healthy.
<br />
<HealthCircle size={spacing.sp8} variant="warning" /> Warning, the
Platform is degraded but not at risk.
<br />
<HealthCircle size={spacing.sp8} variant="critical" /> Critical
status, the Platform is degraded and at risk.
<br />
<br />
Hover or click on an alert segment on the Global Health bar for
more details.
</div>
}
placement="bottom"
>
<i className="fas fa-question-circle" />
</Tooltip>
<HealthCircle
size={spacing.sp16}
variant={highestAlertToStatus(platformAlerts)}
/>
</TitleContainer>
{isLoading && !data ? (
<Loader />
) : (
<GlobalHealthBar
id={'dashboard-global-health-bar'}
alerts={data}
start={start}
end={end}
/>
)}
</GlobalHealthContainer>
);
};

export default DashboardHealthBar;
7 changes: 4 additions & 3 deletions ui/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@flow
export const REFRESH_TIMEOUT = 15000;
export const REFRESH_METRICS_GRAPH = 60000;
export const REFRESH_GLOBAL_HEALTH_BAR = 300000;
export const FR_LANG = 'FR';
export const EN_LANG = 'EN';
export const LANGUAGE = 'language';
Expand Down Expand Up @@ -127,7 +128,7 @@ export const lineColor4 = '#C6B38A';

// Grafana dashboard UIDs (for stable links)
export const GRAFANA_DASHBOARDS = {
logs: "a7e130cb82be229d6f3edbfd0a438001",
nodes: "node-exporter-full",
volumes: "919b92a8e8041bd567af9edab12c840c",
logs: 'a7e130cb82be229d6f3edbfd0a438001',
nodes: 'node-exporter-full',
volumes: '919b92a8e8041bd567af9edab12c840c',
};
4 changes: 2 additions & 2 deletions ui/src/containers/AlertProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
ComponentWithFederatedImports,
FederatedComponent,
} from '@scality/module-federation';
import { STATUS_HEALTH } from '../constants';
import { STATUS_HEALTH, STATUS_WARNING, STATUS_CRITICAL } from '../constants';

export type Status = 'healthy' | 'warning' | 'critical';
export type Status = STATUS_HEALTH | STATUS_WARNING | STATUS_CRITICAL;

const alertGlobal = {};
export const useAlerts = (filters: FilterLabels) => {
Expand Down
1 change: 1 addition & 0 deletions ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"prometheus_unavailable": "Prometheus is unavailable",
"down": "Down",
"alerts": "Alerts",
"global_health": "Global Health",
"node_creation": "Node creation",
"node_creation_success": "Node {name} has been created successfully.",
"node_creation_failed": "Node {name} creation has failed.",
Expand Down
1 change: 1 addition & 0 deletions ui/src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"prometheus_unavailable": "Prometheus n'est pas disponible",
"down": "H.S",
"alerts": "Alertes",
"global_health": "Santé Globale",
"node_creation": "Création du nœud",
"node_creation_success": "Le nœud {name} a été créé avec succèss",
"node_creation_failed": "La création du nœud {name} a échoué.",
Expand Down
6 changes: 3 additions & 3 deletions ui/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ module.exports = (env) => ({
*/
performance: {
hints: 'error',
// ~732 KiB for production
// ~4.06 MiB for development because flow increase the size of assets.
maxAssetSize: process.env.NODE_ENV === 'production' ? 750000 : 5000000,
// ~3,24 MiB for production
// ~10,49 MiB for development because flow increase the size of assets.
maxAssetSize: process.env.NODE_ENV === 'production' ? 3400000 : 11000000,
assetFilter: (assetFilename) => {
return (
!assetFilename.endsWith('.map.gz') && assetFilename.endsWith('.gz')
Expand Down

0 comments on commit 580e734

Please sign in to comment.