mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[TSVB] Remove field_stats calls from 5.6 for TSVB (#14152)
* Changing strategy to match core * Adding tests
This commit is contained in:
parent
864b8719e2
commit
a179e7b27e
2 changed files with 31 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import { getParams, handleResponse } from '../calculate_indices';
|
||||
import { getParams, handleResponse, handleError } from '../calculate_indices';
|
||||
|
||||
describe('calculateIndices', () => {
|
||||
|
||||
|
@ -32,6 +32,22 @@ describe('calculateIndices', () => {
|
|||
|
||||
});
|
||||
|
||||
describe('handleError', () => {
|
||||
it('should resolve a promise with an array with the index pattern', () => {
|
||||
const error = new Error('_field_stats');
|
||||
error.statusCode = 400;
|
||||
return handleError('metricbeat-*')(error)
|
||||
.then(resp => expect(resp).to.eql(['metricbeat-*']));
|
||||
});
|
||||
|
||||
it('should reject a promise if the error is not field stats', () => {
|
||||
const error = new Error('_');
|
||||
error.statusCode = 404;
|
||||
return handleError('metricbeat-*')(error)
|
||||
.catch(err => expect(err instanceof Error).to.equal(true));
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleResponse', () => {
|
||||
it('returns an array of indices', () => {
|
||||
const resp = {
|
||||
|
|
|
@ -34,15 +34,28 @@ function handleResponse(indexPattern) {
|
|||
};
|
||||
}
|
||||
|
||||
function handleError(indexPattern) {
|
||||
return error => {
|
||||
const errorCode400 = error.statusCode === 400;
|
||||
const fieldStatsError = (error.message || '').includes('_field_stats');
|
||||
if (errorCode400 && fieldStatsError) {
|
||||
return Promise.resolve([indexPattern]);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
};
|
||||
}
|
||||
|
||||
function calculateIndices(req, indexPattern = '*', timeField = '@timestamp', offsetBy) {
|
||||
const { server } = req;
|
||||
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
|
||||
const params = getParams(req, indexPattern, timeField, offsetBy);
|
||||
return callWithRequest(req, 'fieldStats', params)
|
||||
.then(handleResponse(indexPattern));
|
||||
.then(handleResponse(indexPattern))
|
||||
.catch(handleError(indexPattern));
|
||||
}
|
||||
|
||||
|
||||
calculateIndices.handleResponse = handleResponse;
|
||||
calculateIndices.getParams = getParams;
|
||||
calculateIndices.handleError = handleError;
|
||||
export default calculateIndices;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue