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

[Perfomance] Add is_initial_load meta #206645

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function trackPerformanceMeasureEntries(analytics: AnalyticsClient, isDev
target,
query_range_secs: meta?.queryRangeSecs,
query_offset_secs: meta?.queryOffsetSecs,
is_initial_load: meta?.isInitialLoad,
},
});
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import { EventData } from '../performance_context';
interface PerformanceMeta {
queryRangeSecs: number;
queryOffsetSecs: number;
isInitialLoad: boolean;
}

export function measureInteraction() {
performance.mark(perfomanceMarkers.startPageChange);
const trackedRoutes: string[] = [];
const trackedRoutes = new Set<string>();
Copy link
Member

Choose a reason for hiding this comment

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

Q: Do we remove the tracked routes at any point?

Aside from a potential memory leak, what happens if the user goes elsewhere in Kibana and comes back?

Would it be enough if trackedRoutes (Set<string>) is actually currentPathname (string)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The trackedRoutes updates with each route change. If the user navigates to another page (e.g., the services page) and then returns, trackedRoutes will be empty.

The objective is to determine whether the current load is due to navigation (an initial load) or a page refresh. Happy to update it if you have a better approach.

Not sure I understand the following, can you explain please

Would it be enough if trackedRoutes (Set) is actually currentPathname (string)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Tracking currentPathname or plugin url would be better, see comment.


return {
/**
* Marks the end of the page ready state and measures the performance between the start of the page change and the end of the page ready state.
Expand All @@ -46,22 +48,21 @@ export function measureInteraction() {
queryRangeSecs: getTimeDifferenceInSeconds(dateRangesInEpoch),
queryOffsetSecs:
rangeTo === 'now' ? 0 : getOffsetFromNowInSeconds(dateRangesInEpoch.endDate),
isInitialLoad: !trackedRoutes.has(pathname),
};
}

if (!trackedRoutes.includes(pathname)) {
performance.measure(pathname, {
detail: {
eventName: 'kibana:plugin_render_time',
type: 'kibana:performance',
customMetrics: eventData?.customMetrics,
meta: performanceMeta,
},
start: perfomanceMarkers.startPageChange,
end: perfomanceMarkers.endPageReady,
});
trackedRoutes.push(pathname);
}
performance.measure(pathname, {
detail: {
eventName: 'kibana:plugin_render_time',
type: 'kibana:performance',
customMetrics: eventData?.customMetrics,
meta: performanceMeta,
},
start: perfomanceMarkers.startPageChange,
end: perfomanceMarkers.endPageReady,
});
trackedRoutes.add(pathname);
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('measureInteraction', () => {
meta: {
queryRangeSecs: 900,
queryOffsetSecs: 0,
isInitialLoad: true,
},
},
end: 'end::pageReady',
Expand Down Expand Up @@ -88,6 +89,7 @@ describe('measureInteraction', () => {
meta: {
queryRangeSecs: 1800,
queryOffsetSecs: 0,
isInitialLoad: true,
},
},
end: 'end::pageReady',
Expand Down Expand Up @@ -115,6 +117,7 @@ describe('measureInteraction', () => {
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: -1800,
isInitialLoad: true,
},
},
end: 'end::pageReady',
Expand Down Expand Up @@ -142,20 +145,40 @@ describe('measureInteraction', () => {
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: 1800,
isInitialLoad: true,
},
},
end: 'end::pageReady',
start: 'start::pageChange',
});
});

it('should not measure the same route twice', () => {
it('should set isInitialLoad to false on subsequent pageReady calls', () => {
const interaction = measureInteraction();
const pathname = '/test-path';
jest.spyOn(global.Date, 'now').mockReturnValue(1733704200000); // 2024-12-09T00:30:00Z

interaction.pageReady(pathname);
interaction.pageReady(pathname);
const eventData = {
meta: { rangeFrom: '2024-12-08T01:00:00Z', rangeTo: '2024-12-09T01:00:00Z' },
};

expect(performance.measure).toHaveBeenCalledTimes(1);
interaction.pageReady(pathname, eventData);
interaction.pageReady(pathname, eventData);

expect(performance.mark).toHaveBeenCalledWith(perfomanceMarkers.endPageReady);
expect(performance.measure).toHaveBeenCalledWith(pathname, {
detail: {
eventName: 'kibana:plugin_render_time',
type: 'kibana:performance',
customMetrics: undefined,
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: 1800,
isInitialLoad: false,
},
},
end: 'end::pageReady',
start: 'start::pageChange',
});
});
});