Skip to content

Commit

Permalink
Hide errors due to unsupported _field_stats api (elastic#13670)
Browse files Browse the repository at this point in the history
During a rolling upgrade from 5.6 to 6.0, the cluster might contain nodes that do not support the _field_stats api anymore. This can lead to errors during index pattern expansion, which was removed in 6.0 as well but is still present in Kibana 5.6. If the cluster answers with an error in that direction, we fall back to using the unexpanded index pattern, which has already been the recommended practice for a while.
  • Loading branch information
weltenwort authored and tylersmalley committed Aug 23, 2017
1 parent 13369d5 commit 4cc5700
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 21 deletions.
26 changes: 22 additions & 4 deletions src/ui/public/index_patterns/__tests__/_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ describe('index pattern', function () {
beforeEach(ngMock.module('kibana', StubIndexPatternsApiClientModule, (PrivateProvider) => {
PrivateProvider.swap(IndexPatternsCalculateIndicesProvider, () => {
// stub calculateIndices
calculateIndices = sinon.spy(function () {
return Promise.resolve([
calculateIndices = sinon.stub().returns(Promise.resolve([
{ index: 'foo', max: Infinity, min: -Infinity },
{ index: 'bar', max: Infinity, min: -Infinity }
]);
});
]));

return calculateIndices;
});
Expand Down Expand Up @@ -325,6 +323,26 @@ describe('index pattern', function () {
});
});

describe('when index pattern is a time-base wildcard but field_stats are not supported', function () {
beforeEach(function () {
calculateIndices.returns(Promise.reject({
message: '[illegal_argument_exception] request [/filebeat-**/_field_stats] contains unrecognized parameter: [level]',
statusCode: 400,
}));

indexPattern.id = 'randomID';
indexPattern.title = 'logstash-*';
indexPattern.timeFieldName = defaultTimeField.name;
indexPattern.intervalName = null;
indexPattern.notExpandable = false;
});

it('is fulfilled by title', async function () {
const indexList = await indexPattern.toDetailedIndexList();
expect(indexList.map(i => i.index)).to.eql([indexPattern.title]);
});
});

describe('when index pattern is a time-base wildcard that is configured not to expand', function () {
beforeEach(function () {
indexPattern.id = 'randomID';
Expand Down
45 changes: 28 additions & 17 deletions src/ui/public/index_patterns/_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ export function IndexPatternProvider(Private, $http, config, kbnIndex, Promise,
});
}

function isFieldStatsError(error) {
return (
error.statusCode === 400
&& (error.message || '').includes('_field_stats')
);
}

class IndexPattern {
constructor(id) {
setId(this, id);
Expand Down Expand Up @@ -273,28 +280,32 @@ export function IndexPatternProvider(Private, $http, config, kbnIndex, Promise,
});
}

toDetailedIndexList(start, stop, sortDirection) {
return Promise.resolve().then(() => {
if (this.isTimeBasedInterval()) {
return intervals.toIndexList(
this.title, this.getInterval(), start, stop, sortDirection
);
}
async toDetailedIndexList(start, stop, sortDirection) {
if (this.isTimeBasedInterval()) {
return await intervals.toIndexList(
this.title, this.getInterval(), start, stop, sortDirection
);
}

if (this.isTimeBasedWildcard() && this.isIndexExpansionEnabled()) {
return calculateIndices(
if (this.isTimeBasedWildcard() && this.isIndexExpansionEnabled()) {
try {
return await calculateIndices(
this.title, this.timeFieldName, start, stop, sortDirection
);
} catch(error) {
if (!isFieldStatsError(error)) {
throw error;
}
}
}

return [
{
index: this.title,
min: -Infinity,
max: Infinity
}
];
});
return [
{
index: this.title,
min: -Infinity,
max: Infinity
}
];
}

isIndexExpansionEnabled() {
Expand Down

0 comments on commit 4cc5700

Please sign in to comment.