Skip to content

Commit

Permalink
[7.3] [Uptime] Handle mode: all in uptime snapshot calculation (#41335
Browse files Browse the repository at this point in the history
) (#41423)

* [Uptime] Handle `mode: all` in uptime snapshot calculation (#41335)

Patching this function in #41210 fixed performance but was missing this filter clause. We depend on only processing summary info. This fixes errors around missing destructured data where we expect summary fields to be present.

* Update snapshot to use heartbeat7.0.0 index for backport
  • Loading branch information
andrewvc committed Jul 18, 2019
1 parent a79f418 commit c384d60
Show file tree
Hide file tree
Showing 31 changed files with 5,385 additions and 1,315 deletions.
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/uptime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ In another shell, from **~kibana/x-pack**:
#### API tests

If instead you need to run API tests, start up the test server and then in another shell, from **~kibana/x-pack**:

`node ../scripts/functional_test_runner.js --config test/api_integration/config.js --grep="{TEST_NAME}"`.

You can update snapshots by prefixing the runner command with `env UPDATE_UPTIME_FIXTURES=1`

You can access the functional test server's Kibana at `http://localhost:5620/`.

You can login with username `elastic` and password `changeme` by default.

If you want to freeze a UI or API test you can include an async call like `await new Promise(r => setTimeout(r, 1000 * 60))`
to freeze the execution for 60 seconds if you need to click around or check things in the state that is loaded.

Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ export class ElasticsearchMonitorsAdapter implements UMMonitorsAdapter {
const params = {
index: INDEX_NAMES.HEARTBEAT,
body: {
query,
query: {
bool: {
filter: [{ exists: { field: 'summary.up' } }, query],
},
},
size: 0,
aggs: {
ids: {
Expand Down
14 changes: 5 additions & 9 deletions x-pack/test/api_integration/apis/uptime/graphql/error_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { errorListQueryString } from '../../../../../legacy/plugins/uptime/public/queries';
import errorList from './fixtures/error_list';
import errorListFilteredById from './fixtures/error_list_filtered_by_id';
import errorListFilteredByPort from './fixtures/error_list_filtered_by_port';
import errorListFilteredByPortAndType from './fixtures/error_list_filtered_by_port_and_type';
import { expectFixtureEql } from './expect_fixture_eql';

export default function ({ getService }) {
describe('errorList query', () => {
Expand All @@ -30,7 +26,7 @@ export default function ({ getService }) {
.post('/api/uptime/graphql')
.set('kbn-xsrf', 'foo')
.send({ ...getErrorListQuery });
expect(data).to.eql(errorList);
expectFixtureEql(data, 'error_list');
});

it('returns an error list filtered by monitor id', async () => {
Expand All @@ -49,7 +45,7 @@ export default function ({ getService }) {
.post('/api/uptime/graphql')
.set('kbn-xsrf', 'foo')
.send({ ...getErrorListQuery });
expect(data).to.eql(errorListFilteredById);
expectFixtureEql(data, 'error_list_filtered_by_id');
});

it('returns an error list filtered by port', async () => {
Expand All @@ -68,7 +64,7 @@ export default function ({ getService }) {
.post('/api/uptime/graphql')
.set('kbn-xsrf', 'foo')
.send({ ...getErrorListQuery });
expect(data).to.eql(errorListFilteredByPort);
expectFixtureEql(data, 'error_list_filtered_by_port');
});

it('returns an error list filtered by port/type', async () => {
Expand All @@ -89,7 +85,7 @@ export default function ({ getService }) {
.post('/api/uptime/graphql')
.set('kbn-xsrf', 'foo')
.send({ ...getErrorListQuery });
expect(data).to.eql(errorListFilteredByPortAndType);
expectFixtureEql(data, 'error_list_filtered_by_port_and_type');
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 expect from '@kbn/expect';
import fs from 'fs';
import { join } from 'path';

const fixturesDir = join(__dirname, 'fixtures');

export const expectFixtureEql = (data: any, fixtureName: string) => {
const fixturePath = join(fixturesDir, `${fixtureName}.json`);
if (process.env.UPDATE_UPTIME_FIXTURES) {
fs.writeFileSync(fixturePath, JSON.stringify(data, null, 2));
}
const fixture = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
expect(data).to.eql(fixture);
};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "statesIndexStatus": { "docCount": { "count": 9231 }, "indexExists": true } }
{ "statesIndexStatus": { "docCount": { "count": 9234 }, "indexExists": true } }
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "io"
},
{
"count": 748,
"count": 749,
"latestMessage": "dial tcp 127.0.0.1:9200: connect: connection refused",
"location": null,
"monitorId": "auto-tcp-0X81440A68E839814C",
Expand Down Expand Up @@ -41,4 +41,4 @@
"type": "io"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"type": "io"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"errorList": [
{
"count": 748,
"count": 749,
"latestMessage": "dial tcp 127.0.0.1:9200: connect: connection refused",
"location": null,
"monitorId": "auto-tcp-0X81440A68E839814C",
Expand All @@ -11,4 +11,4 @@
"type": "io"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"type": "io"
}
]
}
}
Loading

0 comments on commit c384d60

Please sign in to comment.