Skip to content

Commit

Permalink
[Uptime] Fix Telemetry Api flaky test (elastic#67358)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
shahzad31 and elasticmachine authored Jun 4, 2020
1 parent 6195f3e commit 8e74275
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export class KibanaTelemetryAdapter {
});
}

public static clearLocalTelemetry() {
this.collector = {};
}

public static countPageView(pageView: PageViewParams) {
if (pageView.refreshTelemetryHistory) {
this.collector = {};
}
const bucketId = this.getBucketToIncrement();
const bucket = this.collector[bucketId];
if (pageView.page === 'Overview') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ export const createLogPageViewRoute: UMRestApiRouteFactory = () => ({
request,
response
): Promise<any> => {
const pageView = request.body as PageViewParams;
if (pageView.refreshTelemetryHistory) {
KibanaTelemetryAdapter.clearLocalTelemetry();
}
await KibanaTelemetryAdapter.countNoOfUniqueMonitorAndLocations(callES, savedObjectsClient);
const pageViewResult = KibanaTelemetryAdapter.countPageView(request.body as PageViewParams);
const pageViewResult = KibanaTelemetryAdapter.countPageView(pageView as PageViewParams);

return response.ok({
body: pageViewResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ export default function ({ getService }: FtrProviderContext) {
);

await makeChecksWithStatus(es, 'mixMonitorId', 1, 1, 1, { observer: observer2 }, 'down');
await es.indices.refresh();
});

after('unload heartbeat index', () => getService('esArchiver').unload('uptime/blank'));

it('should receive expected results after calling monitor/overview logging', async () => {
beforeEach(async () => {
await es.indices.refresh();
});

it('should receive expected results after calling monitor logging', async () => {
// call monitor page
await supertest
const { body: result } = await supertest
.post(API_URLS.LOG_PAGE_VIEW)
.set('kbn-xsrf', 'true')
.send({
Expand All @@ -97,6 +102,23 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(200);

expect(result).to.eql({
overview_page: 0,
monitor_page: 1,
no_of_unique_monitors: 4,
settings_page: 0,
monitor_frequency: [120, 0.001, 60, 60],
monitor_name_stats: { min_length: 7, max_length: 22, avg_length: 12 },
no_of_unique_observer_locations: 3,
observer_location_name_stats: { min_length: 2, max_length: 7, avg_length: 4.8 },
dateRangeStart: ['now/d'],
dateRangeEnd: ['now/d'],
autoRefreshEnabled: true,
autorefreshInterval: [100],
});
});

it('should receive expected results after calling overview logging', async () => {
// call overview page
const { body: result } = await supertest
.post(API_URLS.LOG_PAGE_VIEW)
Expand Down

0 comments on commit 8e74275

Please sign in to comment.