Skip to content

Commit

Permalink
Remaining feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed May 5, 2020
1 parent 1dd7a73 commit 983222b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getServiceAnnotations({
annotationsClient?: ScopedAnnotationsClient;
apiCaller: APICaller;
}) {
// start fetching derived annotations, but don't wait on it
// start fetching derived annotations (based on transactions), but don't wait on it
// it will likely be significantly slower than the stored annotations
const derivedAnnotationsPromise = getDerivedServiceAnnotations({
setup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../../common/annotations';
import { PromiseReturnType } from '../../../../apm/typings/common';
import { createOrUpdateIndex } from '../../utils/create_or_update_index';
import { mappings } from './mappings';

type CreateParams = t.TypeOf<typeof createAnnotationRt>;
type DeleteParams = t.TypeOf<typeof deleteAnnotationRt>;
Expand Down Expand Up @@ -45,47 +46,7 @@ export function createAnnotationsClient(params: {
const initIndex = () =>
createOrUpdateIndex({
index,
mappings: {
dynamic: 'strict',
properties: {
annotation: {
properties: {
type: {
type: 'keyword',
},
},
},
message: {
type: 'text',
},
tags: {
type: 'keyword',
},
'@timestamp': {
type: 'date',
},
event: {
properties: {
created: {
type: 'date',
},
},
},
service: {
properties: {
name: {
type: 'keyword',
},
environment: {
type: 'keyword',
},
version: {
type: 'keyword',
},
},
},
},
},
mappings,
apiCaller,
logger,
});
Expand All @@ -97,7 +58,13 @@ export function createAnnotationsClient(params: {
create: async (
createParams: CreateParams
): Promise<{ _id: string; _index: string; _source: Annotation }> => {
await initIndex();
const indexExists = await apiCaller('indices.exists', {
index,
});

if (!indexExists) {
await initIndex();
}

const annotation = {
...createParams,
Expand Down
47 changes: 47 additions & 0 deletions x-pack/plugins/observability/server/lib/annotations/mappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const mappings = {
dynamic: 'strict',
properties: {
annotation: {
properties: {
type: {
type: 'keyword',
},
},
},
message: {
type: 'text',
},
tags: {
type: 'keyword',
},
'@timestamp': {
type: 'date',
},
event: {
properties: {
created: {
type: 'date',
},
},
},
service: {
properties: {
name: {
type: 'keyword',
},
environment: {
type: 'keyword',
},
version: {
type: 'keyword',
},
},
},
},
} as const;
8 changes: 4 additions & 4 deletions x-pack/plugins/observability/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ export class ObservabilityPlugin implements Plugin<ObservabilityPluginSetup> {
index: config.annotations.index,
context: this.initContext,
}).catch(err => {
this.initContext.logger.get('annotations').warn(err);
const logger = this.initContext.logger.get('annotations');
logger.warn(err);
throw err;
});
}

return {
getScopedAnnotationsClient: async (...args) => {
return annotationsApiPromise
? (await annotationsApiPromise).getScopedAnnotationsClient(...args)
: undefined;
const api = await annotationsApiPromise;
return api?.getScopedAnnotationsClient(...args);
},
};
}
Expand Down

0 comments on commit 983222b

Please sign in to comment.