Skip to content

Commit

Permalink
Rollup index patterns with live data (#21187)
Browse files Browse the repository at this point in the history
* Use new rollup capabilities keyed by rollup index name ES api, remove wildcard restriction
* Adjust plugins to work with new typeMeta information on rollup index patterns
* Disable rollup index patterns from:
- Timelion `index` suggestions
- ML
- Graph
* Set Discover to use default search strategy
  • Loading branch information
jen-huang committed Aug 10, 2018
1 parent a81c26b commit f82629a
Show file tree
Hide file tree
Showing 35 changed files with 724 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ function discoverController(
.setField('highlightAll', true)
.setField('version', true);

// Even when searching rollups, we want to use the default strategy so that we get back a
// document-like response.
$scope.searchSource.setPreferredSearchStrategyId('default');

// searchSource which applies time range
const timeRangeSearchSource = savedSearch.searchSource.create();
timeRangeSearchSource.setField('filter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const HeaderComponent = ({
onQueryChanged,
goToNextStep,
isNextStepDisabled,
allowWildcards,
intl,
...rest
}) => (
Expand Down Expand Up @@ -68,17 +67,13 @@ export const HeaderComponent = ({
error={errors}
helpText={
<div>
{
allowWildcards ? (
<p>
<FormattedMessage
id="kbn.management.createIndexPattern.step.indexPattern.allowLabel"
defaultMessage="You can use a {asterisk} as a wildcard in your index pattern."
values={{ asterisk: <strong>*</strong> }}
/>
</p>
) : ''
}
<p>
<FormattedMessage
id="kbn.management.createIndexPattern.step.indexPattern.allowLabel"
defaultMessage="You can use a {asterisk} as a wildcard in your index pattern."
values={{ asterisk: <strong>*</strong> }}
/>
</p>
<p>
<FormattedMessage
id="kbn.management.createIndexPattern.step.indexPattern.disallowLabel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ export class StepIndexPatternComponent extends Component {
query: props.initialQuery,
appendedWildcard: false,
showingIndexPatternQueryErrors: false,
allowWildcards: indexPatternCreationType.getAllowWildcards(),
indexPatternName: indexPatternCreationType.getIndexPatternName(),
};

this.ILLEGAL_CHARACTERS = indexPatternCreationType.illegalCharacters(ILLEGAL_CHARACTERS);
this.ILLEGAL_CHARACTERS = [...ILLEGAL_CHARACTERS];
this.lastQuery = null;
}

Expand Down Expand Up @@ -138,11 +137,11 @@ export class StepIndexPatternComponent extends Component {
}

onQueryChanged = e => {
const { appendedWildcard, allowWildcards } = this.state;
const { appendedWildcard } = this.state;
const { target } = e;

let query = target.value;
if (query.length === 1 && allowWildcards && canAppendWildcard(query)) {
if (query.length === 1 && canAppendWildcard(query)) {
query += '*';
this.setState({ appendedWildcard: true });
setTimeout(() => target.setSelectionRange(1, 1));
Expand Down Expand Up @@ -237,7 +236,7 @@ export class StepIndexPatternComponent extends Component {

renderHeader({ exactMatchedIndices: indices }) {
const { goToNextStep, indexPatternCreationType, intl } = this.props;
const { query, showingIndexPatternQueryErrors, indexPatternExists, indexPatternName, allowWildcards } = this.state;
const { query, showingIndexPatternQueryErrors, indexPatternExists, indexPatternName } = this.state;

let containsErrors = false;
const errors = [];
Expand Down Expand Up @@ -276,7 +275,6 @@ export class StepIndexPatternComponent extends Component {
onQueryChanged={this.onQueryChanged}
goToNextStep={goToNextStep}
isNextStepDisabled={isNextStepDisabled}
allowWildcards={allowWildcards}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class StepTimeFieldComponent extends Component {
constructor(props) {
super(props);

const {
getIndexPatternType,
getIndexPatternName,
} = props.indexPatternCreationType;

this.state = {
timeFields: [],
selectedTimeField: undefined,
Expand All @@ -57,8 +62,8 @@ export class StepTimeFieldComponent extends Component {
isFetchingTimeFields: false,
isCreating: false,
indexPatternId: '',
indexPatternType: props.indexPatternCreationType.getIndexPatternType(),
indexPatternName: props.indexPatternCreationType.getIndexPatternName(),
indexPatternType: getIndexPatternType(),
indexPatternName: getIndexPatternName(),
};
}

Expand All @@ -68,10 +73,12 @@ export class StepTimeFieldComponent extends Component {

fetchTimeFields = async () => {
const { indexPatternsService, indexPattern } = this.props;
const { indexPatternType } = this.state;
const { getFetchForWildcardOptions } = this.props.indexPatternCreationType;

this.setState({ isFetchingTimeFields: true });
const fields = await ensureMinimumTime(indexPatternsService.fieldsFetcher.fetchForWildcard(indexPattern, indexPatternType));
const fields = await ensureMinimumTime(
indexPatternsService.fieldsFetcher.fetchForWildcard(indexPattern, getFetchForWildcardOptions())
);
const timeFields = extractTimeFields(fields);

this.setState({ timeFields, isFetchingTimeFields: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export async function getIndices(es, indexPatternCreationType, rawPattern, limit
}
}
},
...indexPatternCreationType.getIndexPatternCreationQuery(),
}
};

Expand All @@ -72,10 +71,10 @@ export async function getIndices(es, indexPatternCreationType, rawPattern, limit
response.aggregations.indices.buckets.map(bucket => {
return bucket.key;
})
.map((index) => {
.map((indexName) => {
return {
name: index,
tags: indexPatternCreationType.getIndexTags(index)
name: indexName,
tags: indexPatternCreationType.getIndexTags(indexName)
};
})
, 'name'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TableComponent extends PureComponent {
type="questionInCircle"
color="primary"
aria-label={infoLabel}
content={field.info.map(info => <div>{info}</div>)}
content={field.info.map((info, i) => <div key={i}>{info}</div>)}
/>
</span>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ uiModules.get('apps/management')
$scope.$evalAsync(() => kbnUrl.change(url));
});

$scope.editingId = $route.current.params.indexPatternId;
config.bindToScope($scope, 'defaultIndex');

const renderList = () => {
$scope.indexPatternList = $route.current.locals.indexPatterns.map(pattern => {
const id = pattern.id;
Expand Down Expand Up @@ -134,13 +131,11 @@ uiModules.get('apps/management')
updateIndexPatternList($scope, indexPatternCreationOptions, $scope.defaultIndex, $scope.indexPatternList);
};

$scope.$watch('defaultIndex', renderList);

renderList();

$scope.$on('$destroy', () => {
destroyIndexPatternList();
});
$scope.$on('$destroy', () => destroyIndexPatternList());
$scope.editingId = $route.current.params.indexPatternId;
$scope.$watch('defaultIndex', () => renderList());
config.bindToScope($scope, 'defaultIndex');
$scope.$apply();
}
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ export function ArgValueSuggestionsProvider(Private, indexPatterns) {
const search = partial ? `${partial}*` : '*';
const resp = await savedObjectsClient.find({
type: 'index-pattern',
fields: ['title'],
fields: ['title', 'type'],
search: `${search}`,
search_fields: ['title'],
perPage: 25
});
return resp.savedObjects.map(savedObject => {
return { name: savedObject.attributes.title };
});
return resp.savedObjects
.filter(savedObject => !savedObject.get('type'))
.map(savedObject => {
return { name: savedObject.attributes.title };
});
},
metric: async function (partial, functionArgs) {
if (!partial || !partial.includes(':')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const createFieldsForWildcardRoute = pre => ({
validate: {
query: Joi.object().keys({
pattern: Joi.string().required(),
meta_fields: Joi.array().items(Joi.string()).default([])
meta_fields: Joi.array().items(Joi.string()).default([]),
params: Joi.object(),
}).default()
},
handler(req, reply) {
Expand Down
9 changes: 9 additions & 0 deletions src/ui/public/courier/search_source/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function SearchSourceProvider(Promise, Private, config) {
constructor(initialFields) {
this._id = _.uniqueId('data_source');

this._searchStrategyId = undefined;
this._fields = parseInitialFields(initialFields);
this._parent = undefined;

Expand Down Expand Up @@ -164,6 +165,14 @@ export function SearchSourceProvider(Promise, Private, config) {
* PUBLIC API
*****/

setPreferredSearchStrategyId(searchStrategyId) {
this._searchStrategyId = searchStrategyId;
}

getPreferredSearchStrategyId() {
return this._searchStrategyId;
}

setFields(newFields) {
this._fields = newFields;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

export const isDefaultTypeIndexPattern = indexPattern => {
// Default index patterns don't have `type` defined.
return indexPattern.type == null;
return !indexPattern.type;
};
27 changes: 22 additions & 5 deletions src/ui/public/courier/search_strategy/search_strategy_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,31 @@ export const addSearchStrategy = searchStrategy => {
searchStrategies.push(searchStrategy);
};

const getSearchStrategy = indexPattern => {
const getSearchStrategyByViability = indexPattern => {
return searchStrategies.find(searchStrategy => {
return searchStrategy.isViable(indexPattern);
});
};

const getSearchStrategyById = searchStrategyId => {
return searchStrategies.find(searchStrategy => {
return searchStrategy.id === searchStrategyId;
});
};

const getSearchStrategyForSearchRequest = searchRequest => {
// Allow the searchSource to declare the correct strategy with which to execute its searches.
const preferredSearchStrategyId = searchRequest.source.getPreferredSearchStrategyId();
if (preferredSearchStrategyId != null) {
return getSearchStrategyById(preferredSearchStrategyId);
}

// Otherwise try to match it to a strategy.
const indexPattern = searchRequest.source.getField('index');
return getSearchStrategyByViability(indexPattern);
};


/**
* Build a structure like this:
*
Expand All @@ -52,9 +71,7 @@ export const assignSearchRequestsToSearchStrategies = searchRequests => {
const searchStrategyById = {};

searchRequests.forEach(searchRequest => {
const indexPattern = searchRequest.source.getField('index');
const matchingSearchStrategy = getSearchStrategy(indexPattern);

const matchingSearchStrategy = getSearchStrategyForSearchRequest(searchRequest);
const { id } = matchingSearchStrategy;
let searchStrategyWithRequest = searchStrategyById[id];

Expand All @@ -76,5 +93,5 @@ export const assignSearchRequestsToSearchStrategies = searchRequests => {
};

export const hasSearchStategyForIndexPattern = indexPattern => {
return Boolean(getSearchStrategy(indexPattern));
return Boolean(getSearchStrategyByViability(indexPattern));
};
10 changes: 7 additions & 3 deletions src/ui/public/index_patterns/fields_fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export function createFieldsFetcher(apiClient, config) {
return this.fetchForTimePattern(indexPattern.title, interval);
}

return this.fetchForWildcard(indexPattern.title, indexPattern.type);
return this.fetchForWildcard(indexPattern.title, {
type: indexPattern.type,
params: indexPattern.typeMeta && indexPattern.typeMeta.params,
});
}

fetchForTimePattern(indexPatternId) {
Expand All @@ -36,11 +39,12 @@ export function createFieldsFetcher(apiClient, config) {
});
}

fetchForWildcard(indexPatternId, indexPatternType) {
fetchForWildcard(indexPatternId, options = {}) {
return apiClient.getFieldsForWildcard({
pattern: indexPatternId,
metaFields: config.get('metaFields'),
type: indexPatternType,
type: options.type,
params: options.params || {},
});
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/ui/public/index_patterns/index_patterns_api_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,16 @@ export function createIndexPatternsApiClient($http, basePath) {
pattern,
metaFields,
type,
params,
} = options;

const url = getUrl(['_fields_for_wildcard'], {
const url = getUrl([type, '_fields_for_wildcard'], {
pattern,
meta_fields: metaFields,
params: JSON.stringify(params),
});

return request('GET', url).then(resp => {
if(type) {
const typeUrl = type ? getUrl([type, '_fields_for_wildcard'], {
pattern,
fields: resp.fields,
meta_fields: metaFields,
}) : null;

return request('GET', typeUrl).then(typeResp => typeResp.fields);
} else {
return resp.fields;
}
});
return request('GET', url).then(resp => resp.fields);
}
}

Expand Down
Loading

0 comments on commit f82629a

Please sign in to comment.