Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Feb 23, 2021
1 parent 0ab0ea9 commit 5d34c65
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
PROFILE_TOP_ID,
SERVICE_NAME,
} from '../../../../common/elasticsearch_fieldnames';
import { rangeQuery, environmentQuery } from '../../../../common/utils/queries';
import {
rangeQuery,
environmentQuery,
kqlQuery,
} from '../../../../server/utils/queries';
import { APMEventClient } from '../../helpers/create_es_client/create_apm_event_client';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { withApmSpan } from '../../../utils/with_apm_span';
Expand Down Expand Up @@ -184,12 +188,14 @@ function getProfilesWithStacks({
}

export async function getServiceProfilingStatistics({
kuery,
serviceName,
setup,
environment,
valueType,
logger,
}: {
kuery?: string;
serviceName: string;
setup: Setup & SetupTimeRange;
environment?: string;
Expand All @@ -202,11 +208,11 @@ export async function getServiceProfilingStatistics({
const valueTypeField = getValueTypeConfig(valueType).field;

const filter: ESFilter[] = [
...rangeQuery(start, end),
{ term: { [SERVICE_NAME]: serviceName } },
...environmentQuery(environment),
{ exists: { field: valueTypeField } },
...setup.esFilter,
...rangeQuery(start, end),
...environmentQuery(environment),
...kqlQuery(kuery),
];

const [profileStats, profileStacks] = await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { mapKeys, mapValues } from 'lodash';
import { rangeQuery, environmentQuery } from '../../../../common/utils/queries';
import { rangeQuery, environmentQuery } from '../../../../server/utils/queries';
import { ProcessorEvent } from '../../../../common/processor_event';
import {
PROFILE_ID,
Expand All @@ -18,6 +18,7 @@ import {
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { getBucketSize } from '../../helpers/get_bucket_size';
import { withApmSpan } from '../../../utils/with_apm_span';
import { kqlQuery } from '../../../utils/queries';

const configMap = mapValues(
mapKeys(ProfilingValueType, (val, key) => val),
Expand All @@ -27,16 +28,18 @@ const configMap = mapValues(
const allFields = Object.values(configMap).map((config) => config.field);

export async function getServiceProfilingTimeline({
kuery,
serviceName,
environment,
setup,
}: {
kuery?: string;
serviceName: string;
setup: Setup & SetupTimeRange;
environment?: string;
}) {
return withApmSpan('get_service_profiling_timeline', async () => {
const { apmEventClient, start, end, esFilter } = setup;
const { apmEventClient, start, end } = setup;

const response = await apmEventClient.search({
apm: {
Expand All @@ -50,7 +53,7 @@ export async function getServiceProfilingTimeline({
{ term: { [SERVICE_NAME]: serviceName } },
...rangeQuery(start, end),
...environmentQuery(environment),
...esFilter,
...kqlQuery(kuery),
],
},
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/rum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const percentileRangeRt = t.partial({
maxPercentile: t.string,
});

export const uiFiltersRt = t.type({ uiFilters: t.string });
const uiFiltersRt = t.type({ uiFilters: t.string });

const uxQueryRt = t.intersection([
uiFiltersRt,
Expand Down
20 changes: 7 additions & 13 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,7 @@ export const serviceProfilingTimelineRoute = createRoute({
path: t.type({
serviceName: t.string,
}),
query: t.intersection([
rangeRt,
uiFiltersRt,
t.partial({
environment: t.string,
}),
]),
query: t.intersection([environmentRt, kueryRt, rangeRt]),
}),
options: {
tags: ['access:apm'],
Expand All @@ -526,10 +520,11 @@ export const serviceProfilingTimelineRoute = createRoute({

const {
path: { serviceName },
query: { environment },
query: { environment, kuery },
} = context.params;

return getServiceProfilingTimeline({
kuery,
setup,
serviceName,
environment,
Expand All @@ -544,11 +539,9 @@ export const serviceProfilingStatisticsRoute = createRoute({
serviceName: t.string,
}),
query: t.intersection([
environmentRt,
kueryRt,
rangeRt,
uiFiltersRt,
t.partial({
environment: t.string,
}),
t.type({
valueType: t.union([
t.literal(ProfilingValueType.wallTime),
Expand All @@ -570,10 +563,11 @@ export const serviceProfilingStatisticsRoute = createRoute({

const {
path: { serviceName },
query: { environment, valueType },
query: { environment, kuery, valueType },
} = context.params;

return getServiceProfilingStatistics({
kuery,
serviceName,
environment,
valueType,
Expand Down

0 comments on commit 5d34c65

Please sign in to comment.