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

Don't turn Kibana plugin red if Kibana index is not yet ready #7428

Merged
merged 8 commits into from
Jun 10, 2016
10 changes: 9 additions & 1 deletion src/plugins/status_page/public/status_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import uiModules from 'ui/modules';

const chrome = require('ui/chrome')
.setRootTemplate(require('plugins/status_page/status_page.html'))
.setRootController('ui', function ($http, $scope) {
.setRootController('ui', function ($http, $window, $scope) {
const ui = this;
ui.loading = false;

Expand All @@ -36,6 +36,14 @@ const chrome = require('ui/chrome')
ui.serverState = overall.state;
ui.serverStateMessage = overall.title;
}

// Unless the status page was explicitly requested, there is no
// reason to stay on the status page if the status is green; reload
// the window so the user is shown the page they were requesting.
const statusPageUrl = chrome.addBasePath('/status');
if ((overall.state === 'green') && ($window.location.pathname !== statusPageUrl)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd get rid of the extra parenthesis here (overall.state === 'green' && $window.location.pathname !== statusPageUrl) is good enough

return $window.location.reload();
}
Copy link
Contributor Author

@ycombinator ycombinator Jun 10, 2016

Choose a reason for hiding this comment

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

This bit of code is necessary for the following scenario:

If I tried to load up Kibana in the browser while the server was still starting up, and the Kibana index wasn't yet ready (i.e. the Elasticsearch plugin wasn't yet green), I was taken to the Status page. However, by the time the Status page was actually rendered, the Kibana index was ready and all the plugins had turned green. In such cases, rather than show the user a Status page where everything is green, I think it makes sense to reload the window so they are taken to wherever they meant to go.

Happy to remove this code if folks disagree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I disagree with this approach. The issue here is a race condition caused by legacy code from back when the status page automatically refreshed. I think the right thing to do here is get rid of the race condition and send the status information to the browser with the app code, rather than fetching it on page load.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @spalger. Are you okay with me filing a separate issue to fix this, rather than adding to the scope of this PR? I will, of course, remove this reloading code block from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed issue for the right fix at #7432 and removed reloading code block in db780bd.

})
.catch(function () {
if (ui.fetchError) return;
Expand Down
12 changes: 10 additions & 2 deletions src/ui/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ export default function setupSettings(kbnServer, server, config) {
}

function userSettingsNotFound(kibanaVersion) {
const message = 'Could not find user-provided settings for this version of Kibana (' + kibanaVersion + ')';
server.plugins.kibana.status.red(message);
let message;
if (server.plugins.elasticsearch.status.state === 'green') {
// If Kibana index is ready but we still couldn't find user-provided settings in it,
// turn Kibana plugin to red
server.plugins.kibana.status.red('Could not find user-provided settings for this version of Kibana (' + kibanaVersion + ')');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change the message into a template string? Also the message variable is unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally. And good catch on the unused message variable — I'm surprised the linter didn't catch that. Fixing both things.

} else {
// Otherwise, simply log a warning because a page refresh (once the Kibana index is ready) will
// solve the problem
server.log(['warning', 'settings'], 'User-provided settings were requested before the Kibana index was ready');
}
return {};
}

Expand Down