Skip to content

Commit

Permalink
fix rollups WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Jan 28, 2020
1 parent 3968b07 commit f00d2d9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/plugins/vis_type_timeseries/server/lib/get_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { uniq } from 'lodash';
import { first, map } from 'rxjs/operators';
import { RequestHandlerContext } from 'kibana/server';
import { KibanaRequest, RequestHandlerContext } from 'kibana/server';

// @ts-ignore
import { getIndexPatternObject } from './vis_data/helpers/get_index_pattern';
Expand All @@ -28,6 +28,7 @@ import { FieldDescriptor, IndexPatternsFetcher } from '../../../data/server';

export async function getFields(
requestContext: RequestHandlerContext,
request: KibanaRequest,
framework: Framework,
indexPattern: string
) {
Expand All @@ -36,6 +37,7 @@ export async function getFields(
// level object passed from here. The layers should be refactored fully at some point, but for now
// this works and we are still using the New Platform services for these vis data portions.
const reqFacade: any = {
...request,
framework,
pre: {
indexPatternsService: new IndexPatternsFetcher(
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/vis_type_timeseries/server/lib/get_vis_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { RequestHandlerContext } from 'kibana/server';
import { KibanaRequest, RequestHandlerContext } from 'kibana/server';
import _ from 'lodash';
import { first, map } from 'rxjs/operators';
import { getPanelData } from './vis_data/get_panel_data';
Expand Down Expand Up @@ -56,16 +56,17 @@ export type GetVisData = (

export function getVisData(
requestContext: RequestHandlerContext,
options: GetVisDataOptions,
request: KibanaRequest<{}, {}, GetVisDataOptions>,
framework: Framework
): Promise<GetVisDataResponse> {
// NOTE / TODO: This facade has been put in place to make migrating to the New Platform easier. It
// removes the need to refactor many layers of dependencies on "req", and instead just augments the top
// level object passed from here. The layers should be refactored fully at some point, but for now
// this works and we are still using the New Platform services for these vis data portions.
const reqFacade: any = {
...request,
framework,
payload: options,
payload: request.body,
getUiSettingsService: () => requestContext.core.uiSettings.client,
getSavedObjectsClient: () => requestContext.core.savedObjects.client,
server: {
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/vis_type_timeseries/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import {
RequestHandlerContext,
Logger,
IRouter,
KibanaRequest,
} from 'src/core/server';
import { Observable } from 'rxjs';
import { Server } from 'hapi';
import { VisTypeTimeseriesConfig } from '.';
import { getVisData, GetVisData, GetVisDataOptions } from './lib/get_vis_data';
import { ValidationTelemetryService } from './validation_telemetry/validation_telemetry_service';
import { ValidationTelemetryService } from './validation_telemetry';
import { UsageCollectionSetup } from '../../usage_collection/server';
import { visDataRoutes } from './routes/vis';
// @ts-ignore
Expand Down Expand Up @@ -101,8 +102,11 @@ export class VisTypeTimeseriesPlugin implements Plugin<VisTypeTimeseriesSetup> {
})();

return {
getVisData: async (requestContext: RequestHandlerContext, options: GetVisDataOptions) => {
return await getVisData(requestContext, options, framework);
getVisData: async (
requestContext: RequestHandlerContext,
request: KibanaRequest<{}, {}, GetVisDataOptions>
) => {
return await getVisData(requestContext, request, framework);
},
addSearchStrategy: searchStrategyRegistry.addStrategy.bind(searchStrategyRegistry),
};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_timeseries/server/routes/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const fieldsRoutes = (framework: Framework) => {
},
async (context, req, res) => {
try {
return res.ok({ body: await getFields(context, framework, req.query.index) });
return res.ok({ body: await getFields(context, req, framework, req.query.index) });
} catch (err) {
if (isBoom(err) && err.output.statusCode === 401) {
return res.customError({
Expand Down
10 changes: 7 additions & 3 deletions src/plugins/vis_type_timeseries/server/routes/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { IRouter } from 'kibana/server';
import { IRouter, KibanaRequest } from 'kibana/server';
import { schema } from '@kbn/config-schema';
import { getVisData } from '../lib/get_vis_data';
import { getVisData, GetVisDataOptions } from '../lib/get_vis_data';
import { visPayloadSchema } from './post_vis_schema';
import { Framework, ValidationTelemetryServiceSetup } from '../index';

Expand Down Expand Up @@ -49,7 +49,11 @@ export const visDataRoutes = (
);
}
try {
const results = await getVisData(requestContext, request.body, framework);
const results = await getVisData(
requestContext,
request as KibanaRequest<{}, {}, GetVisDataOptions>,
framework
);
return response.ok({ body: results });
} catch (error) {
return response.internalError({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { once } from 'lodash';
import { elasticsearchJsPlugin } from '../../client/elasticsearch_rollup';

const callWithRequest = once(server => {
const config = { plugins: [elasticsearchJsPlugin] };
const cluster = server.plugins.elasticsearch.createCluster('rollup', config);

return cluster.callWithRequest;
console.log('>>>>>>>>>>>>');
console.log(server);
const client = server.newPlatform.setup.core.elasticsearch.createClient('rollup', {
plugins: [elasticsearchJsPlugin],
});
return (request, ...args) => client.asScoped(request).callAsCurrentUser(...args);
});

export const callWithRequestFactory = (server, request) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export const registerRollupSearchStrategy = (kbnServer, server) =>
RollupSearchCapabilities
);

addSearchStrategy(new RollupSearchStrategy(server));
addSearchStrategy(new RollupSearchStrategy(kbnServer));
});

0 comments on commit f00d2d9

Please sign in to comment.