-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get min values from indicies response
- Loading branch information
Showing
7 changed files
with
134 additions
and
9 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
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
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
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
30 changes: 30 additions & 0 deletions
30
x-pack/legacy/plugins/maps/server/lib/get_index_pattern_settings.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,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_INNER_RESULT_WINDOW } from '../../common/constants'; | ||
|
||
export function getIndexPatternSettings(indicesSettingsResp) { | ||
let maxResultWindow = Infinity; | ||
let maxInnerResultWindow = Infinity; | ||
Object.values(indicesSettingsResp).forEach(indexSettings => { | ||
const indexMaxResultWindow = _.get( | ||
indexSettings, | ||
'settings.index.max_result_window', | ||
DEFAULT_MAX_RESULT_WINDOW | ||
); | ||
maxResultWindow = Math.min(maxResultWindow, indexMaxResultWindow); | ||
|
||
const indexMaxInnerResultWindow = _.get( | ||
indexSettings, | ||
'settings.index.max_inner_result_window', | ||
DEFAULT_MAX_INNER_RESULT_WINDOW | ||
); | ||
maxInnerResultWindow = Math.min(indexMaxInnerResultWindow, indexMaxResultWindow); | ||
}); | ||
|
||
return { maxResultWindow, maxInnerResultWindow }; | ||
} |
86 changes: 86 additions & 0 deletions
86
x-pack/legacy/plugins/maps/server/lib/get_index_pattern_settings.test.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,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getIndexPatternSettings } from './get_index_pattern_settings'; | ||
import { DEFAULT_MAX_RESULT_WINDOW, DEFAULT_MAX_INNER_RESULT_WINDOW } from '../../common/constants'; | ||
|
||
describe('max_result_window and max_inner_result_window are not set', () => { | ||
test('Should provide default values when values not set', () => { | ||
const indicesSettingsResp = { | ||
kibana_sample_data_logs: { | ||
settings: { | ||
index: {}, | ||
}, | ||
}, | ||
}; | ||
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp); | ||
expect(maxResultWindow).toBe(DEFAULT_MAX_RESULT_WINDOW); | ||
expect(maxInnerResultWindow).toBe(DEFAULT_MAX_INNER_RESULT_WINDOW); | ||
}); | ||
|
||
test('Should include default values when providing minimum values for indices in index pattern', () => { | ||
const indicesSettingsResp = { | ||
kibana_sample_data_logs: { | ||
settings: { | ||
index: { | ||
max_result_window: '15000', | ||
max_inner_result_window: '200', | ||
}, | ||
}, | ||
}, | ||
kibana_sample_data_flights: { | ||
settings: { | ||
index: {}, | ||
}, | ||
}, | ||
}; | ||
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp); | ||
expect(maxResultWindow).toBe(DEFAULT_MAX_RESULT_WINDOW); | ||
expect(maxInnerResultWindow).toBe(DEFAULT_MAX_INNER_RESULT_WINDOW); | ||
}); | ||
}); | ||
|
||
describe('max_result_window and max_inner_result_window are set', () => { | ||
test('Should provide values from settings', () => { | ||
const indicesSettingsResp = { | ||
kibana_sample_data_logs: { | ||
settings: { | ||
index: { | ||
max_result_window: '15000', // value is returned as string API | ||
max_inner_result_window: '200', | ||
}, | ||
}, | ||
}, | ||
}; | ||
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp); | ||
expect(maxResultWindow).toBe(15000); | ||
expect(maxInnerResultWindow).toBe(200); | ||
}); | ||
|
||
test('Should provide minimum values for indices in index pattern', () => { | ||
const indicesSettingsResp = { | ||
kibana_sample_data_logs: { | ||
settings: { | ||
index: { | ||
max_result_window: '15000', | ||
max_inner_result_window: '200', | ||
}, | ||
}, | ||
}, | ||
kibana_sample_data_flights: { | ||
settings: { | ||
index: { | ||
max_result_window: '7000', | ||
max_inner_result_window: '75', | ||
}, | ||
}, | ||
}, | ||
}; | ||
const { maxResultWindow, maxInnerResultWindow } = getIndexPatternSettings(indicesSettingsResp); | ||
expect(maxResultWindow).toBe(7000); | ||
expect(maxInnerResultWindow).toBe(75); | ||
}); | ||
}); |
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