forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Average mobile app launch (elastic#170773)
## Summary Enabled the "Average app load time" panel in the mobile dashboard. ![Screenshot 2023-11-08 at 18 35 12](https://github.com/elastic/kibana/assets/56847527/4ae1b05b-d71b-47e2-9f11-a884251de975) ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Katerina <kate@kpatticha.com>
- Loading branch information
1 parent
e252b85
commit 5c44377
Showing
7 changed files
with
200 additions
and
15 deletions.
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
161 changes: 161 additions & 0 deletions
161
x-pack/plugins/apm/server/routes/mobile/get_mobile_average_launch_time.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,161 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ProcessorEvent } from '@kbn/observability-plugin/common'; | ||
import { | ||
kqlQuery, | ||
rangeQuery, | ||
termQuery, | ||
} from '@kbn/observability-plugin/server'; | ||
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate'; | ||
import { APP_LAUNCH_TIME, SERVICE_NAME } from '../../../common/es_fields/apm'; | ||
import { environmentQuery } from '../../../common/utils/environment_query'; | ||
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms'; | ||
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client'; | ||
import { getBucketSize } from '../../../common/utils/get_bucket_size'; | ||
import { Coordinate } from '../../../typings/timeseries'; | ||
import { Maybe } from '../../../typings/common'; | ||
|
||
export interface AvgLaunchTimeTimeseries { | ||
currentPeriod: { timeseries: Coordinate[]; value: Maybe<number> }; | ||
previousPeriod: { timeseries: Coordinate[]; value: Maybe<number> }; | ||
} | ||
|
||
interface Props { | ||
apmEventClient: APMEventClient; | ||
serviceName: string; | ||
transactionName?: string; | ||
environment: string; | ||
start: number; | ||
end: number; | ||
kuery: string; | ||
offset?: string; | ||
} | ||
|
||
async function getAvgLaunchTimeTimeseries({ | ||
apmEventClient, | ||
serviceName, | ||
transactionName, | ||
environment, | ||
start, | ||
end, | ||
kuery, | ||
offset, | ||
}: Props) { | ||
const { startWithOffset, endWithOffset } = getOffsetInMs({ | ||
start, | ||
end, | ||
offset, | ||
}); | ||
|
||
const { intervalString } = getBucketSize({ | ||
start: startWithOffset, | ||
end: endWithOffset, | ||
minBucketSize: 60, | ||
}); | ||
|
||
const aggs = { | ||
launchTimeAvg: { | ||
avg: { field: APP_LAUNCH_TIME }, | ||
}, | ||
}; | ||
|
||
const response = await apmEventClient.search('get_mobile_launch_time', { | ||
apm: { | ||
events: [ProcessorEvent.metric], | ||
}, | ||
body: { | ||
track_total_hits: false, | ||
size: 0, | ||
query: { | ||
bool: { | ||
filter: [ | ||
...termQuery(SERVICE_NAME, serviceName), | ||
...rangeQuery(startWithOffset, endWithOffset), | ||
...environmentQuery(environment), | ||
...kqlQuery(kuery), | ||
], | ||
}, | ||
}, | ||
aggs: { | ||
timeseries: { | ||
date_histogram: { | ||
field: '@timestamp', | ||
fixed_interval: intervalString, | ||
min_doc_count: 0, | ||
extended_bounds: { min: startWithOffset, max: endWithOffset }, | ||
}, | ||
aggs, | ||
}, | ||
...aggs, | ||
}, | ||
}, | ||
}); | ||
|
||
const timeseries = | ||
response?.aggregations?.timeseries.buckets.map((bucket) => { | ||
return { | ||
x: bucket.key, | ||
y: bucket.launchTimeAvg.value, | ||
}; | ||
}) ?? []; | ||
|
||
return { | ||
timeseries, | ||
value: response.aggregations?.launchTimeAvg?.value, | ||
}; | ||
} | ||
|
||
export async function getMobileAvgLaunchTime({ | ||
kuery, | ||
apmEventClient, | ||
serviceName, | ||
transactionName, | ||
environment, | ||
start, | ||
end, | ||
offset, | ||
}: Props): Promise<AvgLaunchTimeTimeseries> { | ||
const options = { | ||
serviceName, | ||
transactionName, | ||
apmEventClient, | ||
kuery, | ||
environment, | ||
}; | ||
|
||
const currentPeriodPromise = getAvgLaunchTimeTimeseries({ | ||
...options, | ||
start, | ||
end, | ||
}); | ||
|
||
const previousPeriodPromise = offset | ||
? getAvgLaunchTimeTimeseries({ | ||
...options, | ||
start, | ||
end, | ||
offset, | ||
}) | ||
: { timeseries: [], value: null }; | ||
|
||
const [currentPeriod, previousPeriod] = await Promise.all([ | ||
currentPeriodPromise, | ||
previousPeriodPromise, | ||
]); | ||
|
||
return { | ||
currentPeriod, | ||
previousPeriod: { | ||
timeseries: offsetPreviousPeriodCoordinates({ | ||
currentPeriodTimeseries: currentPeriod.timeseries, | ||
previousPeriodTimeseries: previousPeriod.timeseries, | ||
}), | ||
value: previousPeriod?.value, | ||
}, | ||
}; | ||
} |
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
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