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

Fix auto interval filter building #102086

Merged
merged 2 commits into from
Jun 17, 2021
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 @@ -12,11 +12,24 @@ import { mockAggTypesRegistry, mockGetFieldFormatsStart } from '../../test_helpe
import { BUCKET_TYPES } from '../bucket_agg_types';
import { IBucketAggConfig } from '../bucket_agg_type';
import { createFilterHistogram } from './histogram';
import { RangeFilter } from '../../../../es_query';

function validateFilter(filter: RangeFilter) {
expect(mockGetFieldFormatsStart().deserialize).toHaveBeenCalledTimes(1);
expect(filter).toHaveProperty('meta');
expect(filter.meta).toHaveProperty('index', '1234');
expect(filter).toHaveProperty('range');
expect(filter.range).toHaveProperty('bytes');
expect(filter.range.bytes).toHaveProperty('gte', 2048);
expect(filter.range.bytes).toHaveProperty('lt', 3072);
expect(filter.meta).toHaveProperty('formattedValue');
}

describe('AggConfig Filters', () => {
describe('histogram', () => {
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
const getAggConfigs = () => {
jest.clearAllMocks();
const field = {
name: 'bytes',
format: new BytesFormat({}, getConfig),
Expand Down Expand Up @@ -56,14 +69,20 @@ describe('AggConfig Filters', () => {
'2048'
);

expect(mockGetFieldFormatsStart().deserialize).toHaveBeenCalledTimes(1);
expect(filter).toHaveProperty('meta');
expect(filter.meta).toHaveProperty('index', '1234');
expect(filter).toHaveProperty('range');
expect(filter.range).toHaveProperty('bytes');
expect(filter.range.bytes).toHaveProperty('gte', 2048);
expect(filter.range.bytes).toHaveProperty('lt', 3072);
expect(filter.meta).toHaveProperty('formattedValue');
validateFilter(filter);
});

test('should work for auto histograms', () => {
const aggConfigs = getAggConfigs();
const histogramAggConfig = aggConfigs.aggs[0];
histogramAggConfig.params.interval = 'auto';
histogramAggConfig.params.used_interval = 1024;

const filter = createFilterHistogram(mockGetFieldFormatsStart)(
histogramAggConfig as IBucketAggConfig,
'2048'
);
validateFilter(filter);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export const createFilterHistogram = (
return (aggConfig: IBucketAggConfig, key: string) => {
const { deserialize } = getFieldFormatsStart();
const value = parseInt(key, 10);
const params: RangeFilterParams = { gte: value, lt: value + aggConfig.params.interval };
const params: RangeFilterParams = {
gte: value,
lt:
value +
(typeof aggConfig.params.used_interval === 'number'
? aggConfig.params.used_interval
: aggConfig.params.interval),
};

return buildRangeFilter(
aggConfig.params.field,
Expand Down