Skip to content

Commit

Permalink
Update query to include filter
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Jun 21, 2021
1 parent 6af39c0 commit 9a37eec
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,6 @@ export const asyncSearchServiceProvider = (
return;
}

const {
fieldCandidates,
totalHits,
} = await fetchTransactionDurationFieldCandidates(esClient, params);

progress.loadedFieldCanditates = 1;

// Create an array of ranges [2, 4, 6, ..., 98]
const percents = Array.from(range(2, 100, 2));
const percentiles = await fetchTransactionDurationPecentiles(
Expand All @@ -116,6 +109,13 @@ export const asyncSearchServiceProvider = (
return;
}

const {
fieldCandidates,
totalHits,
} = await fetchTransactionDurationFieldCandidates(esClient, params);

progress.loadedFieldCanditates = 1;

const fieldValuePairs = await fetchTransactionDurationFieldValuePairs(
esClient,
params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import type { estypes } from '@elastic/elasticsearch';

import { i18n } from '@kbn/i18n';

import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames';
import {
TRANSACTION_DURATION,
TRANSACTION_NAME,
} from '../../../../common/elasticsearch_fieldnames';
import type { SearchServiceParams } from '../../../../common/search_strategies/correlations/types';

export enum ProcessorEvent {
Expand All @@ -23,6 +26,7 @@ export enum ProcessorEvent {
const PROCESSOR_EVENT = 'processor.event';
const SERVICE_ENVIRONMENT = 'service.environment';
const SERVICE_NAME = 'service.name';
const TRANSACTION_TYPE = 'transaction.type';

const ENVIRONMENT_ALL_VALUE = 'ENVIRONMENT_ALL';
const ENVIRONMENT_NOT_DEFINED_VALUE = 'ENVIRONMENT_NOT_DEFINED';
Expand Down Expand Up @@ -84,6 +88,30 @@ const getRangeQuery = (
];
};

const getTransactionTypeQuery = (
transactionType: string | undefined
): estypes.QueryDslQueryContainer[] => {
return transactionType
? [{ term: { [TRANSACTION_TYPE]: transactionType } }]
: [];
};

const getTransactionNameQuery = (
transactionName: string | undefined
): estypes.QueryDslQueryContainer[] => {
return typeof transactionName === 'string'
? [
{
term: {
[TRANSACTION_NAME]: {
value: transactionName,
},
},
},
]
: [];
};

const getPercentileThresholdValueQuery = (
percentileThresholdValue: number
): estypes.QueryDslQueryContainer[] => {
Expand All @@ -101,15 +129,19 @@ const getPercentileThresholdValueQuery = (
export const getQueryWithParams = ({
environment,
serviceName,
transactionType,
start,
end,
percentileThresholdValue,
transactionName,
}: SearchServiceParams) => {
return {
bool: {
filter: [
{ term: { [PROCESSOR_EVENT]: ProcessorEvent.transaction } },
...(serviceName ? [{ term: { [SERVICE_NAME]: serviceName } }] : []),
...getTransactionTypeQuery(transactionType),
...getTransactionNameQuery(transactionName),
...getRangeQuery(start, end),
...getEnvironmentQuery(environment),
...(percentileThresholdValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ export type Field = string;
export const getTermsAggRequest = (
params: SearchServiceParams,
fieldName: string
): estypes.SearchRequest => ({
index: params.index,
body: {
query: getQueryWithParams(params),
size: 0,
aggs: {
attribute_terms: {
terms: {
field: fieldName,
size: TERMS_SIZE,
): estypes.SearchRequest => {
const query = getQueryWithParams(params);
return {
index: params.index,
body: {
query,
size: 0,
aggs: {
attribute_terms: {
terms: {
field: fieldName,
size: TERMS_SIZE,
},
},
},
},
},
});
};
};

export const fetchTransactionDurationFieldValuePairs = async (
esClient: ElasticsearchClient,
Expand Down

0 comments on commit 9a37eec

Please sign in to comment.