-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Fix synthetics detail step count #89940
Merged
justinkambic
merged 3 commits into
elastic:master
from
justinkambic:89560_step-count-sometimes-incorrect
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
x-pack/plugins/uptime/server/lib/requests/get_journey_steps.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
/* | ||
* 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 { getJourneySteps, formatSyntheticEvents } from './get_journey_steps'; | ||
import { getUptimeESMockClient } from './helper'; | ||
|
||
describe('getJourneySteps request module', () => { | ||
describe('formatStepTypes', () => { | ||
it('returns default steps if none are provided', () => { | ||
expect(formatSyntheticEvents()).toMatchInlineSnapshot(` | ||
Array [ | ||
"step/end", | ||
"stderr", | ||
"cmd/status", | ||
"step/screenshot", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns provided step array if isArray', () => { | ||
expect(formatSyntheticEvents(['step/end', 'stderr'])).toMatchInlineSnapshot(` | ||
Array [ | ||
"step/end", | ||
"stderr", | ||
] | ||
`); | ||
}); | ||
|
||
it('returns provided step string in an array', () => { | ||
expect(formatSyntheticEvents('step/end')).toMatchInlineSnapshot(` | ||
Array [ | ||
"step/end", | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
describe('getJourneySteps', () => { | ||
let data: any; | ||
beforeEach(() => { | ||
data = { | ||
body: { | ||
hits: { | ||
hits: [ | ||
{ | ||
_id: 'o6myXncBFt2V8m6r6z-r', | ||
_source: { | ||
'@timestamp': '2021-02-01T17:45:19.001Z', | ||
synthetics: { | ||
package_version: '0.0.1-alpha.8', | ||
journey: { | ||
name: 'inline', | ||
id: 'inline', | ||
}, | ||
step: { | ||
name: 'load homepage', | ||
index: 1, | ||
}, | ||
type: 'step/end', | ||
}, | ||
monitor: { | ||
name: 'My Monitor', | ||
id: 'my-monitor', | ||
check_group: '2bf952dc-64b5-11eb-8b3b-42010a84000d', | ||
type: 'browser', | ||
}, | ||
}, | ||
}, | ||
{ | ||
_id: 'IjqzXncBn2sjqrYxYoCG', | ||
_source: { | ||
'@timestamp': '2021-02-01T17:45:49.944Z', | ||
synthetics: { | ||
package_version: '0.0.1-alpha.8', | ||
journey: { | ||
name: 'inline', | ||
id: 'inline', | ||
}, | ||
step: { | ||
name: 'hover over products menu', | ||
index: 2, | ||
}, | ||
type: 'step/end', | ||
}, | ||
monitor: { | ||
name: 'My Monitor', | ||
timespan: { | ||
lt: '2021-02-01T17:46:49.945Z', | ||
gte: '2021-02-01T17:45:49.945Z', | ||
}, | ||
id: 'my-monitor', | ||
check_group: '2bf952dc-64b5-11eb-8b3b-42010a84000d', | ||
type: 'browser', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
it('formats ES result', async () => { | ||
const { esClient: mockEsClient, uptimeEsClient } = getUptimeESMockClient(); | ||
|
||
mockEsClient.search.mockResolvedValueOnce(data as any); | ||
const result: any = await getJourneySteps({ | ||
uptimeEsClient, | ||
checkGroup: '2bf952dc-64b5-11eb-8b3b-42010a84000d', | ||
}); | ||
expect(mockEsClient.search).toHaveBeenCalledTimes(1); | ||
const call: any = mockEsClient.search.mock.calls[0][0]; | ||
|
||
// check that default `synthetics.type` value is supplied, | ||
expect(call.body.query.bool.filter[0]).toMatchInlineSnapshot(` | ||
Object { | ||
"terms": Object { | ||
"synthetics.type": Array [ | ||
"step/end", | ||
"stderr", | ||
"cmd/status", | ||
"step/screenshot", | ||
], | ||
}, | ||
} | ||
`); | ||
|
||
// given check group is used for the terms filter | ||
expect(call.body.query.bool.filter[1]).toMatchInlineSnapshot(` | ||
Object { | ||
"term": Object { | ||
"monitor.check_group": "2bf952dc-64b5-11eb-8b3b-42010a84000d", | ||
}, | ||
} | ||
`); | ||
|
||
// should sort by step index, then timestamp | ||
expect(call.body.sort).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"synthetics.step.index": Object { | ||
"order": "asc", | ||
}, | ||
}, | ||
Object { | ||
"@timestamp": Object { | ||
"order": "asc", | ||
}, | ||
}, | ||
] | ||
`); | ||
|
||
expect(result).toHaveLength(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here explaining that we're testing the formatting? |
||
// `getJourneySteps` is responsible for formatting these fields, so we need to check them | ||
result.forEach((step: any) => { | ||
expect(['2021-02-01T17:45:19.001Z', '2021-02-01T17:45:49.944Z']).toContain(step.timestamp); | ||
expect(['o6myXncBFt2V8m6r6z-r', 'IjqzXncBn2sjqrYxYoCG']).toContain(step.docId); | ||
expect(step.synthetics.screenshotExists).toBeDefined(); | ||
}); | ||
}); | ||
|
||
it('notes screenshot exists when a document of type step/screenshot is included', async () => { | ||
const { esClient: mockEsClient, uptimeEsClient } = getUptimeESMockClient(); | ||
|
||
data.body.hits.hits[0]._source.synthetics.type = 'step/screenshot'; | ||
data.body.hits.hits[0]._source.synthetics.step.index = 2; | ||
mockEsClient.search.mockResolvedValueOnce(data as any); | ||
|
||
const result: any = await getJourneySteps({ | ||
uptimeEsClient, | ||
checkGroup: '2bf952dc-64b5-11eb-8b3b-42010a84000d', | ||
syntheticEventTypes: ['stderr', 'step/end'], | ||
}); | ||
|
||
const call: any = mockEsClient.search.mock.calls[0][0]; | ||
|
||
// assert that filters for only the provided step types are used | ||
expect(call.body.query.bool.filter[0]).toMatchInlineSnapshot(` | ||
Object { | ||
"terms": Object { | ||
"synthetics.type": Array [ | ||
"stderr", | ||
"step/end", | ||
], | ||
}, | ||
} | ||
`); | ||
|
||
expect(result).toHaveLength(1); | ||
expect(result[0].synthetics.screenshotExists).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to specify all the fields here? Most aren't related to this specific functionality. If it's to pass a type check there's probably not much we can do, but I've seen these get to be hard to maintain with all the extra data.