forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Infra UI] Adding links from Infra UI to Uptime (elastic#35993)
* [Infra UI] Adding from Infra UI to Uptime * Removed unused variable * Adding tests for link generation * Sometimes the IP address will be an array with [IPv4, IPv6] * Ensuring only IPv4 addresses are returned; adding tests; * only showing uptime link for host's with ip addresses
- Loading branch information
1 parent
581d499
commit 471aba0
Showing
16 changed files
with
311 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
x-pack/plugins/infra/public/components/waffle/lib/create_uptime_link.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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 { createUptimeLink } from './create_uptime_link'; | ||
import { | ||
InfraWaffleMapOptions, | ||
InfraWaffleMapLegendMode, | ||
InfraFormatterType, | ||
} from '../../../lib/lib'; | ||
import { InfraNodeType } from '../../../../common/graphql/types'; | ||
import { InfraSnapshotMetricType } from '../../../graphql/types'; | ||
|
||
const options: InfraWaffleMapOptions = { | ||
fields: { | ||
container: 'container.id', | ||
pod: 'kubernetes.pod.uid', | ||
host: 'host.name', | ||
message: ['@message'], | ||
timestamp: '@timestanp', | ||
tiebreaker: '@timestamp', | ||
}, | ||
formatter: InfraFormatterType.percent, | ||
formatTemplate: '{{value}}', | ||
metric: { type: InfraSnapshotMetricType.cpu }, | ||
groupBy: [], | ||
legend: { | ||
type: InfraWaffleMapLegendMode.gradient, | ||
rules: [], | ||
}, | ||
}; | ||
|
||
describe('createUptimeLink()', () => { | ||
it('should work for hosts with ip', () => { | ||
const node = { | ||
pathId: 'host-01', | ||
id: 'host-01', | ||
name: 'host-01', | ||
ip: '10.0.1.2', | ||
path: [], | ||
metric: { | ||
name: InfraSnapshotMetricType.cpu, | ||
value: 0.5, | ||
max: 0.8, | ||
avg: 0.6, | ||
}, | ||
}; | ||
expect(createUptimeLink(options, InfraNodeType.host, node)).toBe( | ||
'../app/uptime#/?search=host.ip:"10.0.1.2"' | ||
); | ||
}); | ||
|
||
it('should work for hosts without ip', () => { | ||
const node = { | ||
pathId: 'host-01', | ||
id: 'host-01', | ||
name: 'host-01', | ||
path: [], | ||
metric: { | ||
name: InfraSnapshotMetricType.cpu, | ||
value: 0.5, | ||
max: 0.8, | ||
avg: 0.6, | ||
}, | ||
}; | ||
expect(createUptimeLink(options, InfraNodeType.host, node)).toBe( | ||
'../app/uptime#/?search=host.name:"host-01"' | ||
); | ||
}); | ||
|
||
it('should work for pods', () => { | ||
const node = { | ||
pathId: 'pod-01', | ||
id: '29193-pod-02939', | ||
name: 'pod-01', | ||
path: [], | ||
metric: { | ||
name: InfraSnapshotMetricType.cpu, | ||
value: 0.5, | ||
max: 0.8, | ||
avg: 0.6, | ||
}, | ||
}; | ||
expect(createUptimeLink(options, InfraNodeType.pod, node)).toBe( | ||
'../app/uptime#/?search=kubernetes.pod.uid:"29193-pod-02939"' | ||
); | ||
}); | ||
|
||
it('should work for container', () => { | ||
const node = { | ||
pathId: 'docker-01', | ||
id: 'docker-1234', | ||
name: 'docker-01', | ||
path: [], | ||
metric: { | ||
name: InfraSnapshotMetricType.cpu, | ||
value: 0.5, | ||
max: 0.8, | ||
avg: 0.6, | ||
}, | ||
}; | ||
expect(createUptimeLink(options, InfraNodeType.container, node)).toBe( | ||
'../app/uptime#/?search=container.id:"docker-1234"' | ||
); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
x-pack/plugins/infra/public/components/waffle/lib/create_uptime_link.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 { get } from 'lodash'; | ||
import { InfraNodeType } from '../../../graphql/types'; | ||
import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../../lib/lib'; | ||
|
||
const BASE_URL = '../app/uptime#/?search='; | ||
|
||
export const createUptimeLink = ( | ||
options: InfraWaffleMapOptions, | ||
nodeType: InfraNodeType, | ||
node: InfraWaffleMapNode | ||
) => { | ||
if (nodeType === InfraNodeType.host && node.ip) { | ||
return `${BASE_URL}host.ip:"${node.ip}"`; | ||
} | ||
const field = get(options, ['fields', nodeType], ''); | ||
return `${BASE_URL}${field ? field + ':' : ''}"${node.id}"`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ export const waffleNodesQuery = gql` | |
path { | ||
value | ||
label | ||
ip | ||
} | ||
metric { | ||
name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/infra/server/lib/snapshot/response_helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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 { isIPv4, getIPFromBucket, InfraSnapshotNodeGroupByBucket } from './response_helpers'; | ||
import { InfraNodeType } from '../../graphql/types'; | ||
|
||
describe('InfraOps ResponseHelpers', () => { | ||
describe('isIPv4', () => { | ||
it('should return true for IPv4', () => { | ||
expect(isIPv4('192.168.2.4')).toBe(true); | ||
}); | ||
it('should return false for anything else', () => { | ||
expect(isIPv4('0:0:0:0:0:0:0:1')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getIPFromBucket', () => { | ||
it('should return IPv4 address', () => { | ||
const bucket: InfraSnapshotNodeGroupByBucket = { | ||
key: { | ||
id: 'example-01', | ||
name: 'example-01', | ||
}, | ||
ip: { | ||
hits: { | ||
total: { value: 1 }, | ||
hits: [ | ||
{ | ||
_index: 'metricbeat-2019-01-01', | ||
_type: '_doc', | ||
_id: '29392939', | ||
_score: null, | ||
sort: [], | ||
_source: { | ||
host: { | ||
ip: ['2001:db8:85a3::8a2e:370:7334', '192.168.1.4'], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
expect(getIPFromBucket(InfraNodeType.host, bucket)).toBe('192.168.1.4'); | ||
}); | ||
it('should NOT return ipv6 address', () => { | ||
const bucket: InfraSnapshotNodeGroupByBucket = { | ||
key: { | ||
id: 'example-01', | ||
name: 'example-01', | ||
}, | ||
ip: { | ||
hits: { | ||
total: { value: 1 }, | ||
hits: [ | ||
{ | ||
_index: 'metricbeat-2019-01-01', | ||
_type: '_doc', | ||
_id: '29392939', | ||
_score: null, | ||
sort: [], | ||
_source: { | ||
host: { | ||
ip: ['2001:db8:85a3::8a2e:370:7334'], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
expect(getIPFromBucket(InfraNodeType.host, bucket)).toBe(null); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.