forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elastic#8376 from elastic/jasper/backport/8339/5.x
[backport] PR elastic#8339 to 5.x - Set minimum aggregation 'Size' input value to 1, because ES will return an error if you provide a size of 0.
- Loading branch information
Showing
7 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
required | ||
class="form-control" | ||
type="number" | ||
min="0" | ||
> | ||
min="1" | ||
> | ||
</div> | ||
</div> | ||
</div> |
51 changes: 51 additions & 0 deletions
51
src/ui/public/elasticsearch_errors/__tests__/elasticsearch_error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sinon from 'auto-release-sinon'; | ||
import expect from 'expect.js'; | ||
import ElasticsearchError from '../elasticsearch_error'; | ||
|
||
describe('ElasticsearchError', () => { | ||
function createError(rootCauses = []) { | ||
// Elasticsearch errors are characterized by the resp.error.root_cause array. | ||
return { | ||
resp: { | ||
error: { | ||
root_cause: rootCauses.map(rootCause => ({ | ||
reason: rootCause, | ||
})), | ||
} | ||
} | ||
}; | ||
} | ||
|
||
describe('interface', () => { | ||
describe('constructor', () => { | ||
it('throws an error if instantiated with a non-elasticsearch error', () => { | ||
expect(() => new ElasticsearchError({})).to.throwError(); | ||
}); | ||
}); | ||
|
||
describe('getRootCauses', () => { | ||
it(`returns the root_cause array's reason values`, () => { | ||
const rootCauses = ['a', 'b']; | ||
const error = createError(rootCauses); | ||
const esError = new ElasticsearchError(error); | ||
expect(esError.getRootCauses()).to.eql(rootCauses); | ||
}); | ||
}); | ||
|
||
describe('hasRootCause', () => { | ||
it(`returns true if the cause occurs in the root_cause array's reasons, insensitive to case`, () => { | ||
const rootCauses = ['a very detailed error', 'a slightly more detailed error']; | ||
const error = createError(rootCauses); | ||
const esError = new ElasticsearchError(error); | ||
expect(esError.hasRootCause('slightly MORE')).to.be(true); | ||
}); | ||
|
||
it(`returns false if the cause doesn't occur in the root_cause array's reasons`, () => { | ||
const rootCauses = ['a very detailed error', 'a slightly more detailed error']; | ||
const error = createError(rootCauses); | ||
const esError = new ElasticsearchError(error); | ||
expect(esError.hasRootCause('nonexistent error')).to.be(false); | ||
}); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
src/ui/public/elasticsearch_errors/__tests__/is_term_size_zero_error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sinon from 'auto-release-sinon'; | ||
import expect from 'expect.js'; | ||
import isTermSizeZeroError from '../is_term_size_zero_error'; | ||
|
||
describe('isTermSizeZeroError', () => { | ||
const identifyingString = 'size must be positive, got 0'; | ||
|
||
it('returns true if it contains the identifying string', () => { | ||
const error = { | ||
resp: { | ||
error: { | ||
root_cause: [{ | ||
reason: `Some crazy Java exception: ${identifyingString}`, | ||
}], | ||
} | ||
} | ||
}; | ||
expect(isTermSizeZeroError(error)).to.be(true); | ||
}); | ||
|
||
it(`returns false if it doesn't contain the identifying string`, () => { | ||
const error = { | ||
resp: { | ||
error: { | ||
root_cause: [{ | ||
reason: `Some crazy Java exception`, | ||
}], | ||
} | ||
} | ||
}; | ||
expect(isTermSizeZeroError(error)).to.be(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import _ from 'lodash'; | ||
|
||
export default class ElasticsearchError { | ||
constructor(error) { | ||
this.error = error; | ||
|
||
this.getRootCauses = this.getRootCauses.bind(this); | ||
this.hasRootCause = this.hasRootCause.bind(this); | ||
|
||
if (!this.getRootCauses().length) { | ||
throw new Error( | ||
'ElasticsearchError must be instantiated with an elasticsearch error, i.e. it must have' + | ||
`a resp.error.root_cause property. Instead got ${JSON.stringify(error)}` | ||
); | ||
} | ||
} | ||
|
||
getRootCauses() { | ||
const rootCauses = _.get(this.error, 'resp.error.root_cause'); | ||
return _.pluck(rootCauses, 'reason'); | ||
} | ||
|
||
hasRootCause(cause) { | ||
const normalizedCause = cause.toLowerCase(); | ||
const rootCauses = this.getRootCauses(); | ||
const matchingCauses = rootCauses.filter(rootCause => { | ||
const normalizedRootCause = rootCause.toLowerCase(); | ||
return normalizedRootCause.indexOf(normalizedCause) !== -1; | ||
}); | ||
return matchingCauses.length !== 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { | ||
default as ElasticsearchError, | ||
} from './elasticsearch_error'; | ||
|
||
export { | ||
default as isTermSizeZeroError, | ||
} from './is_term_size_zero_error'; |
6 changes: 6 additions & 0 deletions
6
src/ui/public/elasticsearch_errors/is_term_size_zero_error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import ElasticsearchError from './elasticsearch_error'; | ||
|
||
export default function isTermSizeZeroError(error) { | ||
const esError = new ElasticsearchError(error); | ||
return esError.hasRootCause('size must be positive, got 0'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters