[Performance] Refactor TTFMP query from, to fields (#213911)

Currently Kibana forwards `query_range_secs` and `query_offset_secs` to
mark the selected time range when reporting TTFMP event. This format
caused some challenges to identify `from`, `to` date offsets in
visualizations.

To simplify, the PR renames and sends the three fields explicitly:
- `query_from_offset_secs` offset to `0` (now), with -ve for past and
+ve for future dates
- `query_to_offset_secs` offset to `0` (now), with -ve for past and +ve
for future dates
- `query_range_secs`                      same as previously sent

_This approach is followed after a discussion, and based on the
[gist](https://gist.github.com/andrewvc/1f04a57a336d768e4ec5ff2eff06ba54)
excerpt:_

```
Earliest date -> QueryFrom
Newest date -> QueryTo
Duration -> QueryRange
```

### Indexing
These fields then should be mapped in the EBT indexer to ingest in the
top level of the document, eventually removing the need to create
runtime fields in data views for visualizations.

Also, runtime fields in data views should be updated to reflect this
change. For backward compatibility, the runtime fields can cater both
the old and new field names conditionally.

### Testing
- Ensure that the TTFMP events are correctly reporting the date ranges.

### Example

![image](https://github.com/user-attachments/assets/529507fc-66f7-440a-8bbb-b34176e8d093)
This commit is contained in:
Abdul Wahab Zahid 2025-03-20 11:40:24 +01:00 committed by GitHub
parent 48b286e460
commit e6e78ac6d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 16 deletions

View file

@ -330,8 +330,9 @@ This will be indexed as:
"duration": 736, // Event duration as specified when reporting it
"meta": {
"target": '/home',
"query_range_secs": 900
"query_offset_secs": 0 // now
"query_range_secs": 900, // 15 minutes
"query_from_offset_secs": -900 // From 15 minutes ago
"query_to_offset_secs": 0 // To now
},
"context": { // Context holds information identifying the deployment, version, application and page that generated the event
"version": "8.16.0-SNAPSHOT",

View file

@ -117,7 +117,8 @@ describe('trackPerformanceMeasureEntries', () => {
meta: {
isInitialLoad: true,
queryRangeSecs: 86400,
queryOffsetSecs: 0,
queryFromOffsetSecs: -86400,
queryToOffsetSecs: 0,
},
},
},
@ -129,7 +130,12 @@ describe('trackPerformanceMeasureEntries', () => {
duration: 1000,
eventName: 'kibana:plugin_render_time',
key1: 'key1',
meta: { is_initial_load: true, query_range_secs: 86400, query_offset_secs: 0 },
meta: {
is_initial_load: true,
query_range_secs: 86400,
query_from_offset_secs: -86400,
query_to_offset_secs: 0,
},
value1: 'value1',
});
});
@ -146,7 +152,8 @@ describe('trackPerformanceMeasureEntries', () => {
type: 'kibana:performance',
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: 0,
queryFromOffsetSecs: -86400,
queryToOffsetSecs: 0,
},
},
},
@ -159,7 +166,8 @@ describe('trackPerformanceMeasureEntries', () => {
eventName: 'kibana:plugin_render_time',
meta: {
query_range_secs: 86400,
query_offset_secs: 0,
query_from_offset_secs: -86400,
query_to_offset_secs: 0,
},
});
});
@ -191,7 +199,8 @@ describe('trackPerformanceMeasureEntries', () => {
meta: {
is_initial_load: false,
query_range_secs: undefined,
query_offset_secs: undefined,
query_from_offset_secs: undefined,
query_to_offset_secs: undefined,
description:
'[ttfmp_dependencies] onPageReady is called when the most important content is rendered',
},
@ -227,7 +236,8 @@ describe('trackPerformanceMeasureEntries', () => {
meta: {
is_initial_load: false,
query_range_secs: undefined,
query_offset_secs: undefined,
query_from_offset_secs: undefined,
query_to_offset_secs: undefined,
description: truncatedDescription,
},
});

View file

@ -83,7 +83,8 @@ export function trackPerformanceMeasureEntries(analytics: AnalyticsClient, isDev
...customMetrics,
meta: {
query_range_secs: meta?.queryRangeSecs,
query_offset_secs: meta?.queryOffsetSecs,
query_from_offset_secs: meta?.queryFromOffsetSecs,
query_to_offset_secs: meta?.queryToOffsetSecs,
description: description?.slice(0, MAX_DESCRIPTION_LENGTH),
is_initial_load: meta?.isInitialLoad,
},

View file

@ -18,7 +18,8 @@ import { DescriptionWithPrefix } from '../types';
interface PerformanceMeta {
queryRangeSecs?: number;
queryOffsetSecs?: number;
queryFromOffsetSecs?: number;
queryToOffsetSecs?: number;
isInitialLoad?: boolean;
description?: DescriptionWithPrefix;
}
@ -46,7 +47,9 @@ export function measureInteraction(pathname: string) {
});
performanceMeta.queryRangeSecs = getTimeDifferenceInSeconds(dateRangesInEpoch);
performanceMeta.queryOffsetSecs =
performanceMeta.queryFromOffsetSecs =
rangeFrom === 'now' ? 0 : getOffsetFromNowInSeconds(dateRangesInEpoch.startDate);
performanceMeta.queryToOffsetSecs =
rangeTo === 'now' ? 0 : getOffsetFromNowInSeconds(dateRangesInEpoch.endDate);
}

View file

@ -74,7 +74,8 @@ describe('measureInteraction', () => {
customMetrics: eventData.customMetrics,
meta: {
queryRangeSecs: 900,
queryOffsetSecs: 0,
queryFromOffsetSecs: -900,
queryToOffsetSecs: 0,
isInitialLoad: true,
},
},
@ -102,7 +103,8 @@ describe('measureInteraction', () => {
customMetrics: undefined,
meta: {
queryRangeSecs: 1800,
queryOffsetSecs: 0,
queryFromOffsetSecs: -1800,
queryToOffsetSecs: 0,
isInitialLoad: true,
},
},
@ -130,7 +132,8 @@ describe('measureInteraction', () => {
customMetrics: undefined,
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: -1800,
queryFromOffsetSecs: -88200,
queryToOffsetSecs: -1800,
isInitialLoad: true,
},
},
@ -159,7 +162,8 @@ describe('measureInteraction', () => {
customMetrics: undefined,
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: 1800,
queryFromOffsetSecs: -84600,
queryToOffsetSecs: 1800,
isInitialLoad: true,
},
},
@ -198,7 +202,8 @@ describe('measureInteraction', () => {
customMetrics: undefined,
meta: {
queryRangeSecs: 86400,
queryOffsetSecs: 1800,
queryFromOffsetSecs: -84600,
queryToOffsetSecs: 1800,
isInitialLoad: false,
},
},