Skip to content

Commit

Permalink
Enable send to background in TSVB (#82835)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
alexwizp and kibanamachine committed Nov 9, 2020
1 parent 566758c commit ec5bf8c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/plugins/vis_type_timeseries/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*/

import { TypeOf } from '@kbn/config-schema';
import { metricsItems, panel, seriesItems } from './vis_schema';
import { metricsItems, panel, seriesItems, visPayloadSchema } from './vis_schema';

export type SeriesItemsSchema = TypeOf<typeof seriesItems>;
export type MetricsItemsSchema = TypeOf<typeof metricsItems>;
export type PanelSchema = TypeOf<typeof panel>;
export type VisPayload = TypeOf<typeof visPayloadSchema>;
1 change: 1 addition & 0 deletions src/plugins/vis_type_timeseries/common/vis_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,5 @@ export const visPayloadSchema = schema.object({
min: stringRequired,
max: stringRequired,
}),
sessionId: schema.maybe(schema.string()),
});
4 changes: 3 additions & 1 deletion src/plugins/vis_type_timeseries/public/request_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const metricsRequestHandler = async ({
const config = getUISettings();
const timezone = getTimezone(config);
const uiStateObj = uiState.get(visParams.type, {});
const parsedTimeRange = getDataStart().query.timefilter.timefilter.calculateBounds(timeRange);
const dataSearch = getDataStart();
const parsedTimeRange = dataSearch.query.timefilter.timefilter.calculateBounds(timeRange);
const scaledDataFormat = config.get('dateFormat:scaled');
const dateFormat = config.get('dateFormat');

Expand All @@ -53,6 +54,7 @@ export const metricsRequestHandler = async ({
panels: [visParams],
state: uiStateObj,
savedObjectId: savedObjectId || 'unsaved',
sessionId: dataSearch.search.session.getSessionId(),
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('AbstractSearchStrategy', () => {
beforeEach(() => {
mockedFields = {};
req = {
payload: {},
pre: {
indexPatternsService: {
getFieldsForWildcard: jest.fn().mockReturnValue(mockedFields),
Expand Down Expand Up @@ -60,6 +61,9 @@ describe('AbstractSearchStrategy', () => {

const responses = await abstractSearchStrategy.search(
{
payload: {
sessionId: 1,
},
requestContext: {
search: { search: searchFn },
},
Expand All @@ -76,7 +80,9 @@ describe('AbstractSearchStrategy', () => {
},
indexType: undefined,
},
{}
{
sessionId: 1,
}
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@ import {
IUiSettingsClient,
SavedObjectsClientContract,
} from 'kibana/server';

import { Framework } from '../../../plugin';
import { IndexPatternsFetcher } from '../../../../../data/server';
import { VisPayload } from '../../../../common/types';

/**
* ReqFacade is a regular KibanaRequest object extended with additional service
* references to ensure backwards compatibility for existing integrations.
*
* This will be replaced by standard KibanaRequest and RequestContext objects in a later version.
*/
export type ReqFacade = FakeRequest & {
export interface ReqFacade<T = unknown> extends FakeRequest {
requestContext: RequestHandlerContext;
framework: Framework;
payload: unknown;
payload: T;
pre: {
indexPatternsService?: IndexPatternsFetcher;
};
getUiSettingsService: () => IUiSettingsClient;
getSavedObjectsClient: () => SavedObjectsClientContract;
getEsShardTimeout: () => Promise<number>;
};
}

export class AbstractSearchStrategy {
public indexType?: string;
Expand All @@ -53,8 +55,10 @@ export class AbstractSearchStrategy {
this.additionalParams = additionalParams;
}

async search(req: ReqFacade, bodies: any[], options = {}) {
async search(req: ReqFacade<VisPayload>, bodies: any[], options = {}) {
const requests: any[] = [];
const { sessionId } = req.payload;

bodies.forEach((body) => {
requests.push(
req.requestContext
Expand All @@ -67,6 +71,7 @@ export class AbstractSearchStrategy {
indexType: this.indexType,
},
{
sessionId,
...options,
}
)
Expand Down

0 comments on commit ec5bf8c

Please sign in to comment.