Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSVB is retaining results even after indexpattern is removed from opt… #32003

Merged
merged 7 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const IndexPattern = props => {
const dropBucketName = `${prefix}drop_last_bucket`;

const defaults = {
default_index_pattern: '',
[indexPatternName]: '*',
[intervalName]: 'auto',
[dropBucketName]: 1
Expand All @@ -62,11 +63,16 @@ export const IndexPattern = props => {
id="tsvb.indexPatternLabel"
defaultMessage="Index pattern"
/>)}
helpText={(model.default_index_pattern && !model[indexPatternName] && <FormattedMessage
id="tsvb.indexPattern.searchByDefaultIndex"
defaultMessage="Default index pattern is used. To query all indexes use *"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should use indices as plural of index - but I wasn't sure and searched for it in the Kibana codebase - 2800 vs 141 in favor of indices, so I think we should go with it :)

/>)}
fullWidth
>
<EuiFieldText
data-test-subj="metricsIndexPatternInput"
disabled={props.disabled}
placeholder={model.default_index_pattern}
onChange={handleTextChange(indexPatternName, '*')}
value={model[indexPatternName]}
fullWidth
Expand Down
13 changes: 6 additions & 7 deletions src/legacy/core_plugins/metrics/public/components/vis_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ class VisEditor extends Component {
}

setDefaultIndexPattern = async () => {
if (this.props.vis.params.index_pattern === '') {
// set the default index pattern if none is defined.
const savedObjectsClient = chrome.getSavedObjectsClient();
const indexPattern = await savedObjectsClient.get('index-pattern', this.getConfig('defaultIndex'));
const defaultIndexPattern = indexPattern.attributes.title;
this.props.vis.params.index_pattern = defaultIndexPattern;
}
const savedObjectsClient = chrome.getSavedObjectsClient();
const indexPattern = await savedObjectsClient.get('index-pattern', this.getConfig('defaultIndex'));

this.handleChange({
default_index_pattern: indexPattern.attributes.title
});
}

handleChange = async (partialModel) => {
Expand Down
8 changes: 5 additions & 3 deletions src/legacy/core_plugins/metrics/server/lib/get_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
*/
import { SearchStrategiesRegister } from './search_strategies/search_strategies_register';
import { uniq } from 'lodash';
import { getIndexPatternObject } from './vis_data/helpers/get_index_pattern';

export async function getFields(req) {
const indexPattern = req.query.index || '*';
const { searchStrategy, capabilities } = await SearchStrategiesRegister.getViableStrategy(req, indexPattern);
const indexPattern = req.query.index;
const { indexPatternString } = await getIndexPatternObject(req, indexPattern);
const { searchStrategy, capabilities } = await SearchStrategiesRegister.getViableStrategy(req, indexPatternString);

const fields = (await searchStrategy
.getFieldsForWildcard(req, indexPattern, capabilities))
.getFieldsForWildcard(req, indexPatternString, capabilities))
.filter(field => field.aggregatable);

return uniq(fields, field => field.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { get } from 'lodash';

export async function getIndexPatternObject(req, indexPatternString) {
let defaultIndex;
Expand Down Expand Up @@ -48,6 +49,6 @@ export async function getIndexPatternObject(req, indexPatternString) {

return {
indexPatternObject,
indexPatternString: indexPatternString || indexPatternObject.title
indexPatternString: indexPatternString || get(indexPatternObject, 'title', '')
};
}