kibana/packages/kbn-io-ts-utils
Katerina bd1c00fd65
[Perfomance] Track time range picker with onPageReady function (#202889)
## Summary

closes https://github.com/elastic/observability-dev/issues/3377
## Metrics 
#### `meta.query_range_secs` - The duration of the selected time range
in seconds.
#### `meta.query_offset_secs` - The offset from "now" to the
'rangeTo'/end' time picker value in seconds.

____

Extend the `onPageReady` function to support date ranges in the meta
field. The function should compute the query range in seconds based on
the provided time range and report it to telemetry as
meta.query_range_secs.




If the `rangeTo` is different from 'now', calculate the offset. 
- A negative offset indicates that the rangeTo is in the past, 
- a positive offset means it is in the future, 
- and zero indicates that the rangeTo is exactly 'now'." 



### How to instrument
To report the selected time range, pass the `rangeFrom` and `rangeTo` . 
> Failing to pass the correct type will result in TS error.


Then, use this data when invoking onPageReady:
```
 onPageReady({
        meta: { rangeFrom, rangeTo },
 });
```

### Analysis 

Meta is flatten field. In order to aggregate the data it's necessary to
create a run time field. You can add a field in the

1. select data view (`ebt-kibana-*-performance-metrics`) 
2. Add a new field
3. Type double
4. Set value 

`query_range_secs`
```
def meta = doc[“meta”].size();
if (meta > 0) {
    def range = doc[“meta.query_range_secs”].size();
    if (range > 0) {
        // Emit the value of ‘meta.target’
        emit(Double.parseDouble(doc[“meta.query_range_secs”].value));
    }
}

```

`query_offset_secs` 
```

def meta = doc[“meta”].size();
if (meta > 0) {
    def offset = doc[“meta.query_offset_secs”].size();
    if (offset > 0) {
     
        emit(Double.parseDouble(doc[“meta.query_offset_secs”].value));
    }
}

```







### Examples


<img width="1478" alt="Screenshot 2024-12-09 at 19 51 32"
src="https://github.com/user-attachments/assets/72f796e1-4f20-487f-b62a-b6a4aead9a4a">

<img width="1478" alt="Screenshot 2024-12-09 at 19 56 08"
src="https://github.com/user-attachments/assets/c278dc3b-e6f3-47ed-9c90-954d71b59161">

<img width="1478" alt="Screenshot 2024-12-09 at 19 53 45 1"
src="https://github.com/user-attachments/assets/ef42ecef-48cd-4396-9f5d-c971098d5219">





### Notes
- Instrumented only 2 solutions as an example (dataset and apm services)

### TODO
- [x] Update documentation -
https://github.com/elastic/kibana/pull/204179
- [ ] Update dashboards (create a runtime field) 
- [x] Track offset ( we need to know if the user selected now or now)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2024-12-13 07:11:44 -06:00
..
BUILD.bazel [Perfomance] Track time range picker with onPageReady function (#202889) 2024-12-13 07:11:44 -06:00