diff --git a/x-pack/plugins/uptime/common/graphql/introspection.json b/x-pack/plugins/uptime/common/graphql/introspection.json index c8bae40970f48..8fcbcb58c6654 100644 --- a/x-pack/plugins/uptime/common/graphql/introspection.json +++ b/x-pack/plugins/uptime/common/graphql/introspection.json @@ -437,6 +437,14 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "container", + "description": "", + "args": [], + "type": { "kind": "OBJECT", "name": "Container", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "docker", "description": "", @@ -614,6 +622,76 @@ "enumValues": null, "possibleTypes": null }, + { + "kind": "OBJECT", + "name": "Container", + "description": "", + "fields": [ + { + "name": "id", + "description": "", + "args": [], + "type": { "kind": "SCALAR", "name": "String", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "image", + "description": "", + "args": [], + "type": { "kind": "OBJECT", "name": "ContainerImage", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": "", + "args": [], + "type": { "kind": "SCALAR", "name": "String", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "runtime", + "description": "", + "args": [], + "type": { "kind": "SCALAR", "name": "String", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "ContainerImage", + "description": "", + "fields": [ + { + "name": "name", + "description": "", + "args": [], + "type": { "kind": "SCALAR", "name": "String", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "tag", + "description": "", + "args": [], + "type": { "kind": "SCALAR", "name": "String", "ofType": null }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, { "kind": "OBJECT", "name": "Docker", diff --git a/x-pack/plugins/uptime/common/graphql/types.ts b/x-pack/plugins/uptime/common/graphql/types.ts index 19c1ba278cf73..1ce91f9a2b71d 100644 --- a/x-pack/plugins/uptime/common/graphql/types.ts +++ b/x-pack/plugins/uptime/common/graphql/types.ts @@ -1,4 +1,9 @@ -/* eslint-disable */ +/* + * 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. + */ +/* tslint:disable */ // ==================================================== // START: Typescript template @@ -49,6 +54,8 @@ export interface Ping { /** The agent that recorded the ping */ beat?: Beat | null; + container?: Container | null; + docker?: Docker | null; ecs?: Ecs | null; @@ -92,6 +99,22 @@ export interface Beat { type?: string | null; } +export interface Container { + id?: string | null; + + image?: ContainerImage | null; + + name?: string | null; + + runtime?: string | null; +} + +export interface ContainerImage { + name?: string | null; + + tag?: string | null; +} + export interface Docker { id?: string | null; diff --git a/x-pack/plugins/uptime/public/queries/monitor_list_query.ts b/x-pack/plugins/uptime/public/queries/monitor_list_query.ts index 4977b36da9964..abaef1e79a8c4 100644 --- a/x-pack/plugins/uptime/public/queries/monitor_list_query.ts +++ b/x-pack/plugins/uptime/public/queries/monitor_list_query.ts @@ -20,6 +20,14 @@ export const monitorListQueryString = ` } ping { timestamp + container { + id + } + kubernetes { + pod { + uid + } + } monitor { duration { us diff --git a/x-pack/plugins/uptime/server/graphql/pings/schema.gql.ts b/x-pack/plugins/uptime/server/graphql/pings/schema.gql.ts index 860be8d20af7f..122a6cd610138 100644 --- a/x-pack/plugins/uptime/server/graphql/pings/schema.gql.ts +++ b/x-pack/plugins/uptime/server/graphql/pings/schema.gql.ts @@ -31,6 +31,18 @@ export const pingsSchema = gql` getDocCount: DocCount! } + type ContainerImage { + name: String + tag: String + } + + type Container { + id: String + image: ContainerImage + name: String + runtime: String + } + type DocCount { count: UnsignedInteger! } @@ -210,6 +222,7 @@ export const pingsSchema = gql` millisFromNow: String "The agent that recorded the ping" beat: Beat + container: Container docker: Docker ecs: ECS error: Error diff --git a/x-pack/plugins/uptime/server/lib/adapters/monitors/__tests__/__snapshots__/elasticsearch_monitors_adapter.test.ts.snap b/x-pack/plugins/uptime/server/lib/adapters/monitors/__tests__/__snapshots__/elasticsearch_monitors_adapter.test.ts.snap new file mode 100644 index 0000000000000..79d6d87611bda --- /dev/null +++ b/x-pack/plugins/uptime/server/lib/adapters/monitors/__tests__/__snapshots__/elasticsearch_monitors_adapter.test.ts.snap @@ -0,0 +1,27 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ElasticsearchMonitorsAdapter will return kubernetes information if contained in hits 1`] = ` +Object { + "downSeries": Array [], + "id": Object { + "key": "foo", + "url": "bar", + }, + "ping": Object { + "@timestamp": "2018-10-30T18:51:59.800Z", + "container": Object { + "id": "container_id", + }, + "kubernetes": Object { + "pod": Object { + "uid": "kubernetes_pod_uid", + }, + }, + "monitor": Object { + "status": "up", + }, + "timestamp": "2018-10-30T18:51:59.800Z", + }, + "upSeries": Array [], +} +`; diff --git a/x-pack/plugins/uptime/server/lib/adapters/monitors/__tests__/elasticsearch_monitors_adapter.test.ts b/x-pack/plugins/uptime/server/lib/adapters/monitors/__tests__/elasticsearch_monitors_adapter.test.ts new file mode 100644 index 0000000000000..6a1ea8595d0f3 --- /dev/null +++ b/x-pack/plugins/uptime/server/lib/adapters/monitors/__tests__/elasticsearch_monitors_adapter.test.ts @@ -0,0 +1,65 @@ +/* + * 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 { DatabaseAdapter } from '../../database'; +import { ElasticsearchMonitorsAdapter } from '../elasticsearch_monitors_adapter'; + +// FIXME: there are many untested functions in this adapter. They should be tested. +describe('ElasticsearchMonitorsAdapter', () => { + it('will return kubernetes information if contained in hits', async () => { + expect.assertions(2); + + const mockHits = [ + { + _source: { + '@timestamp': '2018-10-30T18:51:59.800Z', + container: { + id: 'container_id', + }, + kubernetes: { + pod: { + uid: 'kubernetes_pod_uid', + }, + }, + monitor: { + status: 'up', + }, + }, + }, + ]; + const mockEsQueryResult = { + aggregations: { + hosts: { + buckets: [ + { + key: { + id: 'foo', + url: 'bar', + }, + latest: { + hits: { + hits: mockHits, + }, + }, + histogram: { + buckets: [], + }, + }, + ], + }, + }, + }; + + const database: DatabaseAdapter = { + search: async (request: any, params: any) => mockEsQueryResult, + count: async (request: any, params: any) => null, + }; + const adapter = new ElasticsearchMonitorsAdapter(database); + const result = await adapter.getMonitors({}, 'now-15m', 'now'); + expect(result).toHaveLength(1); + expect(result[0]).toMatchSnapshot(); + }); +}); diff --git a/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list.json b/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list.json index 01a6ae6cda309..dc2e4541777a1 100644 --- a/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list.json +++ b/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list.json @@ -5,6 +5,8 @@ "id": { "key": "auto-http-0X131221E73F825974", "url": "https://www.google.com/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 132169 }, "id": "auto-http-0X131221E73F825974", @@ -47,6 +49,8 @@ "id": { "key": "auto-http-0X3675F89EF0612091", "url": "http://localhost:12349/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 3331 }, "id": "auto-http-0X3675F89EF0612091", @@ -89,6 +93,8 @@ "id": { "key": "auto-http-0X970CBD2F2102BFA8", "url": "http://www.google.com/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 118727 }, "id": "auto-http-0X970CBD2F2102BFA8", @@ -131,6 +137,8 @@ "id": { "key": "auto-http-0X9CB71300ABD5A2A8", "url": "https://www.github.com/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 247244 }, "id": "auto-http-0X9CB71300ABD5A2A8", @@ -173,6 +181,8 @@ "id": { "key": "auto-http-0XA8096548ECEB85B7", "url": "http://www.example.com/" }, "ping": { "timestamp": "2019-01-28T18:43:07.078Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 4751074 }, "id": "auto-http-0XA8096548ECEB85B7", @@ -215,6 +225,8 @@ "id": { "key": "auto-http-0XC9CDA429418EDC2B", "url": "https://www.wikipedia.org/" }, "ping": { "timestamp": "2019-01-28T18:42:55.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 1164812 }, "id": "auto-http-0XC9CDA429418EDC2B", @@ -257,6 +269,8 @@ "id": { "key": "auto-http-0XD9AE729FC1C1E04A", "url": "http://www.reddit.com/" }, "ping": { "timestamp": "2019-01-28T18:43:13.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 299586 }, "id": "auto-http-0XD9AE729FC1C1E04A", @@ -299,6 +313,8 @@ "id": { "key": "auto-http-0XDD2D4E60FD4A61C3", "url": "https://www.elastic.co" }, "ping": { "timestamp": "2019-01-28T18:43:13.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 850870 }, "id": "auto-http-0XDD2D4E60FD4A61C3", @@ -341,6 +357,8 @@ "id": { "key": "auto-http-0XE3B163481423197D", "url": "https://news.google.com/" }, "ping": { "timestamp": "2019-01-28T18:42:55.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 2059606 }, "id": "auto-http-0XE3B163481423197D", @@ -383,6 +401,8 @@ "id": { "key": "auto-tcp-0X81440A68E839814C", "url": "tcp://localhost:9200" }, "ping": { "timestamp": "2019-01-28T18:43:16.078Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 3328 }, "id": "auto-tcp-0X81440A68E839814C", diff --git a/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_down_filtered.json b/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_down_filtered.json index 48de497bb1736..676c422d107b4 100644 --- a/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_down_filtered.json +++ b/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_down_filtered.json @@ -5,6 +5,8 @@ "id": { "key": "auto-http-0X3675F89EF0612091", "url": "http://localhost:12349/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 3331 }, "id": "auto-http-0X3675F89EF0612091", @@ -47,6 +49,8 @@ "id": { "key": "auto-http-0XA8096548ECEB85B7", "url": "http://www.example.com/" }, "ping": { "timestamp": "2019-01-28T18:43:07.078Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 4751074 }, "id": "auto-http-0XA8096548ECEB85B7", diff --git a/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_up_filtered.json b/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_up_filtered.json index 5dc5e7e8db80e..883bbab4818ff 100644 --- a/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_up_filtered.json +++ b/x-pack/test/api_integration/apis/uptime/graphql/fixtures/monitor_list_up_filtered.json @@ -5,6 +5,8 @@ "id": { "key": "auto-http-0X131221E73F825974", "url": "https://www.google.com/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 132169 }, "id": "auto-http-0X131221E73F825974", @@ -47,6 +49,8 @@ "id": { "key": "auto-http-0X970CBD2F2102BFA8", "url": "http://www.google.com/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 118727 }, "id": "auto-http-0X970CBD2F2102BFA8", @@ -89,6 +93,8 @@ "id": { "key": "auto-http-0X9CB71300ABD5A2A8", "url": "https://www.github.com/" }, "ping": { "timestamp": "2019-01-28T18:43:15.077Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 247244 }, "id": "auto-http-0X9CB71300ABD5A2A8", @@ -131,6 +137,8 @@ "id": { "key": "auto-http-0XC9CDA429418EDC2B", "url": "https://www.wikipedia.org/" }, "ping": { "timestamp": "2019-01-28T18:42:55.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 1164812 }, "id": "auto-http-0XC9CDA429418EDC2B", @@ -173,6 +181,8 @@ "id": { "key": "auto-http-0XD9AE729FC1C1E04A", "url": "http://www.reddit.com/" }, "ping": { "timestamp": "2019-01-28T18:43:13.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 299586 }, "id": "auto-http-0XD9AE729FC1C1E04A", @@ -215,6 +225,8 @@ "id": { "key": "auto-http-0XDD2D4E60FD4A61C3", "url": "https://www.elastic.co" }, "ping": { "timestamp": "2019-01-28T18:43:13.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 850870 }, "id": "auto-http-0XDD2D4E60FD4A61C3", @@ -257,6 +269,8 @@ "id": { "key": "auto-http-0XE3B163481423197D", "url": "https://news.google.com/" }, "ping": { "timestamp": "2019-01-28T18:42:55.074Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 2059606 }, "id": "auto-http-0XE3B163481423197D", @@ -299,6 +313,8 @@ "id": { "key": "auto-tcp-0X81440A68E839814C", "url": "tcp://localhost:9200" }, "ping": { "timestamp": "2019-01-28T18:43:16.078Z", + "container": null, + "kubernetes": null, "monitor": { "duration": { "us": 3328 }, "id": "auto-tcp-0X81440A68E839814C",