Reverts breaking change for Status API (#21927)

* Unbreak status API

* Update xpack test

* Bump
This commit is contained in:
Josh Dover 2018-08-13 17:26:20 -05:00 committed by GitHub
parent 359ac43ed6
commit 17af683933
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 56 additions and 44 deletions

View file

@ -97,7 +97,7 @@ class StatusApp extends Component {
<EuiSpacer />
<EuiPageContent grow={0}>
<EuiPageContent grow={false}>
<EuiFlexGroup alignItems="center" justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiTitle size="s">

View file

@ -65,6 +65,23 @@ function formatMetrics(data) {
];
}
/**
* Reformat the backend data to make the frontend views simpler.
*/
function formatStatus(status) {
return {
id: status.id,
state: {
id: status.state,
title: status.title,
message: status.message,
uiColor: status.uiColor
}
};
}
async function fetchData() {
return fetch(
chrome.addBasePath('/api/status'),
@ -107,8 +124,8 @@ async function loadStatus(fetchFn = fetchData) {
return {
name: data.name,
statuses: data.status.statuses,
serverState: data.status.overall.state,
statuses: data.status.statuses.map(formatStatus),
serverState: formatStatus(data.status.overall).state,
metrics: formatMetrics(data),
};
}

View file

@ -34,11 +34,11 @@ const mockFetch = async () => ({
name: 'My computer',
status: {
overall: {
state: { id: 'yellow', title: 'Yellow' }
state: 'yellow', title: 'Yellow'
},
statuses: [
{ id: 'plugin:1', state: { id: 'green' } },
{ id: 'plugin:2', state: { id: 'yellow' } }
{ id: 'plugin:1', state: 'green', title: 'Green', message: 'Ready', uiColor: 'secondary' },
{ id: 'plugin:2', state: 'yellow', title: 'Yellow', message: 'Something is weird', uiColor: 'warning' }
],
},
metrics: {
@ -75,8 +75,8 @@ describe('response processing', () => {
test('includes the plugin statuses', async () => {
const data = await loadStatus(mockFetch);
expect(data.statuses).toEqual([
{ id: 'plugin:1', state: { id: 'green' } },
{ id: 'plugin:2', state: { id: 'yellow' } }
{ id: 'plugin:1', state: { id: 'green', title: 'Green', message: 'Ready', uiColor: 'secondary' } },
{ id: 'plugin:2', state: { id: 'yellow', title: 'Yellow', message: 'Something is weird', uiColor: 'warning' } }
]);
});

View file

@ -41,6 +41,6 @@ export function getKibanaInfoForStats(server, kbnServer) {
transport_address: `${config.get('server.host')}:${config.get('server.port')}`,
version: kbnServer.version.replace(snapshotRegex, ''),
snapshot: snapshotRegex.test(kbnServer.version),
status: get(status, 'overall.id')
status: get(status, 'overall.state')
};
}

View file

@ -86,18 +86,17 @@ export default class ServerStatus {
const since = _.get(_.sortBy(statuses, 'since'), [0, 'since']);
return {
id: state.id,
state: {
title: state.title,
uiColor: states.get(state.id).uiColor,
nickname: _.sample(state.nicknames),
},
state: state.id,
title: state.title,
nickname: _.sample(state.nicknames),
icon: state.icon,
uiColor: states.get(state.id).uiColor,
since: since,
};
}
isGreen() {
return (this.overall().id === 'green');
return (this.overall().state === 'green');
}
notGreen() {

View file

@ -24,7 +24,6 @@ import * as states from './states';
import Status from './status';
import ServerStatus from './server_status';
describe('ServerStatus class', function () {
const plugin = { id: 'name', version: '1.2.3' };
@ -94,13 +93,14 @@ describe('ServerStatus class', function () {
it('considers each status to produce a summary', function () {
const status = serverStatus.createForPlugin(plugin);
expect(serverStatus.overall().id).toBe('uninitialized');
expect(serverStatus.overall().state).toBe('uninitialized');
const match = function (overall, state) {
expect(overall).toHaveProperty('id', state.id);
expect(overall).toHaveProperty('state.title', state.title);
expect(overall).toHaveProperty('state.uiColor', state.uiColor);
expect(state.nicknames).toContain(overall.state.nickname);
expect(overall).toHaveProperty('state', state.id);
expect(overall).toHaveProperty('title', state.title);
expect(overall).toHaveProperty('icon', state.icon);
expect(overall).toHaveProperty('uiColor', state.uiColor);
expect(state.nicknames).toContain(overall.nickname);
};
status.green();
@ -134,12 +134,9 @@ describe('ServerStatus class', function () {
expect(json.statuses).toHaveLength(3);
const out = status => find(json.statuses, { id: status.id });
expect(out(service)).toHaveProperty('state.message', 'Green');
expect(out(service)).toHaveProperty('state.uiColor', 'secondary');
expect(out(p1)).toHaveProperty('state.message', 'Yellow');
expect(out(p1)).toHaveProperty('state.uiColor', 'warning');
expect(out(p2)).toHaveProperty('state.message', 'Red');
expect(out(p2)).toHaveProperty('state.uiColor', 'danger');
expect(out(service)).toHaveProperty('state', 'green');
expect(out(p1)).toHaveProperty('state', 'yellow');
expect(out(p2)).toHaveProperty('state', 'red');
});
});

View file

@ -23,6 +23,7 @@ export const all = [
{
id: 'red',
title: 'Red',
icon: 'danger',
uiColor: 'danger',
severity: 1000,
nicknames: [
@ -32,6 +33,7 @@ export const all = [
{
id: 'uninitialized',
title: 'Uninitialized',
icon: 'spinner',
uiColor: 'default',
severity: 900,
nicknames: [
@ -41,6 +43,7 @@ export const all = [
{
id: 'yellow',
title: 'Yellow',
icon: 'warning',
uiColor: 'warning',
severity: 800,
nicknames: [
@ -52,6 +55,7 @@ export const all = [
{
id: 'green',
title: 'Green',
icon: 'success',
uiColor: 'secondary',
severity: 0,
nicknames: [
@ -62,6 +66,7 @@ export const all = [
id: 'disabled',
title: 'Disabled',
severity: -1,
icon: 'toggle-off',
uiColor: 'default',
nicknames: [
'Am I even a thing?'

View file

@ -55,11 +55,10 @@ export default class Status extends EventEmitter {
toJSON() {
return {
id: this.id,
state: {
id: this.state,
message: this.message,
uiColor: states.get(this.state).uiColor,
},
state: this.state,
icon: states.get(this.state).icon,
message: this.message,
uiColor: states.get(this.state).uiColor,
since: this.since
};
}

View file

@ -74,8 +74,8 @@ describe('Status class', function () {
const json = status.toJSON();
expect(json.id).toEqual(status.id);
expect(json.state.id).toEqual('green');
expect(json.state.message).toEqual('Ready');
expect(json.state).toEqual('green');
expect(json.message).toEqual('Ready');
});
it('should call on handler if status is already matched', function (done) {

View file

@ -36,16 +36,13 @@ export default function ({ getService }) {
expect(body.version.build_number).to.be.a('number');
expect(body.status.overall).to.be.an('object');
expect(body.status.overall.id).to.be('green');
expect(body.status.overall.state).to.be.an('object');
expect(body.status.overall.state.title).to.be('Green');
expect(body.status.overall.state).to.be('green');
expect(body.status.statuses).to.be.an('array');
const kibanaPlugin = body.status.statuses.find(s => {
return s.id.indexOf('plugin:kibana') === 0;
});
expect(kibanaPlugin.state).to.be.an('object');
expect(kibanaPlugin.state.id).to.be('green');
expect(kibanaPlugin.state).to.be('green');
expect(body.metrics.collection_interval_in_millis).to.be.a('number');

View file

@ -39,6 +39,6 @@ export class KibanaServerStatus {
async getOverallState() {
const status = await this.get();
return status.status.overall.id;
return status.status.overall.state;
}
}

View file

@ -34,9 +34,7 @@ export default function ({ getService }) {
expect(body.settings.kibana.host.length > 0).to.eql(true);
expect(body.settings.kibana.transport_address.length > 0).to.eql(true);
expect(body.settings.kibana.version.length > 0).to.eql(true);
expect(body.settings.kibana.status.title.length > 0).to.eql(true);
expect(body.settings.kibana.status.uiColor.length > 0).to.eql(true);
expect(body.settings.kibana.status.nickname.length > 0).to.eql(true);
expect(body.settings.kibana.status.length > 0).to.eql(true);
});
});
});