From e3a573ccedbee9df156d7e2aabe478b60650b048 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 10 May 2019 14:03:58 +0800 Subject: [PATCH 1/3] update types for areachart and barchart --- .../siem/public/components/stat_items/index.tsx | 6 +++--- .../plugins/siem/public/containers/kpi_hosts/index.tsx | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/siem/public/components/stat_items/index.tsx b/x-pack/plugins/siem/public/components/stat_items/index.tsx index ac4bf34bf2f6e..8de8656f964e4 100644 --- a/x-pack/plugins/siem/public/components/stat_items/index.tsx +++ b/x-pack/plugins/siem/public/components/stat_items/index.tsx @@ -31,7 +31,7 @@ export const WrappedByAutoSizer = styled.div` `; const FlexGroup = styled(EuiFlexGroup)` - height: '100%'; + height: 100%; `; const FlexItem = styled(EuiFlexItem)` @@ -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( diff --git a/x-pack/plugins/siem/public/containers/kpi_hosts/index.tsx b/x-pack/plugins/siem/public/containers/kpi_hosts/index.tsx index 5ee3623015b91..cfcb6a9f9c80c 100644 --- a/x-pack/plugins/siem/public/containers/kpi_hosts/index.tsx +++ b/x-pack/plugins/siem/public/containers/kpi_hosts/index.tsx @@ -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( From b5086f1a12be86c3d750f8871cb7740b5ccc1066 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Fri, 10 May 2019 15:56:03 +0800 Subject: [PATCH 2/3] handle no buckets returns for charts --- .../components/stat_items/barchart.test.tsx | 12 +- .../public/components/stat_items/barchart.tsx | 5 +- .../public/components/stat_items/index.tsx | 4 +- .../containers/kpi_hosts/index.gql_query.ts | 2 +- .../siem/public/graphql/introspection.json | 12 +- x-pack/plugins/siem/public/graphql/types.ts | 14 +- .../server/graphql/kpi_hosts/schema.gql.ts | 12 +- x-pack/plugins/siem/server/graphql/types.ts | 46 +++--- .../plugins/siem/server/lib/kpi_hosts/mock.ts | 2 +- .../api_integration/apis/siem/kpi_hosts.ts | 153 +++--------------- 10 files changed, 86 insertions(+), 176 deletions(-) diff --git a/x-pack/plugins/siem/public/components/stat_items/barchart.test.tsx b/x-pack/plugins/siem/public/components/stat_items/barchart.test.tsx index 3edcb316526e7..5586a079267d5 100644 --- a/x-pack/plugins/siem/public/components/stat_items/barchart.test.tsx +++ b/x-pack/plugins/siem/public/components/stat_items/barchart.test.tsx @@ -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' }], @@ -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' }, diff --git a/x-pack/plugins/siem/public/components/stat_items/barchart.tsx b/x-pack/plugins/siem/public/components/stat_items/barchart.tsx index 10987e0b44449..e67236e9af2c1 100644 --- a/x-pack/plugins/siem/public/components/stat_items/barchart.tsx +++ b/x-pack/plugins/siem/public/components/stat_items/barchart.tsx @@ -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) ) ? ( ) : ( diff --git a/x-pack/plugins/siem/public/components/stat_items/index.tsx b/x-pack/plugins/siem/public/components/stat_items/index.tsx index 8de8656f964e4..911f3164797e3 100644 --- a/x-pack/plugins/siem/public/components/stat_items/index.tsx +++ b/x-pack/plugins/siem/public/components/stat_items/index.tsx @@ -67,7 +67,7 @@ export interface ChartData { export interface BarChartData { key: string; - value: ChartData[] | [] | null; + value: [ChartData] | [] | null; color?: string | undefined; } @@ -120,7 +120,7 @@ export const StatItemsComponent = pure(

- {field.value ? field.value.toLocaleString() : getEmptyTagValue()}{' '} + {field.value != null ? field.value.toLocaleString() : getEmptyTagValue()}{' '} {field.description}

diff --git a/x-pack/plugins/siem/public/containers/kpi_hosts/index.gql_query.ts b/x-pack/plugins/siem/public/containers/kpi_hosts/index.gql_query.ts index 97bcb9d7907c1..cee743d85e373 100644 --- a/x-pack/plugins/siem/public/containers/kpi_hosts/index.gql_query.ts +++ b/x-pack/plugins/siem/public/containers/kpi_hosts/index.gql_query.ts @@ -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 diff --git a/x-pack/plugins/siem/public/graphql/introspection.json b/x-pack/plugins/siem/public/graphql/introspection.json index f951d737c47d1..83797c01ac8b8 100644 --- a/x-pack/plugins/siem/public/graphql/introspection.json +++ b/x-pack/plugins/siem/public/graphql/introspection.json @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -6373,7 +6373,7 @@ }, { "kind": "OBJECT", - "name": "HistogramData", + "name": "KpiHostHistogramData", "description": "", "fields": [ { diff --git a/x-pack/plugins/siem/public/graphql/types.ts b/x-pack/plugins/siem/public/graphql/types.ts index 2dcc8bc0328a1..df50b0ddd8e54 100644 --- a/x-pack/plugins/siem/public/graphql/types.ts +++ b/x-pack/plugins/siem/public/graphql/types.ts @@ -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; @@ -3889,7 +3889,7 @@ export namespace GetUsersQuery { export namespace ChartFields { export type Fragment = { - __typename?: 'HistogramData'; + __typename?: 'KpiHostHistogramData'; x?: string | null; diff --git a/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts b/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts index 85c98e89f9313..8f5041b93ac18 100644 --- a/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts +++ b/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts @@ -12,7 +12,7 @@ export const kpiHostsSchema = gql` doc_count: Float } - type HistogramData { + type KpiHostHistogramData { key: Float key_as_string: String count: Count @@ -20,15 +20,15 @@ export const kpiHostsSchema = gql` type KpiHostsData { hosts: Float - hostsHistogram: [HistogramData] + hostsHistogram: [KpiHostHistogramData] 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 { diff --git a/x-pack/plugins/siem/server/graphql/types.ts b/x-pack/plugins/siem/server/graphql/types.ts index 721ddce7e7c36..7325b491be994 100644 --- a/x-pack/plugins/siem/server/graphql/types.ts +++ b/x-pack/plugins/siem/server/graphql/types.ts @@ -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; @@ -5187,12 +5187,16 @@ export namespace KpiHostsDataResolvers { export interface Resolvers { hosts?: HostsResolver; - hostsHistogram?: HostsHistogramResolver<(HistogramData | null)[] | null, TypeParent, Context>; + hostsHistogram?: HostsHistogramResolver< + (KpiHostHistogramData | null)[] | null, + TypeParent, + Context + >; authSuccess?: AuthSuccessResolver; authSuccessHistogram?: AuthSuccessHistogramResolver< - (HistogramData | null)[] | null, + (KpiHostHistogramData | null)[] | null, TypeParent, Context >; @@ -5200,7 +5204,7 @@ export namespace KpiHostsDataResolvers { authFailure?: AuthFailureResolver; authFailureHistogram?: AuthFailureHistogramResolver< - (HistogramData | null)[] | null, + (KpiHostHistogramData | null)[] | null, TypeParent, Context >; @@ -5208,7 +5212,7 @@ export namespace KpiHostsDataResolvers { uniqueSourceIps?: UniqueSourceIpsResolver; uniqueSourceIpsHistogram?: UniqueSourceIpsHistogramResolver< - (HistogramData | null)[] | null, + (KpiHostHistogramData | null)[] | null, TypeParent, Context >; @@ -5216,7 +5220,7 @@ export namespace KpiHostsDataResolvers { uniqueDestinationIps?: UniqueDestinationIpsResolver; uniqueDestinationIpsHistogram?: UniqueDestinationIpsHistogramResolver< - (HistogramData | null)[] | null, + (KpiHostHistogramData | null)[] | null, TypeParent, Context >; @@ -5228,7 +5232,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type HostsHistogramResolver< - R = (HistogramData | null)[] | null, + R = (KpiHostHistogramData | null)[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5238,7 +5242,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type AuthSuccessHistogramResolver< - R = (HistogramData | null)[] | null, + R = (KpiHostHistogramData | null)[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5248,7 +5252,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type AuthFailureHistogramResolver< - R = (HistogramData | null)[] | null, + R = (KpiHostHistogramData | null)[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5258,7 +5262,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type UniqueSourceIpsHistogramResolver< - R = (HistogramData | null)[] | null, + R = (KpiHostHistogramData | null)[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5268,14 +5272,14 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type UniqueDestinationIpsHistogramResolver< - R = (HistogramData | null)[] | null, + R = (KpiHostHistogramData | null)[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; } -export namespace HistogramDataResolvers { - export interface Resolvers { +export namespace KpiHostHistogramDataResolvers { + export interface Resolvers { key?: KeyResolver; key_as_string?: KeyAsStringResolver; @@ -5285,17 +5289,17 @@ export namespace HistogramDataResolvers { export type KeyResolver< R = number | null, - Parent = HistogramData, + Parent = KpiHostHistogramData, Context = SiemContext > = Resolver; export type KeyAsStringResolver< R = string | null, - Parent = HistogramData, + Parent = KpiHostHistogramData, Context = SiemContext > = Resolver; export type CountResolver< R = Count | null, - Parent = HistogramData, + Parent = KpiHostHistogramData, Context = SiemContext > = Resolver; } diff --git a/x-pack/plugins/siem/server/lib/kpi_hosts/mock.ts b/x-pack/plugins/siem/server/lib/kpi_hosts/mock.ts index 903c17dbe27d7..af7a5e40ee4fb 100644 --- a/x-pack/plugins/siem/server/lib/kpi_hosts/mock.ts +++ b/x-pack/plugins/siem/server/lib/kpi_hosts/mock.ts @@ -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: {}, }; diff --git a/x-pack/test/api_integration/apis/siem/kpi_hosts.ts b/x-pack/test/api_integration/apis/siem/kpi_hosts.ts index 44c46d01aa0ac..a672653f2a913 100644 --- a/x-pack/test/api_integration/apis/siem/kpi_hosts.ts +++ b/x-pack/test/api_integration/apis/siem/kpi_hosts.ts @@ -30,7 +30,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 1, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T19:00:00.000Z', @@ -39,7 +39,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 0, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T22:00:00.000Z', @@ -48,7 +48,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 1, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-10T01:00:00.000Z', @@ -57,7 +57,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 1, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, ], authSuccess: 0, @@ -73,7 +73,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 52, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T19:00:00.000Z', @@ -82,7 +82,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 0, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T22:00:00.000Z', @@ -91,7 +91,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 31, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-10T01:00:00.000Z', @@ -100,7 +100,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 88, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, ], uniqueDestinationIps: 154, @@ -112,7 +112,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 61, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T19:00:00.000Z', @@ -121,7 +121,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 0, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T22:00:00.000Z', @@ -130,7 +130,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 45, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-10T01:00:00.000Z', @@ -139,7 +139,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 114, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, ], }; @@ -181,7 +181,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 1, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T19:00:00.000Z', @@ -190,7 +190,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 0, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T22:00:00.000Z', @@ -199,7 +199,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 1, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-10T01:00:00.000Z', @@ -208,7 +208,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 1, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, ], authSuccess: 0, @@ -224,7 +224,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 52, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T19:00:00.000Z', @@ -233,7 +233,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 0, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T22:00:00.000Z', @@ -242,7 +242,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 31, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-10T01:00:00.000Z', @@ -251,7 +251,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 88, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, ], uniqueDestinationIps: 154, @@ -263,7 +263,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 61, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T19:00:00.000Z', @@ -272,7 +272,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 0, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-09T22:00:00.000Z', @@ -281,7 +281,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 45, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, { x: '2019-02-10T01:00:00.000Z', @@ -290,7 +290,7 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { doc_count: null, value: 114, }, - __typename: 'HistogramData', + __typename: 'KpiHostHistogramData', }, ], }; @@ -310,111 +310,6 @@ const kpiHostsTests: KbnTestProvider = ({ getService }) => { .then(resp => { const kpiHosts = resp.data.source.KpiHosts; expect(kpiHosts!).to.eql(expectedResult); - // expect(kpiHosts!.hostsHistogram).to.eql([ - // { - // x: '2019-02-09T16:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 1, - // }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-09T19:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 0, - // }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-09T22:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 1, - // }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-10T01:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 1, - // }, - // __typename: 'HistogramData', - // }, - // ]); - // expect(kpiHosts!.authSuccess).to.be(0); - // expect(kpiHosts!.authSuccessHistogram).to.eql([]); - // expect(kpiHosts!.authFailure).to.equal(0); - // expect(kpiHosts!.authFailureHistogram).to.eql([]); - // expect(kpiHosts!.uniqueSourceIps).to.equal(121); - // expect(kpiHosts!.uniqueSourceIpsHistogram).to.eql([ - // { - // x: '2019-02-09T16:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 52, - // }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-09T19:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 0, - // }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-09T22:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 31, - // }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-10T01:00:00.000Z', - // y: { - // __typename: 'Count', - // doc_count: null, - // value: 88, - // }, - // __typename: 'HistogramData', - // }, - // ]); - // expect(kpiHosts!.uniqueDestinationIps).to.equal(154); - // expect(kpiHosts!.uniqueDestinationIpsHistogram).to.eql([ - // { - // x: '2019-02-09T16:00:00.000Z', - // y: { value: 61, doc_count: null, __typename: 'Count' }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-09T19:00:00.000Z', - // y: { value: 0, doc_count: null, __typename: 'Count' }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-09T22:00:00.000Z', - // y: { value: 45, doc_count: null, __typename: 'Count' }, - // __typename: 'HistogramData', - // }, - // { - // x: '2019-02-10T01:00:00.000Z', - // y: { value: 114, doc_count: null, __typename: 'Count' }, - // __typename: 'HistogramData', - // }, - // ]); - // }); }); }); }); From 1daeb8d7e71e56fda47c0a9d8e9f5561456f6f12 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Sat, 11 May 2019 00:58:13 +0800 Subject: [PATCH 3/3] update data types for histogram data --- .../public/components/stat_items/index.tsx | 4 +-- .../siem/public/graphql/introspection.json | 30 +++++++++++++--- x-pack/plugins/siem/public/graphql/types.ts | 20 +++++------ .../server/graphql/kpi_hosts/schema.gql.ts | 10 +++--- x-pack/plugins/siem/server/graphql/types.ts | 34 ++++++++----------- 5 files changed, 57 insertions(+), 41 deletions(-) diff --git a/x-pack/plugins/siem/public/components/stat_items/index.tsx b/x-pack/plugins/siem/public/components/stat_items/index.tsx index 911f3164797e3..e05db0efe2fe9 100644 --- a/x-pack/plugins/siem/public/components/stat_items/index.tsx +++ b/x-pack/plugins/siem/public/components/stat_items/index.tsx @@ -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( diff --git a/x-pack/plugins/siem/public/graphql/introspection.json b/x-pack/plugins/siem/public/graphql/introspection.json index 83797c01ac8b8..fa056ef0c91eb 100644 --- a/x-pack/plugins/siem/public/graphql/introspection.json +++ b/x-pack/plugins/siem/public/graphql/introspection.json @@ -6280,7 +6280,11 @@ "type": { "kind": "LIST", "name": null, - "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + } }, "isDeprecated": false, "deprecationReason": null @@ -6300,7 +6304,11 @@ "type": { "kind": "LIST", "name": null, - "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + } }, "isDeprecated": false, "deprecationReason": null @@ -6320,7 +6328,11 @@ "type": { "kind": "LIST", "name": null, - "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + } }, "isDeprecated": false, "deprecationReason": null @@ -6340,7 +6352,11 @@ "type": { "kind": "LIST", "name": null, - "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + } }, "isDeprecated": false, "deprecationReason": null @@ -6360,7 +6376,11 @@ "type": { "kind": "LIST", "name": null, - "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { "kind": "OBJECT", "name": "KpiHostHistogramData", "ofType": null } + } }, "isDeprecated": false, "deprecationReason": null diff --git a/x-pack/plugins/siem/public/graphql/types.ts b/x-pack/plugins/siem/public/graphql/types.ts index df50b0ddd8e54..f7ecbbe7412cd 100644 --- a/x-pack/plugins/siem/public/graphql/types.ts +++ b/x-pack/plugins/siem/public/graphql/types.ts @@ -1037,23 +1037,23 @@ export interface KpiNetworkData { export interface KpiHostsData { hosts?: number | null; - hostsHistogram?: (KpiHostHistogramData | null)[] | null; + hostsHistogram?: KpiHostHistogramData[] | null; authSuccess?: number | null; - authSuccessHistogram?: (KpiHostHistogramData | null)[] | null; + authSuccessHistogram?: KpiHostHistogramData[] | null; authFailure?: number | null; - authFailureHistogram?: (KpiHostHistogramData | null)[] | null; + authFailureHistogram?: KpiHostHistogramData[] | null; uniqueSourceIps?: number | null; - uniqueSourceIpsHistogram?: (KpiHostHistogramData | null)[] | null; + uniqueSourceIpsHistogram?: KpiHostHistogramData[] | null; uniqueDestinationIps?: number | null; - uniqueDestinationIpsHistogram?: (KpiHostHistogramData | null)[] | null; + uniqueDestinationIpsHistogram?: KpiHostHistogramData[] | null; } export interface KpiHostHistogramData { @@ -2474,23 +2474,23 @@ export namespace GetKpiHostsQuery { hosts?: number | null; - hostsHistogram?: (HostsHistogram | null)[] | null; + hostsHistogram?: HostsHistogram[] | null; authSuccess?: number | null; - authSuccessHistogram?: (AuthSuccessHistogram | null)[] | null; + authSuccessHistogram?: AuthSuccessHistogram[] | null; authFailure?: number | null; - authFailureHistogram?: (AuthFailureHistogram | null)[] | null; + authFailureHistogram?: AuthFailureHistogram[] | null; uniqueSourceIps?: number | null; - uniqueSourceIpsHistogram?: (UniqueSourceIpsHistogram | null)[] | null; + uniqueSourceIpsHistogram?: UniqueSourceIpsHistogram[] | null; uniqueDestinationIps?: number | null; - uniqueDestinationIpsHistogram?: (UniqueDestinationIpsHistogram | null)[] | null; + uniqueDestinationIpsHistogram?: UniqueDestinationIpsHistogram[] | null; }; export type HostsHistogram = ChartFields.Fragment; diff --git a/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts b/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts index 8f5041b93ac18..48dd199d84bed 100644 --- a/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts +++ b/x-pack/plugins/siem/server/graphql/kpi_hosts/schema.gql.ts @@ -20,15 +20,15 @@ export const kpiHostsSchema = gql` type KpiHostsData { hosts: Float - hostsHistogram: [KpiHostHistogramData] + hostsHistogram: [KpiHostHistogramData!] authSuccess: Float - authSuccessHistogram: [KpiHostHistogramData] + authSuccessHistogram: [KpiHostHistogramData!] authFailure: Float - authFailureHistogram: [KpiHostHistogramData] + authFailureHistogram: [KpiHostHistogramData!] uniqueSourceIps: Float - uniqueSourceIpsHistogram: [KpiHostHistogramData] + uniqueSourceIpsHistogram: [KpiHostHistogramData!] uniqueDestinationIps: Float - uniqueDestinationIpsHistogram: [KpiHostHistogramData] + uniqueDestinationIpsHistogram: [KpiHostHistogramData!] } extend type Source { diff --git a/x-pack/plugins/siem/server/graphql/types.ts b/x-pack/plugins/siem/server/graphql/types.ts index 7325b491be994..2f20017795906 100644 --- a/x-pack/plugins/siem/server/graphql/types.ts +++ b/x-pack/plugins/siem/server/graphql/types.ts @@ -1066,23 +1066,23 @@ export interface KpiNetworkData { export interface KpiHostsData { hosts?: number | null; - hostsHistogram?: (KpiHostHistogramData | null)[] | null; + hostsHistogram?: KpiHostHistogramData[] | null; authSuccess?: number | null; - authSuccessHistogram?: (KpiHostHistogramData | null)[] | null; + authSuccessHistogram?: KpiHostHistogramData[] | null; authFailure?: number | null; - authFailureHistogram?: (KpiHostHistogramData | null)[] | null; + authFailureHistogram?: KpiHostHistogramData[] | null; uniqueSourceIps?: number | null; - uniqueSourceIpsHistogram?: (KpiHostHistogramData | null)[] | null; + uniqueSourceIpsHistogram?: KpiHostHistogramData[] | null; uniqueDestinationIps?: number | null; - uniqueDestinationIpsHistogram?: (KpiHostHistogramData | null)[] | null; + uniqueDestinationIpsHistogram?: KpiHostHistogramData[] | null; } export interface KpiHostHistogramData { @@ -5187,16 +5187,12 @@ export namespace KpiHostsDataResolvers { export interface Resolvers { hosts?: HostsResolver; - hostsHistogram?: HostsHistogramResolver< - (KpiHostHistogramData | null)[] | null, - TypeParent, - Context - >; + hostsHistogram?: HostsHistogramResolver; authSuccess?: AuthSuccessResolver; authSuccessHistogram?: AuthSuccessHistogramResolver< - (KpiHostHistogramData | null)[] | null, + KpiHostHistogramData[] | null, TypeParent, Context >; @@ -5204,7 +5200,7 @@ export namespace KpiHostsDataResolvers { authFailure?: AuthFailureResolver; authFailureHistogram?: AuthFailureHistogramResolver< - (KpiHostHistogramData | null)[] | null, + KpiHostHistogramData[] | null, TypeParent, Context >; @@ -5212,7 +5208,7 @@ export namespace KpiHostsDataResolvers { uniqueSourceIps?: UniqueSourceIpsResolver; uniqueSourceIpsHistogram?: UniqueSourceIpsHistogramResolver< - (KpiHostHistogramData | null)[] | null, + KpiHostHistogramData[] | null, TypeParent, Context >; @@ -5220,7 +5216,7 @@ export namespace KpiHostsDataResolvers { uniqueDestinationIps?: UniqueDestinationIpsResolver; uniqueDestinationIpsHistogram?: UniqueDestinationIpsHistogramResolver< - (KpiHostHistogramData | null)[] | null, + KpiHostHistogramData[] | null, TypeParent, Context >; @@ -5232,7 +5228,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type HostsHistogramResolver< - R = (KpiHostHistogramData | null)[] | null, + R = KpiHostHistogramData[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5242,7 +5238,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type AuthSuccessHistogramResolver< - R = (KpiHostHistogramData | null)[] | null, + R = KpiHostHistogramData[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5252,7 +5248,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type AuthFailureHistogramResolver< - R = (KpiHostHistogramData | null)[] | null, + R = KpiHostHistogramData[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5262,7 +5258,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type UniqueSourceIpsHistogramResolver< - R = (KpiHostHistogramData | null)[] | null, + R = KpiHostHistogramData[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver; @@ -5272,7 +5268,7 @@ export namespace KpiHostsDataResolvers { Context = SiemContext > = Resolver; export type UniqueDestinationIpsHistogramResolver< - R = (KpiHostHistogramData | null)[] | null, + R = KpiHostHistogramData[] | null, Parent = KpiHostsData, Context = SiemContext > = Resolver;