Skip to content

Commit

Permalink
[Uptime] Only show ~latest checks on certs page/alert (#66349)
Browse files Browse the repository at this point in the history
* [Uptime] Only show ~latest checks on certs page/alert

Fixes elastic/uptime#199

Also fixes some duplicate constants used in the queries here.

For default index we just use a literal `0` now since there's no way that'd
ever change.

* Change window to 5m

* Fix dependency issues in FTR suite for certs page.

* Ensures tests can run independently, and always navigate to the certs
page
* Ensures that the not_after field is consistent
* Ensures that timespan field is always present in checked documents
  • Loading branch information
andrewvc authored May 14, 2020
1 parent 9e6ebc5 commit d2381eb
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 40 deletions.
6 changes: 2 additions & 4 deletions x-pack/plugins/uptime/server/lib/alerts/tls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import { updateState } from './common';
import { ACTION_GROUP_DEFINITIONS, DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants';
import { Cert, CertResult } from '../../../common/runtime_types';
import { commonStateTranslations, tlsTranslations } from './translations';
import { DEFAULT_FROM, DEFAULT_TO } from '../../rest_api/certs/certs';

const { TLS } = ACTION_GROUP_DEFINITIONS;

const DEFAULT_FROM = 'now-1d';
const DEFAULT_TO = 'now';
const DEFAULT_INDEX = 0;
const DEFAULT_SIZE = 20;

interface TlsAlertState {
Expand Down Expand Up @@ -113,7 +111,7 @@ export const tlsAlertFactory: UptimeAlertTypeFactory = (_server, libs) => ({
dynamicSettings,
from: DEFAULT_FROM,
to: DEFAULT_TO,
index: DEFAULT_INDEX,
index: 0,
size: DEFAULT_SIZE,
notValidAfter: `now+${dynamicSettings?.certExpirationThreshold ??
DYNAMIC_SETTINGS_DEFAULTS.certExpirationThreshold}d`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('getCerts', () => {
},
Object {
"range": Object {
"@timestamp": Object {
"monitor.timespan": Object {
"gte": "now-2d",
"lte": "now+1h",
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/server/lib/requests/get_certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const getCerts: UMElasticsearchQueryFn<GetCertsParams, CertResult> = asyn
},
{
range: {
'@timestamp': {
'monitor.timespan': {
gte: from,
lte: to,
},
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/uptime/server/rest_api/certs/certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { API_URLS } from '../../../common/constants';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';

const DEFAULT_INDEX = 0;
export const DEFAULT_FROM = 'now-5m';
export const DEFAULT_TO = 'now';

const DEFAULT_SIZE = 25;
const DEFAULT_FROM = 'now-1d';
const DEFAULT_TO = 'now';
const DEFAULT_SORT = 'not_after';
const DEFAULT_DIRECTION = 'asc';

Expand All @@ -31,7 +31,7 @@ export const createGetCertsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) =
}),
},
handler: async ({ callES, dynamicSettings }, _context, request, response): Promise<any> => {
const index = request.query?.index ?? DEFAULT_INDEX;
const index = request.query?.index ?? 0;
const size = request.query?.size ?? DEFAULT_SIZE;
const from = request.query?.from ?? DEFAULT_FROM;
const to = request.query?.to ?? DEFAULT_TO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const makePing = async (
refresh: boolean = true,
tls: boolean | TlsProps = false
) => {
const timestamp = new Date();
const baseDoc: any = {
tcp: {
rtt: {
Expand All @@ -40,7 +41,7 @@ export const makePing = async (
ephemeral_id: '0d9a8dc6-f604-49e3-86a0-d8f9d6f2cbad',
version: '8.0.0',
},
'@timestamp': new Date().toISOString(),
'@timestamp': timestamp.toISOString(),
resolve: {
rtt: {
us: 350,
Expand Down Expand Up @@ -88,6 +89,10 @@ export const makePing = async (
check_group: uuid.v4(),
type: 'http',
status: 'up',
timespan: {
gte: timestamp.toISOString(),
lt: new Date(timestamp.getTime() + 5000).toISOString,
},
},
event: {
dataset: 'uptime',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const makeTls = ({ valid = true, commonName = '*.elastic.co', expiry, sha
server: {
x509: {
not_before: '2020-03-01T00:00:00.000Z',
not_after: '2020-05-30T12:00:00.000Z',
not_after: expiryDate,
issuer: {
distinguished_name:
'CN=DigiCert SHA2 High Assurance Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US',
Expand Down
58 changes: 30 additions & 28 deletions x-pack/test/functional/apps/uptime/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

const es = getService('es');

// FLAKY: https://github.com/elastic/kibana/issues/65010
describe.skip('certificate page', function() {
before(async () => {
await uptime.goToRoot(true);
});

describe('certificates', function() {
beforeEach(async () => {
await uptime.goToRoot(true);
await makeCheck({ es, tls: true });
await uptimeService.navigation.refreshApp();
});
Expand All @@ -30,33 +26,39 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await uptimeService.navigation.goToCertificates();
});

it('displays certificates', async () => {
await uptimeService.cert.hasCertificates();
});
describe('page', () => {
beforeEach(async () => {
await uptimeService.navigation.goToCertificates();
});

it('displays specific certificates', async () => {
const certId = getSha256();
const { monitorId } = await makeCheck({
es,
tls: {
sha256: certId,
},
it('displays certificates', async () => {
await uptimeService.cert.hasCertificates();
});

await uptimeService.navigation.refreshApp();
await uptimeService.cert.certificateExists({ certId, monitorId });
});
it('displays specific certificates', async () => {
const certId = getSha256();
const { monitorId } = await makeCheck({
es,
tls: {
sha256: certId,
},
});

it('performs search against monitor id', async () => {
const certId = getSha256();
const { monitorId } = await makeCheck({
es,
tls: {
sha256: certId,
},
await uptimeService.navigation.refreshApp();
await uptimeService.cert.certificateExists({ certId, monitorId });
});

it('performs search against monitor id', async () => {
const certId = getSha256();
const { monitorId } = await makeCheck({
es,
tls: {
sha256: certId,
},
});
await uptimeService.navigation.refreshApp();
await uptimeService.cert.searchIsWorking(monitorId);
});
await uptimeService.navigation.refreshApp();
await uptimeService.cert.searchIsWorking(monitorId);
});
});
};

0 comments on commit d2381eb

Please sign in to comment.