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

[APM] Moves the APM index creation from server startup #37965

Merged
merged 2 commits into from
Jun 6, 2019

Conversation

ogupte
Copy link
Contributor

@ogupte ogupte commented Jun 4, 2019

Closes #37499 by moving the APM index creation from server startup to savedObject request for the index pattern. It first checks if the index pattern is saved, if not it creates it.

@ogupte ogupte requested a review from a team as a code owner June 4, 2019 09:11
@ogupte ogupte self-assigned this Jun 4, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@cjcenizal cjcenizal added Team:APM All issues that need APM UI Team support :AppArch labels Jun 4, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks great, I just had some questions and suggestions. I would approve the PR but when I tested locally I noticed that the problem in the referenced issue still occurs:

image

So I think either this PR needs more work to fix the issue or we should update the PR description to clarify that it doesn't fix the reported problem.

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does savedObjectsClient return an error with a status code, e.g. 404? If so, then maybe we should check this before trying to create the index pattern. If it's some other kind of status code it seems like we'd probably want to surface it in the UI as an initialization failure or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

pathname: `/api/apm/index_pattern`
});
} catch (error) {
return;
Copy link
Contributor

@cjcenizal cjcenizal Jun 4, 2019

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.

Copy link
Contributor Author

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.

const defaultErrorHandler = (err: Error) => {
// eslint-disable-next-line
console.error(err.stack);
throw Boom.boomify(err, { statusCode: 400 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: is there any benefit to making this more informative by providing different status codes? For example, if the error thrown is due to a JS error (e.g. accessing a property on undefined) then this would be a 500.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks great, I just had some questions and suggestions. I would approve the PR but when I tested locally I noticed that the problem in the referenced issue still occurs:

image

So I think either this PR needs more work to fix the issue or we should update the PR description to clarify that it doesn't fix the reported problem.

In my testing, it has been working as expected. The intention is to create the APM index pattern automatically, when the user performs and action which requires it. In my testing, if i start kibana with an empty ES cluster, i see no errors like this until after the APM home page loads (which requires the apm index pattern for the kuery bar to work).

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@cjcenizal
Copy link
Contributor

@ogupte Oh, I'm sorry! I originally thought that this was a fix for #35898 but I see that's a separate issue. What's the best way for me to test this?

@ogupte
Copy link
Contributor Author

ogupte commented Jun 5, 2019

@ogupte Oh, I'm sorry! I originally thought that this was a fix for #35898 but I see that's a separate issue. What's the best way for me to test this?

Stand up a fresh ES cluster with no data. Start Kibana and navigate to discover and other plugins. Make sure they don't show any missing data errors. Then navigate to APM, and assert that you don't see any of the message of a missing apm-index (the index pattern will have been automatically created). Navigate to settings and see the apm-* index pattern in saved objects.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed your testing instructions and everything went as expected.

However, when I clicked on the apm-* index pattern, I got an error that no matching indices were found:

image

This seemed contrary to your comment that "the index will have been automatically created" so I just wanted to call it out for you.

@ogupte
Copy link
Contributor Author

ogupte commented Jun 5, 2019

I followed your testing instructions and everything went as expected.

However, when I clicked on the apm-* index pattern, I got an error that no matching indices were found:

image

This seemed contrary to your comment that "the index will have been automatically created" so I just wanted to call it out for you.

you are correct! i meant to say "the index pattern will have been automatically created" not the index itself.

ogupte added 2 commits June 5, 2019 11:35
…er startup

to savedObject request for the index pattern. It first checks if the
index pattern is saved, if not it creates it.
@ogupte ogupte force-pushed the apm-37499-move-apm-index-creation branch from 20dbef2 to 04185f0 Compare June 5, 2019 18:35
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@ogupte ogupte merged commit d43ee7f into elastic:master Jun 6, 2019
ogupte added a commit to ogupte/kibana that referenced this pull request Jun 6, 2019
* [APM] Closes elastic#37499 by moving the APM index creation from server startup
to savedObject request for the index pattern. It first checks if the
index pattern is saved, if not it creates it.

* [APM] provide more meaninful status codes in the default error handler
ogupte added a commit to ogupte/kibana that referenced this pull request Jun 6, 2019
* [APM] Closes elastic#37499 by moving the APM index creation from server startup
to savedObject request for the index pattern. It first checks if the
index pattern is saved, if not it creates it.

* [APM] provide more meaninful status codes in the default error handler
ogupte added a commit that referenced this pull request Jun 6, 2019
* [APM] Closes #37499 by moving the APM index creation from server startup
to savedObject request for the index pattern. It first checks if the
index pattern is saved, if not it creates it.

* [APM] provide more meaninful status codes in the default error handler
ogupte added a commit that referenced this pull request Jun 6, 2019
* [APM] Closes #37499 by moving the APM index creation from server startup
to savedObject request for the index pattern. It first checks if the
index pattern is saved, if not it creates it.

* [APM] provide more meaninful status codes in the default error handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:fix Team:APM All issues that need APM UI Team support v7.2.0 v7.3.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Move APM index pattern creation from Kibana startup
5 participants