Skip to content

Commit

Permalink
[Metrics UI / Logs UI] Remove field filtering in Source API call.
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Feb 25, 2020
1 parent 2501919 commit 4115e91
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { RequestHandlerContext } from 'src/core/server';
export interface FieldsAdapter {
getIndexFields(
requestContext: RequestHandlerContext,
indices: string,
timefield: string
indices: string
): Promise<IndexFieldDescriptor[]>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,91 +36,15 @@ export class FrameworkFieldsAdapter implements FieldsAdapter {

public async getIndexFields(
requestContext: RequestHandlerContext,
indices: string,
timefield: string
indices: string
): Promise<IndexFieldDescriptor[]> {
const indexPatternsService = this.framework.getIndexPatternsService(requestContext);
const response = await indexPatternsService.getFieldsForWildcard({
pattern: indices,
});
const { dataSets, modules } = await this.getDataSetsAndModules(
requestContext,
indices,
timefield
);
const allowedList = modules.reduce(
(acc, name) => uniq([...acc, ...getAllowedListForPrefix(name)]),
[] as string[]
);
const dataSetsWithAllowedList = [...allowedList, ...dataSets];
return response.map(field => ({
...field,
displayable: dataSetsWithAllowedList.some(name => startsWith(field.name, name)),
displayable: true,
}));
}

private async getDataSetsAndModules(
requestContext: RequestHandlerContext,
indices: string,
timefield: string
): Promise<{ dataSets: string[]; modules: string[] }> {
const params = {
index: indices,
allowNoIndices: true,
ignoreUnavailable: true,
body: {
size: 0,
query: {
bool: {
filter: [
{
range: {
[timefield]: {
gte: 'now-24h',
lte: 'now',
},
},
},
],
},
},
aggs: {
datasets: {
composite: {
sources: [
{
dataset: {
terms: {
field: 'event.dataset',
},
},
},
],
},
},
},
},
};

const bucketSelector = (response: InfraDatabaseSearchResponse<{}, DataSetResponse>) =>
(response.aggregations && response.aggregations.datasets.buckets) || [];
const handleAfterKey = createAfterKeyHandler(
'body.aggs.datasets.composite.after',
input => input?.aggregations?.datasets?.after_key
);

const buckets = await getAllCompositeData<DataSetResponse, Bucket>(
this.framework,
requestContext,
params,
bucketSelector,
handleAfterKey
);
const dataSets = buckets.map(bucket => bucket.key.dataset);
const modules = dataSets.reduce((acc, dataset) => {
const module = first(dataset.split(/\./));
return module ? uniq([...acc, module]) : acc;
}, [] as string[]);
return { modules, dataSets };
}
}
3 changes: 1 addition & 2 deletions x-pack/plugins/infra/server/lib/domains/fields_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ export class InfraFieldsDomain {
requestContext,
`${includeMetricIndices ? configuration.metricAlias : ''},${
includeLogIndices ? configuration.logAlias : ''
}`,
configuration.fields.timestamp
}`
);

return fields;
Expand Down

0 comments on commit 4115e91

Please sign in to comment.