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

Update Kpi host UI to handle no data for charts #36424

Merged
merged 3 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe.each([
],
[
[
{ key: 'uniqueSourceIps', value: [{ x: 0, y: 'uniqueSourceIps' }], color: '#DB1374' },
{ key: 'uniqueSourceIps', value: [{ x: 1714, y: 'uniqueSourceIps' }], color: '#DB1374' },
{
key: 'uniqueDestinationIps',
value: [{ x: 0, y: 'uniqueDestinationIps' }],
Expand Down Expand Up @@ -129,6 +129,16 @@ describe.each([
},
],
],
[
[
{ key: 'uniqueSourceIps', value: [{ x: 0, y: 'uniqueSourceIps' }], color: '#DB1374' },
{
key: 'uniqueDestinationIps',
value: [{ x: 0, y: 'uniqueDestinationIps' }],
color: '#490092',
},
],
],
[
[
{ key: 'uniqueSourceIps', value: [{ x: null, y: 'uniqueSourceIps' }], color: '#DB1374' },
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/siem/public/components/stat_items/barchart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export const BarChartWithCustomPrompt = pure<{
}>(({ data, height, width }) => {
return data &&
data.length &&
data.every(
({ value }) => value != null && value.length > 0 && value.every(chart => chart.x != null)
data.some(
({ value }) =>
value != null && value.length > 0 && value.every(chart => chart.x != null && chart.x > 0)
) ? (
<BarChartBaseComponent height={height} width={width} data={data} />
) : (
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/siem/public/components/stat_items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const WrappedByAutoSizer = styled.div`
`;

const FlexGroup = styled(EuiFlexGroup)`
height: '100%';
height: 100%;
`;

const FlexItem = styled(EuiFlexItem)`
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface ChartData {

export interface BarChartData {
key: string;
value: ChartData[] | [] | null;
value: [ChartData] | [] | null;
color?: string | undefined;
}

Expand All @@ -81,8 +81,8 @@ export interface StatItems {

export interface StatItemsProps extends StatItems {
key: string;
areaChart?: AreaChartData[];
barChart?: BarChartData[];
areaChart?: AreaChartData[] | [];
barChart?: BarChartData[] | [];
}

export const StatItemsComponent = pure<StatItemsProps>(
Expand Down Expand Up @@ -120,7 +120,7 @@ export const StatItemsComponent = pure<StatItemsProps>(
<FlexItem>
<StatValue>
<p data-test-subj="stat-title">
{field.value ? field.value.toLocaleString() : getEmptyTagValue()}{' '}
{field.value != null ? field.value.toLocaleString() : getEmptyTagValue()}{' '}
{field.description}
</p>
</StatValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import gql from 'graphql-tag';

export const kpiHostsQuery = gql`
fragment ChartFields on HistogramData {
fragment ChartFields on KpiHostHistogramData {
x: key_as_string
y: count {
value
Expand Down
10 changes: 6 additions & 4 deletions x-pack/plugins/siem/public/containers/kpi_hosts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ const formatHistogramData = (
y: { value: number; doc_count: number };
}>
): ChartData[] => {
return data.map(({ x, y }) => ({
x,
y: y.value || y.doc_count,
}));
return data.length > 0
? data.map(({ x, y }) => ({
x,
y: y.value || y.doc_count,
}))
: [];
};

export const KpiHostsQuery = pure<KpiHostsProps>(
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/siem/public/graphql/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -6280,7 +6280,7 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6300,7 +6300,7 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6320,7 +6320,7 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6340,7 +6340,7 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6360,7 +6360,7 @@
"type": {
"kind": "LIST",
"name": null,
"ofType": { "kind": "OBJECT", "name": "HistogramData", "ofType": null }
"ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null }
},
"isDeprecated": false,
"deprecationReason": null
Expand All @@ -6373,7 +6373,7 @@
},
{
"kind": "OBJECT",
"name": "HistogramData",
"name": "KpiHostHistogramData",
"description": "",
"fields": [
{
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/siem/public/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,26 +1037,26 @@ export interface KpiNetworkData {
export interface KpiHostsData {
hosts?: number | null;

hostsHistogram?: (HistogramData | null)[] | null;
hostsHistogram?: (KpiHostHistogramData | null)[] | null;

authSuccess?: number | null;

authSuccessHistogram?: (HistogramData | null)[] | null;
authSuccessHistogram?: (KpiHostHistogramData | null)[] | null;

authFailure?: number | null;

authFailureHistogram?: (HistogramData | null)[] | null;
authFailureHistogram?: (KpiHostHistogramData | null)[] | null;

uniqueSourceIps?: number | null;

uniqueSourceIpsHistogram?: (HistogramData | null)[] | null;
uniqueSourceIpsHistogram?: (KpiHostHistogramData | null)[] | null;

uniqueDestinationIps?: number | null;

uniqueDestinationIpsHistogram?: (HistogramData | null)[] | null;
uniqueDestinationIpsHistogram?: (KpiHostHistogramData | null)[] | null;
}

export interface HistogramData {
export interface KpiHostHistogramData {
key?: number | null;

key_as_string?: string | null;
Expand Down Expand Up @@ -3889,7 +3889,7 @@ export namespace GetUsersQuery {

export namespace ChartFields {
export type Fragment = {
__typename?: 'HistogramData';
__typename?: 'KpiHostHistogramData';

x?: string | null;

Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ export const kpiHostsSchema = gql`
doc_count: Float
}

type HistogramData {
type KpiHostHistogramData {
key: Float
key_as_string: String
count: Count
}

type KpiHostsData {
hosts: Float
hostsHistogram: [HistogramData]
hostsHistogram: [KpiHostHistogramData]
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI -> if you do [KpiHostHistorgramData!], it will change the type from (KpiHostHistogramData | null)[] | null;} to (KpiHostHistogramData)[] | null;} and I think that can simplify some of your logic.

authSuccess: Float
authSuccessHistogram: [HistogramData]
authSuccessHistogram: [KpiHostHistogramData]
authFailure: Float
authFailureHistogram: [HistogramData]
authFailureHistogram: [KpiHostHistogramData]
uniqueSourceIps: Float
uniqueSourceIpsHistogram: [HistogramData]
uniqueSourceIpsHistogram: [KpiHostHistogramData]
uniqueDestinationIps: Float
uniqueDestinationIpsHistogram: [HistogramData]
uniqueDestinationIpsHistogram: [KpiHostHistogramData]
}

extend type Source {
Expand Down
46 changes: 25 additions & 21 deletions x-pack/plugins/siem/server/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,26 +1066,26 @@ export interface KpiNetworkData {
export interface KpiHostsData {
hosts?: number | null;

hostsHistogram?: (HistogramData | null)[] | null;
hostsHistogram?: (KpiHostHistogramData | null)[] | null;

authSuccess?: number | null;

authSuccessHistogram?: (HistogramData | null)[] | null;
authSuccessHistogram?: (KpiHostHistogramData | null)[] | null;

authFailure?: number | null;

authFailureHistogram?: (HistogramData | null)[] | null;
authFailureHistogram?: (KpiHostHistogramData | null)[] | null;

uniqueSourceIps?: number | null;

uniqueSourceIpsHistogram?: (HistogramData | null)[] | null;
uniqueSourceIpsHistogram?: (KpiHostHistogramData | null)[] | null;

uniqueDestinationIps?: number | null;

uniqueDestinationIpsHistogram?: (HistogramData | null)[] | null;
uniqueDestinationIpsHistogram?: (KpiHostHistogramData | null)[] | null;
}

export interface HistogramData {
export interface KpiHostHistogramData {
key?: number | null;

key_as_string?: string | null;
Expand Down Expand Up @@ -5187,36 +5187,40 @@ export namespace KpiHostsDataResolvers {
export interface Resolvers<Context = SiemContext, TypeParent = KpiHostsData> {
hosts?: HostsResolver<number | null, TypeParent, Context>;

hostsHistogram?: HostsHistogramResolver<(HistogramData | null)[] | null, TypeParent, Context>;
hostsHistogram?: HostsHistogramResolver<
(KpiHostHistogramData | null)[] | null,
TypeParent,
Context
>;

authSuccess?: AuthSuccessResolver<number | null, TypeParent, Context>;

authSuccessHistogram?: AuthSuccessHistogramResolver<
(HistogramData | null)[] | null,
(KpiHostHistogramData | null)[] | null,
TypeParent,
Context
>;

authFailure?: AuthFailureResolver<number | null, TypeParent, Context>;

authFailureHistogram?: AuthFailureHistogramResolver<
(HistogramData | null)[] | null,
(KpiHostHistogramData | null)[] | null,
TypeParent,
Context
>;

uniqueSourceIps?: UniqueSourceIpsResolver<number | null, TypeParent, Context>;

uniqueSourceIpsHistogram?: UniqueSourceIpsHistogramResolver<
(HistogramData | null)[] | null,
(KpiHostHistogramData | null)[] | null,
TypeParent,
Context
>;

uniqueDestinationIps?: UniqueDestinationIpsResolver<number | null, TypeParent, Context>;

uniqueDestinationIpsHistogram?: UniqueDestinationIpsHistogramResolver<
(HistogramData | null)[] | null,
(KpiHostHistogramData | null)[] | null,
TypeParent,
Context
>;
Expand All @@ -5228,7 +5232,7 @@ export namespace KpiHostsDataResolvers {
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type HostsHistogramResolver<
R = (HistogramData | null)[] | null,
R = (KpiHostHistogramData | null)[] | null,
Parent = KpiHostsData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
Expand All @@ -5238,7 +5242,7 @@ export namespace KpiHostsDataResolvers {
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type AuthSuccessHistogramResolver<
R = (HistogramData | null)[] | null,
R = (KpiHostHistogramData | null)[] | null,
Parent = KpiHostsData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
Expand All @@ -5248,7 +5252,7 @@ export namespace KpiHostsDataResolvers {
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type AuthFailureHistogramResolver<
R = (HistogramData | null)[] | null,
R = (KpiHostHistogramData | null)[] | null,
Parent = KpiHostsData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
Expand All @@ -5258,7 +5262,7 @@ export namespace KpiHostsDataResolvers {
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type UniqueSourceIpsHistogramResolver<
R = (HistogramData | null)[] | null,
R = (KpiHostHistogramData | null)[] | null,
Parent = KpiHostsData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
Expand All @@ -5268,14 +5272,14 @@ export namespace KpiHostsDataResolvers {
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type UniqueDestinationIpsHistogramResolver<
R = (HistogramData | null)[] | null,
R = (KpiHostHistogramData | null)[] | null,
Parent = KpiHostsData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
}

export namespace HistogramDataResolvers {
export interface Resolvers<Context = SiemContext, TypeParent = HistogramData> {
export namespace KpiHostHistogramDataResolvers {
export interface Resolvers<Context = SiemContext, TypeParent = KpiHostHistogramData> {
key?: KeyResolver<number | null, TypeParent, Context>;

key_as_string?: KeyAsStringResolver<string | null, TypeParent, Context>;
Expand All @@ -5285,17 +5289,17 @@ export namespace HistogramDataResolvers {

export type KeyResolver<
R = number | null,
Parent = HistogramData,
Parent = KpiHostHistogramData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type KeyAsStringResolver<
R = string | null,
Parent = HistogramData,
Parent = KpiHostHistogramData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
export type CountResolver<
R = Count | null,
Parent = HistogramData,
Parent = KpiHostHistogramData,
Context = SiemContext
> = Resolver<R, Parent, Context>;
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/server/lib/kpi_hosts/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const mockRequest = {
filterQuery: '',
},
query:
'fragment ChartFields on HistogramData {\n x: key\n y: count {\n value\n doc_count\n __typename\n }\n __typename\n}\n\nquery GetKpiHostsQuery($sourceId: ID!, $timerange: TimerangeInput!, $filterQuery: String) {\n source(id: $sourceId) {\n id\n KpiHosts(timerange: $timerange, filterQuery: $filterQuery) {\n hosts\n hostsHistogram {\n ...ChartFields\n __typename\n }\n authSuccess\n authSuccessHistogram {\n ...ChartFields\n __typename\n }\n authFailure\n authFailureHistogram {\n ...ChartFields\n __typename\n }\n uniqueSourceIps\n uniqueSourceIpsHistogram {\n ...ChartFields\n __typename\n }\n uniqueDestinationIps\n uniqueDestinationIpsHistogram {\n ...ChartFields\n __typename\n }\n __typename\n }\n __typename\n }\n}\n',
'fragment ChartFields on KpiHostHistogramData {\n x: key\n y: count {\n value\n doc_count\n __typename\n }\n __typename\n}\n\nquery GetKpiHostsQuery($sourceId: ID!, $timerange: TimerangeInput!, $filterQuery: String) {\n source(id: $sourceId) {\n id\n KpiHosts(timerange: $timerange, filterQuery: $filterQuery) {\n hosts\n hostsHistogram {\n ...ChartFields\n __typename\n }\n authSuccess\n authSuccessHistogram {\n ...ChartFields\n __typename\n }\n authFailure\n authFailureHistogram {\n ...ChartFields\n __typename\n }\n uniqueSourceIps\n uniqueSourceIpsHistogram {\n ...ChartFields\n __typename\n }\n uniqueDestinationIps\n uniqueDestinationIpsHistogram {\n ...ChartFields\n __typename\n }\n __typename\n }\n __typename\n }\n}\n',
},
query: {},
};
Expand Down
Loading