-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Moves the APM index creation from server startup #37965
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,24 @@ | |
*/ | ||
import { InternalCoreSetup } from 'src/core/server'; | ||
import { getSavedObjectsClient } from '../helpers/saved_objects_client'; | ||
import indexPattern from '../../../../../../src/legacy/core_plugins/kibana/server/tutorials/apm/index_pattern.json'; | ||
import apmIndexPattern from '../../../../../../src/legacy/core_plugins/kibana/server/tutorials/apm/index_pattern.json'; | ||
|
||
export async function ensureIndexPatternExists(core: InternalCoreSetup) { | ||
export async function getIndexPattern(core: InternalCoreSetup) { | ||
const { server } = core.http; | ||
const config = server.config(); | ||
const apmIndexPatternTitle = config.get('apm_oss.indexPattern'); | ||
const savedObjectsClient = getSavedObjectsClient(server); | ||
const savedObjects = [ | ||
{ | ||
...indexPattern, | ||
attributes: { | ||
...indexPattern.attributes, | ||
try { | ||
return await savedObjectsClient.get('index-pattern', apmIndexPattern.id); | ||
} catch (error) { | ||
// if GET fails, then create a new index pattern saved object | ||
return await savedObjectsClient.create( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We attempt to lazily create the index pattern here as a convenience, but if a failure occurs, the APM UI shows the user some messaging that the APM index pattern is required to use certain features. The user is then directed to a tutorial where they can explicitly create the index pattern. |
||
'index-pattern', | ||
{ | ||
...apmIndexPattern.attributes, | ||
title: apmIndexPatternTitle | ||
} | ||
} | ||
]; | ||
await savedObjectsClient.bulkCreate(savedObjects, { overwrite: false }); | ||
}, | ||
{ id: apmIndexPattern.id, overwrite: false } | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import Boom from 'boom'; | ||
import { InternalCoreSetup } from 'src/core/server'; | ||
import { getIndexPattern } from '../lib/index_pattern'; | ||
|
||
const ROOT = '/api/apm/index_pattern'; | ||
const defaultErrorHandler = (err: Error & { status?: number }) => { | ||
// eslint-disable-next-line | ||
console.error(err.stack); | ||
throw Boom.boomify(err, { statusCode: err.status || 500 }); | ||
}; | ||
|
||
export function initIndexPatternApi(core: InternalCoreSetup) { | ||
const { server } = core.http; | ||
server.route({ | ||
method: 'GET', | ||
path: ROOT, | ||
options: { | ||
tags: ['access:apm'] | ||
}, | ||
handler: async req => { | ||
return await getIndexPattern(core).catch(defaultErrorHandler); | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to swallow errors here? It seems like it might be a better UX to show an EuiCallOut with an error message (e.g. "APM failed to initialize" along with the status code and error message), or maybe just a toast notification. This way a user can report this info to support or on the Discuss forums.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't happen as part of initialization, but rather attempts to lazily create the APM index pattern when the UI attempts to load it. This memoized function is expected to return undefined if no index pattern is present (in this case, there was a failure to lazily create it). When undefined, the UI shows messaging to the user that the APM index pattern is required to use certain features, and the user is directed to explicitly create it.