-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Kpi host #35065
Kpi host #35065
Changes from 24 commits
39ae445
5a9863e
d987866
1e103e1
a615768
e670e43
6c808f3
602220a
843760f
7233f65
12371af
f4f2054
0ace461
45c9e57
67bec4d
b9a0cb6
83e473c
ef5cdfd
3d4dc6e
e407178
7e40378
5dae0fa
13bdc92
aae3feb
601b73b
73fd481
a07aaf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiFlexGroup } from '@elastic/eui'; | ||
import { get, getOr } from 'lodash/fp'; | ||
import React from 'react'; | ||
import { pure } from 'recompose'; | ||
import { EuiLoadingSpinner } from '@elastic/eui'; | ||
import { EuiFlexItem } from '@elastic/eui'; | ||
import { KpiHostsData } from '../../../../graphql/types'; | ||
import { | ||
AreaChartData, | ||
BarChartData, | ||
StatItem, | ||
StatItems, | ||
StatItemsComponent, | ||
StatItemsProps, | ||
} from '../../../stat_items'; | ||
import * as i18n from './translations'; | ||
|
||
interface KpiHostsProps { | ||
data: KpiHostsData; | ||
loading: boolean; | ||
} | ||
|
||
const euiColorVis0 = '#00B3A4'; | ||
const euiColorVis1 = '#3185FC'; | ||
const euiColorVis2 = '#DB1374'; | ||
const euiColorVis3 = '#490092'; | ||
const euiColorVis9 = '#920000'; | ||
|
||
const fieldTitleMapping: StatItems[] = [ | ||
{ | ||
fields: [ | ||
{ | ||
key: 'hosts', | ||
value: null, | ||
color: euiColorVis1, | ||
icon: 'storage', | ||
}, | ||
], | ||
enableAreaChart: true, | ||
grow: 2, | ||
description: i18n.HOSTS, | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
key: 'authSuccess', | ||
description: i18n.AUTHENTICATION_SUCCESS, | ||
value: null, | ||
color: euiColorVis0, | ||
icon: 'check', | ||
}, | ||
{ | ||
key: 'authFailure', | ||
description: i18n.AUTHENTICATION_FAILURE, | ||
value: null, | ||
color: euiColorVis9, | ||
icon: 'cross', | ||
}, | ||
], | ||
enableAreaChart: true, | ||
enableBarChart: true, | ||
grow: 4, | ||
description: i18n.AUTHENTICATION, | ||
}, | ||
{ | ||
fields: [ | ||
{ | ||
key: 'uniqueSourceIps', | ||
name: i18n.UNIQUE_SOURCE_IPS_ABBREVIATION, | ||
description: i18n.UNIQUE_SOURCE_IPS, | ||
value: null, | ||
color: euiColorVis2, | ||
icon: 'visMapCoordinate', | ||
}, | ||
{ | ||
key: 'uniqueDestinationIps', | ||
description: i18n.UNIQUE_DESTINATION_IPS, | ||
value: null, | ||
color: euiColorVis3, | ||
icon: 'visMapCoordinate', | ||
}, | ||
], | ||
enableAreaChart: true, | ||
enableBarChart: true, | ||
grow: 4, | ||
description: i18n.UNIQUE_IPS, | ||
}, | ||
]; | ||
|
||
export const KpiHostsComponent = pure<KpiHostsProps>(({ data, loading }) => { | ||
return loading ? ( | ||
<EuiFlexGroup justifyContent="center" alignItems="center" style={{ minHeight: 247 }}> | ||
<EuiFlexItem grow={false}> | ||
<EuiLoadingSpinner size="xl" /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
) : ( | ||
<EuiFlexGroup> | ||
{fieldTitleMapping.map(stat => { | ||
let statItemProps: StatItemsProps = { | ||
...stat, | ||
key: `kpi-hosts-summary-${stat.description}`, | ||
}; | ||
|
||
if (stat.fields != null) | ||
statItemProps = { | ||
...statItemProps, | ||
fields: addValueToFields(stat.fields, data), | ||
}; | ||
|
||
if (stat.enableAreaChart) | ||
statItemProps = { | ||
...statItemProps, | ||
areaChart: addValueToAreaChart(stat.fields, data), | ||
}; | ||
|
||
if (stat.enableBarChart != null) | ||
statItemProps = { | ||
...statItemProps, | ||
barChart: addValueToBarChart(stat.fields, data), | ||
}; | ||
|
||
return <StatItemsComponent {...statItemProps} />; | ||
})} | ||
</EuiFlexGroup> | ||
); | ||
}); | ||
|
||
const addValueToFields = (fields: StatItem[], data: KpiHostsData): StatItem[] => | ||
fields.map(field => ({ ...field, value: get(field.key, data) })); | ||
|
||
const addValueToAreaChart = (fields: StatItem[], data: KpiHostsData): AreaChartData[] => | ||
fields | ||
.filter(field => get(`${field.key}Histogram`, data) != null) | ||
.map(field => ({ | ||
...field, | ||
value: get(`${field.key}Histogram`, data), | ||
key: `${field.key}Histogram`, | ||
})); | ||
|
||
const addValueToBarChart = (fields: StatItem[], data: KpiHostsData): BarChartData[] => { | ||
if (fields.length === 0) return []; | ||
return fields.reduce((acc: BarChartData[], field: StatItem, idx: number) => { | ||
const key = get('key', field); | ||
const x: number | null = getOr(null, key, data); | ||
const y: string = get(`${idx}.name`, fields) || getOr('', `${idx}.description`, fields); | ||
const dataSet: BarChartData[] = []; | ||
if (y != null) | ||
dataSet.push({ | ||
...field, | ||
value: [ | ||
{ | ||
x, | ||
y, | ||
}, | ||
], | ||
}); | ||
return acc.concat(dataSet); | ||
}, []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: I think you can you eliminate the if (y != null) {
return acc.concat([
{
...field,
value: [
{
x,
y,
},
],
},
]);
} else {
return acc.concat([]);
} Also, your type for const y: string = get(`${idx}.name`, fields) || getOr('', `${idx}.description`, fields); So wondering if you need the |
||
}; |
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.
Not sure if this is the 👍way to do it, but the following is used a bit around the codebase for importing the eui color constants:
As for determining the current theme, there's the context api:
but I don't think we have a specific
ThemeProvider
for accessing color constants for the current theme outside what is wired up for use withinstyled-components
(e.g. empty.tsx). That said, we may have some additional options when using the new elastic-charts.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.
mm, thanks @spong that make sense! So far we haven't had kpis with different themes, and I couldn't find all the color codes here in existing configs. I've found
#490092
,#920000
, should I replace them with import value? Still not sure what's preferable way of doing this.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.
So in addition to importing the colors, this would be for ensuring the right color is chosen depending on which application-level theme is currently enabled -- either the Kibana Light or Dark Theme.
To import these, you could wrap the
KpiHostsComponent
with theKibanaConfigContext.Consumer
example above, and then pass in the appropriateeuiDarkVars
/euiLightVars
for whichever theme is selected. You would then have to restructure your component a bit and movefieldTitleMapping
withinKpiHostsComponent
so you could use the appropriate colors (e.g.euiDarkVars.euiColorVis3
).I just doubled checked the EUI colors used and it looks like they don't change between themes, so it's probably fine to leave things as they are. This is something we can re-visit when we update charting libraries.