Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [APM] Catch annotations index permission error (#69881) #69947

Merged
merged 1 commit into from
Jun 25, 2020
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 @@ -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.legacy.client.callAsCurrentUser,
logger: context.logger,
});
},
}));
Expand Down