Skip to content

Commit

Permalink
[7.8] [APM] Catch annotations index permission error (#69881) (#69948)
Browse files Browse the repository at this point in the history
Relates to #69642. If the user doesn't have the appropriate privileges for the annotations index, instead of failing with a 500, we now catch the error and log a warning to the console.
# Conflicts:
#	x-pack/plugins/apm/server/routes/services.ts
  • Loading branch information
dgieselaar authored Jun 25, 2020
1 parent 39218e1 commit 734cd19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { APICaller } from 'kibana/server';
import { APICaller, Logger } from 'kibana/server';
import { SERVICE_NAME } from '../../../../common/elasticsearch_fieldnames';
import { ESSearchResponse } from '../../../../typings/elasticsearch';
import { ScopedAnnotationsClient } from '../../../../../observability/server';
Expand All @@ -19,12 +19,14 @@ export async function getStoredAnnotations({
environment,
apiCaller,
annotationsClient,
logger,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
environment?: string;
apiCaller: APICaller;
annotationsClient: ScopedAnnotationsClient;
logger: Logger;
}): Promise<Annotation[]> {
try {
const environmentFilter = getEnvironmentUiFilterES(environment);
Expand Down Expand Up @@ -71,6 +73,14 @@ export async function getStoredAnnotations({
if (error.body?.error?.type === 'index_not_found_exception') {
return [];
}

if (error.body?.error?.type === 'security_exception') {
logger.warn(
`Unable to get stored annotations due to a security exception. Please make sure that the user has 'indices:data/read/search' permissions for ${annotationsClient.index}`
);
return [];
}

throw error;
}
}
5 changes: 4 additions & 1 deletion x-pack/plugins/apm/server/lib/services/annotations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { APICaller } from 'kibana/server';
import { APICaller, Logger } from 'kibana/server';
import { ScopedAnnotationsClient } from '../../../../../observability/server';
import { getDerivedServiceAnnotations } from './get_derived_service_annotations';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
Expand All @@ -15,12 +15,14 @@ export async function getServiceAnnotations({
environment,
annotationsClient,
apiCaller,
logger,
}: {
serviceName: string;
environment?: string;
setup: Setup & SetupTimeRange;
annotationsClient?: ScopedAnnotationsClient;
apiCaller: APICaller;
logger: Logger;
}) {
// start fetching derived annotations (based on transactions), but don't wait on it
// it will likely be significantly slower than the stored annotations
Expand All @@ -37,6 +39,7 @@ export async function getServiceAnnotations({
environment,
annotationsClient,
apiCaller,
logger,
})
: [];

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const serviceAnnotationsRoute = createRoute(() => ({
environment,
annotationsClient,
apiCaller: context.core.elasticsearch.dataClient.callAsCurrentUser,
logger: context.logger,
});
},
}));
Expand Down

0 comments on commit 734cd19

Please sign in to comment.