-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[APM] Mobile most launches #168925
[APM] Mobile most launches #168925
Changes from 21 commits
ebc8f05
e8fb0fe
cbcdff1
e67c0d0
2cb6a0d
f2acd01
c4da8f4
84fe444
700db7a
5c8b70b
4e9b616
75f759e
ac0be49
8ed14d6
79e0a08
9fc934b
5ac126e
d8b1777
61cbdbf
2f249de
eea243d
5415f6f
50a5463
894437f
e17aca9
faae624
d1bbcfb
1697bbb
4516b20
8797da7
7b0195f
1f794c9
5cafe2f
fe3df19
4716f62
9749e39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ApmFields } from './apm_fields'; | ||
import { Serializable } from '../serializable'; | ||
|
||
export class Event extends Serializable<ApmFields> { | ||
constructor(fields: ApmFields) { | ||
super({ | ||
...fields, | ||
'event.kind': 'event', | ||
|
||
// Real log events don't have the "processor.event" attribute. See: https://github.com/elastic/apm-server/pull/11494 | ||
// This is a hack needed for the tests in "mobile/mobile_location_stats.spec.ts" to pass since the "SynthtraceEsClient.index" function | ||
// inside "packages/kbn-apm-synthtrace/src/lib/shared/base_client.ts" requires this "processor.event" attr to be available, | ||
// otherwise it'd throw this error: "Could not determine operation: _index and _action not defined in document". | ||
'processor.event': 'error', | ||
LikeTheSalad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
|
||
lifecycle(state: string): this { | ||
this.fields['labels.lifecycle_state'] = state; | ||
return this; | ||
} | ||
|
||
override timestamp(timestamp: number) { | ||
const ret = super.timestamp(timestamp); | ||
this.fields['timestamp.us'] = timestamp * 1000; | ||
return ret; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,111 @@ | ||||||||||
/* | ||||||||||
* 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 { | ||||||||||
kqlQuery, | ||||||||||
rangeQuery, | ||||||||||
termQuery, | ||||||||||
} from '@kbn/observability-plugin/server'; | ||||||||||
import { SERVICE_NAME } from '../../../common/es_fields/apm'; | ||||||||||
import { APMEventClient } from '../../lib/helpers/create_es_client/create_apm_event_client'; | ||||||||||
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms'; | ||||||||||
import { getBucketSize } from '../../../common/utils/get_bucket_size'; | ||||||||||
import { environmentQuery } from '../../../common/utils/environment_query'; | ||||||||||
|
||||||||||
interface Props { | ||||||||||
kuery: string; | ||||||||||
apmEventClient: APMEventClient; | ||||||||||
serviceName: string; | ||||||||||
environment: string; | ||||||||||
start: number; | ||||||||||
end: number; | ||||||||||
locationField?: string; | ||||||||||
offset?: string; | ||||||||||
} | ||||||||||
|
||||||||||
export async function getLaunchesByLocation({ | ||||||||||
kuery, | ||||||||||
apmEventClient, | ||||||||||
serviceName, | ||||||||||
environment, | ||||||||||
start, | ||||||||||
end, | ||||||||||
locationField, | ||||||||||
offset, | ||||||||||
}: Props) { | ||||||||||
const { startWithOffset, endWithOffset } = getOffsetInMs({ | ||||||||||
start, | ||||||||||
end, | ||||||||||
offset, | ||||||||||
}); | ||||||||||
|
||||||||||
const { intervalString } = getBucketSize({ | ||||||||||
start: startWithOffset, | ||||||||||
end: endWithOffset, | ||||||||||
minBucketSize: 60, | ||||||||||
}); | ||||||||||
|
||||||||||
const aggs = { | ||||||||||
launches: { | ||||||||||
filter: { | ||||||||||
terms: { ['labels.lifecycle_state']: ['created', 'active'] }, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Can you please convert Also, the values created and active can be enum. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've converted |
||||||||||
}, | ||||||||||
aggs: { | ||||||||||
byLocation: { | ||||||||||
terms: { | ||||||||||
field: locationField, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}; | ||||||||||
|
||||||||||
const response = await apmEventClient.logEventSearch( | ||||||||||
LikeTheSalad marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
'get_mobile_location_launches', | ||||||||||
{ | ||||||||||
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, | ||||||||||
}, | ||||||||||
aggs, | ||||||||||
}, | ||||||||||
...aggs, | ||||||||||
}, | ||||||||||
}, | ||||||||||
} | ||||||||||
); | ||||||||||
|
||||||||||
return { | ||||||||||
location: response.aggregations?.launches?.byLocation?.buckets[0] | ||||||||||
?.key as string, | ||||||||||
value: | ||||||||||
response.aggregations?.launches?.byLocation?.buckets[0]?.doc_count ?? 0, | ||||||||||
timeseries: | ||||||||||
response.aggregations?.timeseries?.buckets.map((bucket) => ({ | ||||||||||
x: bucket.key, | ||||||||||
y: | ||||||||||
response.aggregations?.launches?.byLocation?.buckets[0]?.doc_count ?? | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Otherwise, you'll always return the total launches for the timeseries. kibana/x-pack/plugins/apm/server/routes/mobile/get_mobile_http_requests_by_location.ts Line 115 in 1697bbb
can you please fix there as well 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also please add an API test to prevent this issue? It appears that our existing tests were insufficient in identifying this problem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @kpatticha - I've just made these changes, fixed the same issue for kibana/x-pack/plugins/apm/server/routes/mobile/get_mobile_crashes_by_location.ts Line 105 in 1697bbb
I've also updated the API test to verify the changes. It should be good now, cheers! |
||||||||||
0, | ||||||||||
})) ?? [], | ||||||||||
}; | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new field for mobile? What does it represent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for ways to narrow down generic logs to only the ones we send as "events" using OTel's event API and I noticed that the logs I was targeting have this
event.kind
field set toevent
, so that's why I used it. It seems to be an ECS field. However, I'm not sure if it's the best way to do what I needed, I recall @bryce-b mentioning that another alternative could be to use theevent.action
attr instead, which OTel sends asevent.name
, and we could filter it to this particular event name, which islifecycle
. Although things started to fail once I did the change so I reverted it back, but if that's a better option, I can spend some more time on it until it works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the clarification. Can you reach out to the apm-server team to verify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They mentioned that
event.kind
shouldn't be used for this use case, so I tried to replace it withevent.action
equals tolifecycle
but doing so broke the tests inmobile_location_stats.spec.ts
. I tried a couple of things to make them work withevent.action
without luck unfortunately. So in the end, I just removed all filters in this function, so that the only filters applied to the query would be the ones passed by the caller of thislogEventSearch
function. Which currently is only done in here where thelabels.lifecycle_state
term is passed as filter.