Skip to content

Commit

Permalink
[APM]Remove observer-version-major from apm queries (elastic#125962)
Browse files Browse the repository at this point in the history
* [APM]Remove observer-version-major from apm queries

* Remove constant from apm, not observability

* fix tests and ts types

* remove Promise.all()

* fix types
  • Loading branch information
MiriamAparicio authored Feb 22, 2022
1 parent 6bf91d7 commit eb05eb5
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 311 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion x-pack/plugins/apm/common/elasticsearch_fieldnames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const USER_AGENT_NAME = 'user_agent.name';
export const DESTINATION_ADDRESS = 'destination.address';

export const OBSERVER_HOSTNAME = 'observer.hostname';
export const OBSERVER_VERSION_MAJOR = 'observer.version_major';
export const OBSERVER_LISTENING = 'observer.listening';
export const PROCESSOR_EVENT = 'processor.event';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Query Debugging

When debugging an issue with the APM UI it can be very helpful to see the exact Elasticsearch queries and responses that was made for a given API request.
When debugging an issue with the APM UI it can be very helpful to see the exact Elasticsearch queries and responses that was made for a given API request.
To enable debugging of Elasticsearch queries in APM UI do the following:

1. Go to "Stack Management"
1. Go to "Stack Management"
2. Under "Kibana" on the left-hand side, select "Advanced Settings"
3. Search for "Observability"
4. Enable "Inspect ES queries" setting
5. Click "Save"

When you navigate back to APM UI you can now inspect Elasticsearch queries by opening your browser's Developer Tools and selecting an api request to APM's api.
When you navigate back to APM UI you can now inspect Elasticsearch queries by opening your browser's Developer Tools and selecting an api request to APM's api.
There will be an `_inspect` key containing every Elasticsearch query made during that request including both requests and responses to and from Elasticsearch.

![image](https://user-images.githubusercontent.com/209966/140500012-b075adf0-8401-40fd-99f8-85b68711de17.png)

## Example
## Example

When "Inspect ES queries" are enabed all API calls to the APM API will be include the query param `_inspect=true`. For the environments API the request / response will be:

Expand All @@ -24,11 +24,7 @@ GET /internal/apm/environments?start=<start>&end=<end>&_inspect=true

```json
{
"environments": [
"production",
"testing",
"ENVIRONMENT_NOT_DEFINED"
],
"environments": ["production", "testing", "ENVIRONMENT_NOT_DEFINED"],
"_inspect": [
{
"id": "get_environments (/internal/apm/environments)",
Expand All @@ -48,18 +44,7 @@ GET /internal/apm/environments?start=<start>&end=<end>&_inspect=true
},
{
"terms": {
"processor.event": [
"transaction",
"metric",
"error"
]
}
},
{
"range": {
"observer.version_major": {
"gte": 7
}
"processor.event": ["transaction", "metric", "error"]
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function useServicesFetcher() {
);

useEffect(() => {
if (mainStatisticsData.hasLegacyData && !hasDisplayedToast) {
if (!hasDisplayedToast) {
hasDisplayedToast = true;

core.notifications.toasts.addWarning({
Expand All @@ -141,11 +141,7 @@ function useServicesFetcher() {
),
});
}
}, [
mainStatisticsData.hasLegacyData,
upgradeAssistantHref,
core.notifications.toasts,
]);
}, [upgradeAssistantHref, core.notifications.toasts]);

return {
mainStatisticsData,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
getDebugTitle,
} from '../call_async_with_debug';
import { cancelEsRequestOnAbort } from '../cancel_es_request_on_abort';
import { addFilterToExcludeLegacyData } from './add_filter_to_exclude_legacy_data';
import { unpackProcessorEvents } from './unpack_processor_events';

export type APMEventESSearchRequest = Omit<ESSearchRequest, 'index'> & {
Expand Down Expand Up @@ -97,14 +96,8 @@ export class APMEventClient {
this.indices
);

const { includeLegacyData = false } = params.apm;

const withPossibleLegacyDataFilter = !includeLegacyData
? addFilterToExcludeLegacyData(withProcessorEventFilter)
: withProcessorEventFilter;

const searchParams = {
...withPossibleLegacyDataFilter,
...withProcessorEventFilter,
...(this.includeFrozen ? { ignore_throttled: false } : {}),
ignore_unavailable: true,
preference: 'any',
Expand Down
94 changes: 1 addition & 93 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { setupRequest } from './setup_request';
import { APMConfig } from '../..';
import { APMRouteHandlerResources } from '../../routes/typings';
import { ProcessorEvent } from '../../../common/processor_event';
import { PROCESSOR_EVENT } from '../../../common/elasticsearch_fieldnames';
import { getApmIndices } from '../../routes/settings/apm_indices/get_apm_indices';

jest.mock('../../routes/settings/apm_indices/get_apm_indices', () => ({
Expand Down Expand Up @@ -121,10 +120,7 @@ describe('setupRequest', () => {
foo: 'bar',
query: {
bool: {
filter: [
{ terms: { 'processor.event': ['transaction'] } },
{ range: { 'observer.version_major': { gte: 7 } } },
],
filter: [{ terms: { 'processor.event': ['transaction'] } }],
},
},
},
Expand Down Expand Up @@ -161,94 +157,6 @@ describe('setupRequest', () => {
);
});
});

describe('with a bool filter', () => {
it('adds a range filter for `observer.version_major` to the existing filter', async () => {
const mockResources = getMockResources();
const { apmEventClient } = await setupRequest(mockResources);
await apmEventClient.search('foo', {
apm: {
events: [ProcessorEvent.transaction],
},
body: {
query: { bool: { filter: [{ term: { field: 'someTerm' } }] } },
},
});
const params =
mockResources.context.core.elasticsearch.client.asCurrentUser.search
.mock.calls[0][0];
// @ts-expect-error missing body definition
expect(params.body).toEqual({
query: {
bool: {
filter: [
{ term: { field: 'someTerm' } },
{ terms: { [PROCESSOR_EVENT]: ['transaction'] } },
{ range: { 'observer.version_major': { gte: 7 } } },
],
},
},
});
});

it('does not add a range filter for `observer.version_major` if includeLegacyData=true', async () => {
const mockResources = getMockResources();
const { apmEventClient } = await setupRequest(mockResources);
await apmEventClient.search('foo', {
apm: {
events: [ProcessorEvent.error],
includeLegacyData: true,
},
body: {
query: { bool: { filter: [{ term: { field: 'someTerm' } }] } },
},
});
const params =
mockResources.context.core.elasticsearch.client.asCurrentUser.search
.mock.calls[0][0];
// @ts-expect-error missing body definition
expect(params.body).toEqual({
query: {
bool: {
filter: [
{ term: { field: 'someTerm' } },
{
terms: {
[PROCESSOR_EVENT]: ['error'],
},
},
],
},
},
});
});
});
});

describe('without a bool filter', () => {
it('adds a range filter for `observer.version_major`', async () => {
const mockResources = getMockResources();
const { apmEventClient } = await setupRequest(mockResources);
await apmEventClient.search('foo', {
apm: {
events: [ProcessorEvent.error],
},
});
const params =
mockResources.context.core.elasticsearch.client.asCurrentUser.search.mock
.calls[0][0];
// @ts-expect-error missing body definition
expect(params.body).toEqual({
query: {
bool: {
filter: [
{ terms: { [PROCESSOR_EVENT]: ['error'] } },
{ range: { 'observer.version_major': { gte: 7 } } },
],
},
},
});
});
});

describe('with includeFrozen=false', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading

0 comments on commit eb05eb5

Please sign in to comment.