Skip to content

Commit

Permalink
[TSVB] get rid of vis_type_timeseries_enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Jan 26, 2021
1 parent 1994c5b commit c6d2a2f
Show file tree
Hide file tree
Showing 30 changed files with 119 additions and 191 deletions.
9 changes: 0 additions & 9 deletions src/plugins/vis_type_timeseries/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export const config: PluginConfigDescriptor<VisTypeTimeseriesConfig> = {
schema: configSchema,
};

export {
AbstractSearchStrategy,
ReqFacade,
} from './lib/search_strategies/strategies/abstract_search_strategy';

export { VisPayload } from '../common/types';

export { DefaultSearchCapabilities } from './lib/search_strategies/default_search_capabilities';

export function plugin(initializerContext: PluginInitializerContext) {
return new VisTypeTimeseriesPlugin(initializerContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import { DefaultSearchCapabilities } from './default_search_capabilities';
import { ReqFacade } from './strategies/abstract_search_strategy';
import { VisPayload } from '../../../common/types';
import type { ReqFacade } from '../strategies/abstract_search_strategy';
import type { VisPayload } from '../../../../common/types';

describe('DefaultSearchCapabilities', () => {
let defaultSearchCapabilities: DefaultSearchCapabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
convertIntervalToUnit,
parseInterval,
getSuitableUnit,
} from '../vis_data/helpers/unit_to_seconds';
import { RESTRICTIONS_KEYS } from '../../../common/ui_restrictions';
import { ReqFacade } from './strategies/abstract_search_strategy';
import { VisPayload } from '../../../common/types';
} from '../../vis_data/helpers/unit_to_seconds';
import { RESTRICTIONS_KEYS } from '../../../../common/ui_restrictions';
import type { ReqFacade } from '../strategies/abstract_search_strategy';
import type { VisPayload } from '../../../../common/types';

const getTimezoneFromRequest = (request: ReqFacade<VisPayload>) => {
return request.payload.timerange.timezone;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { Unit } from '@elastic/datemath';
import { RollupSearchCapabilities } from './rollup_search_capabilities';

import { ReqFacade, VisPayload } from '../../../../../src/plugins/vis_type_timeseries/server';
import type { VisPayload } from '../../../../common/types';
import type { ReqFacade } from '../strategies/abstract_search_strategy';

describe('Rollup Search Capabilities', () => {
const testTimeZone = 'time_zone';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { get, has } from 'lodash';
import { leastCommonInterval, isCalendarInterval } from './lib/interval_helper';
import { leastCommonInterval, isCalendarInterval } from '../lib/interval_helper';

import { DefaultSearchCapabilities } from './default_search_capabilities';

import {
ReqFacade,
DefaultSearchCapabilities,
VisPayload,
} from '../../../../../src/plugins/vis_type_timeseries/server';
import type { VisPayload } from '../../../../common/types';
import type { ReqFacade } from '../strategies/abstract_search_strategy';

export class RollupSearchCapabilities extends DefaultSearchCapabilities {
rollupIndex: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
* Public License, v 1.
*/

export { AbstractSearchStrategy, ReqFacade } from './strategies';
export { SearchStrategyRegistry } from './search_strategy_registry';
export { DefaultSearchCapabilities } from './capabilities/default_search_capabilities';
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { isCalendarInterval, leastCommonInterval } from './interval_helper';

describe('interval_helper', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import dateMath from '@elastic/datemath';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/
import { get } from 'lodash';
import { RequestFacade, SearchStrategyRegistry } from './search_strategy_registry';
import { AbstractSearchStrategy, DefaultSearchStrategy } from './strategies';
import { DefaultSearchCapabilities } from './capabilities/default_search_capabilities';

import { SearchStrategyRegistry } from './search_strategy_registry';
// @ts-ignore
import { AbstractSearchStrategy } from './strategies/abstract_search_strategy';
// @ts-ignore
import { DefaultSearchStrategy } from './strategies/default_search_strategy';
// @ts-ignore
import { DefaultSearchCapabilities } from './default_search_capabilities';
const getPrivateField = <T>(registry: SearchStrategyRegistry, field: string) =>
get(registry, field) as T;

class MockSearchStrategy extends AbstractSearchStrategy {
checkForViability() {
Expand All @@ -31,20 +30,17 @@ describe('SearchStrategyRegister', () => {
});

test('should init strategies register', () => {
expect(
registry.addStrategy({} as AbstractSearchStrategy)[0] instanceof DefaultSearchStrategy
).toBe(true);
expect(getPrivateField(registry, 'strategies')).toHaveLength(2);
});

test('should not add a strategy if it is not an instance of AbstractSearchStrategy', () => {
const addedStrategies = registry.addStrategy({} as AbstractSearchStrategy);

expect(addedStrategies.length).toEqual(1);
expect(addedStrategies[0] instanceof DefaultSearchStrategy).toBe(true);
expect(addedStrategies.length).toEqual(2);
});

test('should return a DefaultSearchStrategy instance', async () => {
const req = {};
const req = {} as RequestFacade;
const indexPattern = '*';

const { searchStrategy, capabilities } = (await registry.getViableStrategy(req, indexPattern))!;
Expand All @@ -57,12 +53,12 @@ describe('SearchStrategyRegister', () => {
const anotherSearchStrategy = new MockSearchStrategy();
const addedStrategies = registry.addStrategy(anotherSearchStrategy);

expect(addedStrategies.length).toEqual(2);
expect(addedStrategies.length).toEqual(3);
expect(addedStrategies[0] instanceof AbstractSearchStrategy).toBe(true);
});

test('should return a MockSearchStrategy instance', async () => {
const req = {};
const req = {} as RequestFacade;
const indexPattern = '*';
const anotherSearchStrategy = new MockSearchStrategy();
registry.addStrategy(anotherSearchStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
* Public License, v 1.
*/

import { AbstractSearchStrategy } from './strategies/abstract_search_strategy';
// @ts-ignore
import { DefaultSearchStrategy } from './strategies/default_search_strategy';
// @ts-ignore
import { extractIndexPatterns } from '../../../common/extract_index_patterns';

export type RequestFacade = any;

import { PanelSchema } from '../../../common/types';
import {
AbstractSearchStrategy,
DefaultSearchStrategy,
RollupSearchStrategy,
ReqFacade,
} from './strategies';

export type RequestFacade = ReqFacade<any>;

export class SearchStrategyRegistry {
private strategies: AbstractSearchStrategy[] = [];

constructor() {
this.addStrategy(new DefaultSearchStrategy());
this.addStrategy(new RollupSearchStrategy());
}

public addStrategy(searchStrategy: AbstractSearchStrategy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,35 @@
*/

import { from } from 'rxjs';
import { AbstractSearchStrategy } from './abstract_search_strategy';
import { AbstractSearchStrategy, ReqFacade } from './abstract_search_strategy';
import type { VisPayload } from '../../../../common/types';
import type { IFieldType } from '../../../../../data/common';

class FooSearchStrategy extends AbstractSearchStrategy {}

describe('AbstractSearchStrategy', () => {
let abstractSearchStrategy;
let req;
let mockedFields;
let indexPattern;
let abstractSearchStrategy: AbstractSearchStrategy;
let req: ReqFacade;
let mockedFields: IFieldType[];
let indexPattern: string;

beforeEach(() => {
mockedFields = [];
req = {
req = ({
payload: {},
pre: {
indexPatternsFetcher: {
getFieldsForWildcard: jest.fn().mockReturnValue(mockedFields),
},
},
getIndexPatternsService: jest.fn(() => ({
find: jest.fn(() => []),
})),
};
getIndexPatternsService: jest.fn(() =>
Promise.resolve({
find: jest.fn(() => []),
})
),
} as unknown) as ReqFacade<VisPayload>;

abstractSearchStrategy = new AbstractSearchStrategy();
abstractSearchStrategy = new FooSearchStrategy();
});

test('should init an AbstractSearchStrategy instance', () => {
Expand All @@ -42,7 +48,7 @@ describe('AbstractSearchStrategy', () => {
const fields = await abstractSearchStrategy.getFieldsForWildcard(req, indexPattern);

expect(fields).toEqual(mockedFields);
expect(req.pre.indexPatternsFetcher.getFieldsForWildcard).toHaveBeenCalledWith({
expect(req.pre.indexPatternsFetcher!.getFieldsForWildcard).toHaveBeenCalledWith({
pattern: indexPattern,
metaFields: [],
fieldCapsOptions: { allow_no_indices: true },
Expand All @@ -54,7 +60,7 @@ describe('AbstractSearchStrategy', () => {
const searchFn = jest.fn().mockReturnValue(from(Promise.resolve({})));

const responses = await abstractSearchStrategy.search(
{
({
payload: {
searchSession: {
sessionId: '1',
Expand All @@ -65,7 +71,7 @@ describe('AbstractSearchStrategy', () => {
requestContext: {
search: { search: searchFn },
},
},
} as unknown) as ReqFacade<VisPayload>,
searches
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

import type { FakeRequest, IUiSettingsClient, SavedObjectsClientContract } from 'kibana/server';

import { indexPatterns } from '../../../../../data/server';

import type { Framework } from '../../../plugin';
import type { IndexPatternsFetcher, IFieldType } from '../../../../../data/server';
import type { VisPayload } from '../../../../common/types';
import type { IndexPatternsService } from '../../../../../data/common';
import { indexPatterns } from '../../../../../data/server';
import { SanitizedFieldType } from '../../../../common/types';
import type { SanitizedFieldType } from '../../../../common/types';
import type { VisTypeTimeseriesRequestHandlerContext } from '../../../types';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import { DefaultSearchStrategy } from './default_search_strategy';
import { ReqFacade } from './abstract_search_strategy';
import { VisPayload } from '../../../../common/types';
import type { ReqFacade } from './abstract_search_strategy';
import type { VisPayload } from '../../../../common/types';

describe('DefaultSearchStrategy', () => {
let defaultSearchStrategy: DefaultSearchStrategy;
Expand All @@ -20,7 +20,6 @@ describe('DefaultSearchStrategy', () => {
});

test('should init an DefaultSearchStrategy instance', () => {
expect(defaultSearchStrategy.name).toBe('default');
expect(defaultSearchStrategy.checkForViability).toBeDefined();
expect(defaultSearchStrategy.search).toBeDefined();
expect(defaultSearchStrategy.getFieldsForWildcard).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
*/

import { AbstractSearchStrategy, ReqFacade } from './abstract_search_strategy';
import { DefaultSearchCapabilities } from '../default_search_capabilities';
import { DefaultSearchCapabilities } from '../capabilities/default_search_capabilities';
import { VisPayload } from '../../../../common/types';

export class DefaultSearchStrategy extends AbstractSearchStrategy {
name = 'default';

checkForViability(req: ReqFacade<VisPayload>) {
return Promise.resolve({
isViable: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

export { AbstractSearchStrategy, ReqFacade } from './abstract_search_strategy';
export { DefaultSearchStrategy } from './default_search_strategy';
export { RollupSearchStrategy } from './rollup_search_strategy';
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { RollupSearchStrategy } from './rollup_search_strategy';
import type { ReqFacade, VisPayload } from '../../../../../src/plugins/vis_type_timeseries/server';

jest.mock('../../../../../src/plugins/vis_type_timeseries/server', () => {
const actual = jest.requireActual('../../../../../src/plugins/vis_type_timeseries/server');
import type { VisPayload } from '../../../../common/types';
import type { ReqFacade } from './abstract_search_strategy';

jest.mock('./abstract_search_strategy', () => {
class AbstractSearchStrategyMock {
getFieldsForWildcard() {
return [
Expand All @@ -23,7 +27,6 @@ jest.mock('../../../../../src/plugins/vis_type_timeseries/server', () => {
}

return {
...actual,
AbstractSearchStrategy: AbstractSearchStrategyMock,
};
});
Expand Down Expand Up @@ -52,7 +55,7 @@ describe('Rollup Search Strategy', () => {
test('should create instance of RollupSearchRequest', () => {
const rollupSearchStrategy = new RollupSearchStrategy();

expect(rollupSearchStrategy.name).toBe('rollup');
expect(rollupSearchStrategy).toBeDefined();
});

describe('checkForViability', () => {
Expand Down
Loading

0 comments on commit c6d2a2f

Please sign in to comment.