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] Handle mode: all in uptime snapshot calculation #41335

Merged
merged 8 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/uptime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ In another shell, from **~kibana/x-pack**:
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.
Expand Down
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! This is along the lines of the solution I was planning to use to address this.

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