Skip to content

Commit

Permalink
TSVB is retaining results even after indexpattern is removed from opt… (
Browse files Browse the repository at this point in the history
#32003) (#32319)

# Conflicts:
#	src/legacy/core_plugins/metrics/server/lib/get_fields.js
  • Loading branch information
alexwizp authored Mar 4, 2019
1 parent 76e6366 commit e054492
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
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 *"
/>)}
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
9 changes: 6 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 @@ -16,13 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/

import { uniq } from 'lodash';
import { getIndexPatternObject } from './vis_data/helpers/get_index_pattern';

export async function getFields(req) {
const indexPattern = req.query.index;
const { indexPatternsService } = req.pre;
const index = req.query.index || '*';
const resp = await indexPatternsService.getFieldsForWildcard({ pattern: index });
const { indexPatternString } = await getIndexPatternObject(req, indexPattern);
const resp = await indexPatternsService.getFieldsForWildcard({ pattern: indexPatternString });
const fields = resp.filter(field => field.aggregatable);

return uniq(fields, field => field.name);
}

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', '')
};
}

0 comments on commit e054492

Please sign in to comment.