mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* Support legacy use cases for passthrough * Support generic case too * Add legacy flag * Do not format api field names in legacy mode * Add basic test for legacy parameter * Add more tests
This commit is contained in:
parent
b4f0e4d8bb
commit
c3026cbff7
3 changed files with 75 additions and 2 deletions
|
@ -52,13 +52,15 @@ export function registerStatsApi(kbnServer, server, config) {
|
|||
config: {
|
||||
validate: {
|
||||
query: {
|
||||
extended: Joi.string().valid('', 'true', 'false')
|
||||
extended: Joi.string().valid('', 'true', 'false'),
|
||||
legacy: Joi.string().valid('', 'true', 'false')
|
||||
}
|
||||
},
|
||||
tags: ['api'],
|
||||
},
|
||||
async handler(req, reply) {
|
||||
const isExtended = req.query.extended !== undefined && req.query.extended !== 'false';
|
||||
const isLegacy = req.query.legacy !== undefined && req.query.legacy !== 'false';
|
||||
|
||||
let extended;
|
||||
if (isExtended) {
|
||||
|
@ -69,7 +71,52 @@ export function registerStatsApi(kbnServer, server, config) {
|
|||
getUsage(callCluster),
|
||||
getClusterUuid(callCluster),
|
||||
]);
|
||||
extended = collectorSet.toApiFieldNames({ usage, clusterUuid });
|
||||
|
||||
|
||||
let modifiedUsage = usage;
|
||||
if (isLegacy) {
|
||||
// In an effort to make telemetry more easily augmented, we need to ensure
|
||||
// we can passthrough the data without every part of the process needing
|
||||
// to know about the change; however, to support legacy use cases where this
|
||||
// wasn't true, we need to be backwards compatible with how the legacy data
|
||||
// looked and support those use cases here.
|
||||
modifiedUsage = Object.keys(usage).reduce((accum, usageKey) => {
|
||||
if (usageKey === 'kibana') {
|
||||
accum = {
|
||||
...accum,
|
||||
...usage[usageKey]
|
||||
};
|
||||
}
|
||||
else if (usageKey === 'reporting') {
|
||||
accum = {
|
||||
...accum,
|
||||
xpack: {
|
||||
...accum.xpack,
|
||||
reporting: usage[usageKey]
|
||||
},
|
||||
};
|
||||
}
|
||||
else {
|
||||
accum = {
|
||||
...accum,
|
||||
[usageKey]: usage[usageKey]
|
||||
};
|
||||
}
|
||||
|
||||
return accum;
|
||||
}, {});
|
||||
|
||||
extended = {
|
||||
usage: modifiedUsage,
|
||||
clusterUuid,
|
||||
};
|
||||
}
|
||||
else {
|
||||
extended = collectorSet.toApiFieldNames({
|
||||
usage: modifiedUsage,
|
||||
clusterUuid
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
return reply(boomify(e));
|
||||
}
|
||||
|
|
|
@ -104,6 +104,20 @@ export default function ({ getService }) {
|
|||
assertStatsAndMetrics(body);
|
||||
});
|
||||
});
|
||||
|
||||
describe('legacy', () => {
|
||||
it(`should return return the 'extended' data in the old format with 'legacy' query string param present`, () => {
|
||||
return supertest
|
||||
.get('/api/stats?extended&legacy')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.then(({ body }) => {
|
||||
expect(body.clusterUuid).to.be.a('string');
|
||||
expect(body.usage).to.be.an('object'); // no usage collectors have been registered so usage is an empty object
|
||||
assertStatsAndMetrics(body, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -59,6 +59,18 @@ export default function ({ getService }) {
|
|||
expect(body.usage.kibana.index).to.be('.kibana');
|
||||
expect(body.usage.kibana.dashboard.total).to.be(0);
|
||||
});
|
||||
|
||||
it('should return 200 for extended and legacy', async () => {
|
||||
const { body } = await supertest
|
||||
.get('/api/stats?extended&legacy')
|
||||
.expect(200);
|
||||
expect(body.kibana.uuid).to.eql('5b2de169-2785-441b-ae8c-186a1936b17d');
|
||||
expect(body.process.uptime_ms).to.be.greaterThan(0);
|
||||
expect(body.os.uptime_ms).to.be.greaterThan(0);
|
||||
expect(body.usage.index).to.be('.kibana');
|
||||
expect(body.usage.dashboard.total).to.be(0);
|
||||
expect(body.usage.xpack.reporting.available).to.be(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue