Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ describe('environmentQuery', () => {
it('returns ENVIRONMENT_NOT_DEFINED', () => {
expect(environmentQuery('')).toEqual([
{
term: { [SERVICE_ENVIRONMENT]: ENVIRONMENT_NOT_DEFINED.value },
bool: {
should: [
{
term: { [SERVICE_ENVIRONMENT]: ENVIRONMENT_NOT_DEFINED.value },
},
{
bool: {
must_not: [
{
exists: { field: SERVICE_ENVIRONMENT },
},
],
},
},
],
minimum_should_match: 1,
},
},
]);
});
Expand All @@ -35,7 +51,23 @@ describe('environmentQuery', () => {
it('creates a query for missing service environments', () => {
expect(environmentQuery(ENVIRONMENT_NOT_DEFINED.value)).toEqual([
{
term: { [SERVICE_ENVIRONMENT]: ENVIRONMENT_NOT_DEFINED.value },
bool: {
should: [
{
term: { [SERVICE_ENVIRONMENT]: ENVIRONMENT_NOT_DEFINED.value },
},
{
bool: {
must_not: [
{
exists: { field: SERVICE_ENVIRONMENT },
},
],
},
},
],
minimum_should_match: 1,
},
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@ export function environmentQuery(
}

if (!environment || environment === ENVIRONMENT_NOT_DEFINED.value) {
return [{ term: { [field]: ENVIRONMENT_NOT_DEFINED.value } }];
}

return [{ term: { [field]: environment } }];
}

export function environmentQueryAnnotations(
environment: string | undefined,
field: string = SERVICE_ENVIRONMENT
): QueryDslQueryContainer[] {
if (!environment || environment === ENVIRONMENT_ALL.value) {
return [];
}

if (environment === ENVIRONMENT_NOT_DEFINED.value) {
return [{ bool: { must_not: { exists: { field } } } }];
return [
{
bool: {
should: [
{
term: { [field]: ENVIRONMENT_NOT_DEFINED.value },
},
{
bool: {
must_not: [
{
exists: { field },
},
],
},
},
],
minimum_should_match: 1,
},
},
];
}

return [{ term: { [field]: environment } }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { isFiniteNumber } from '../../../../common/utils/is_finite_number';
import type { Annotation } from '../../../../common/annotations';
import { AnnotationType } from '../../../../common/annotations';
import { AT_TIMESTAMP, SERVICE_NAME, SERVICE_VERSION } from '../../../../common/es_fields/apm';
import { environmentQueryAnnotations } from '../../../../common/utils/environment_query';
import { environmentQuery } from '../../../../common/utils/environment_query';
import {
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
Expand All @@ -39,7 +39,7 @@ export async function getDerivedServiceAnnotations({
const filter: ESFilter[] = [
{ term: { [SERVICE_NAME]: serviceName } },
...getBackwardCompatibleDocumentTypeFilter(searchAggregatedTransactions),
...environmentQueryAnnotations(environment),
...environmentQuery(environment),
];

const versions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import type { ESSearchResponse } from '@kbn/es-types';
import type { Annotation as ESAnnotation } from '@kbn/observability-plugin/common/annotations';
import type { ScopedAnnotationsClient } from '@kbn/observability-plugin/server';
import { environmentQueryAnnotations } from '../../../../common/utils/environment_query';
import { environmentQuery } from '../../../../common/utils/environment_query';
import type { Annotation } from '../../../../common/annotations';
import { AnnotationType } from '../../../../common/annotations';
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
Expand Down Expand Up @@ -48,7 +48,7 @@ export function getStoredAnnotations({
{ term: { tags: 'apm' } },
{ term: { [SERVICE_NAME]: serviceName } },
...rangeQuery(start, end),
...environmentQueryAnnotations(environment),
...environmentQuery(environment),
],
},
},
Expand Down