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

[Uptime] Add pod and container to monitor list query #35835

Merged
Show file tree
Hide file tree
Changes from 4 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
78 changes: 78 additions & 0 deletions x-pack/plugins/uptime/common/graphql/introspection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion x-pack/plugins/uptime/common/graphql/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
/* tslint:disable */

// ====================================================
// START: Typescript template
Expand Down Expand Up @@ -49,6 +49,8 @@ export interface Ping {
/** The agent that recorded the ping */
beat?: Beat | null;

container?: Container | null;

docker?: Docker | null;

ecs?: Ecs | null;
Expand Down Expand Up @@ -92,6 +94,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;

Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/uptime/public/queries/monitor_list_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export const monitorListQueryString = `
}
ping {
timestamp
container {
id
}
kubernetes {
pod {
uid
}
}
monitor {
duration {
us
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/uptime/server/graphql/pings/schema.gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
Expand Down Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading