Skip to content

Commit

Permalink
Return validationTelemerty and logging part back
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaDerevyankina committed May 6, 2020
1 parent 5d0a59e commit 8eb5bc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/plugins/vis_type_timeseries/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Observable } from 'rxjs';
import { Server } from 'hapi';
import { VisTypeTimeseriesConfig } from './config';
import { getVisData, GetVisData, GetVisDataOptions } from './lib/get_vis_data';
import { ValidationTelemetryService } from './validation_telemetry';
import { UsageCollectionSetup } from '../../usage_collection/server';
import { visDataRoutes } from './routes/vis';
// @ts-ignore
Expand Down Expand Up @@ -65,8 +66,11 @@ export interface Framework {
}

export class VisTypeTimeseriesPlugin implements Plugin<VisTypeTimeseriesSetup> {
private validationTelementryService: ValidationTelemetryService;

constructor(private readonly initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
this.validationTelementryService = new ValidationTelemetryService();
}

public setup(core: CoreSetup, plugins: VisTypeTimeseriesPluginSetupDependencies) {
Expand All @@ -88,9 +92,15 @@ export class VisTypeTimeseriesPlugin implements Plugin<VisTypeTimeseriesSetup> {
searchStrategyRegistry,
};

visDataRoutes(router, framework);
(async () => {
const validationTelemetry = await this.validationTelementryService.setup(core, {
...plugins,
globalConfig$,
});
visDataRoutes(router, framework, validationTelemetry);

fieldsRoutes(framework);
fieldsRoutes(framework);
})();

return {
getVisData: async (
Expand Down
25 changes: 22 additions & 3 deletions src/plugins/vis_type_timeseries/server/routes/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@
*/

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

export const visDataRoutes = (router: IRouter, framework: Framework) => {
const escapeHatch = schema.object({}, { unknowns: 'allow' });

export const visDataRoutes = (
router: IRouter,
framework: Framework,
{ logFailedValidation }: ValidationTelemetryServiceSetup
) => {
router.post(
{
path: '/api/metrics/vis/data',
validate: {
body: visPayloadSchema,
body: escapeHatch,
},
},
async (requestContext, request, response) => {
try {
visPayloadSchema.validate(request.body);
} catch (error) {
logFailedValidation();
const savedObjectId =
(typeof request.body === 'object' && (request.body as any).savedObjectId) ||
'unavailable';
framework.logger.warn(
`Request validation error: ${error.message} (saved object id: ${savedObjectId}). This most likely means your TSVB visualization contains outdated configuration. You can report this problem under https://github.com/elastic/kibana/issues/new?template=Bug_report.md`
);
}

try {
const results = await getVisData(
requestContext,
Expand Down

0 comments on commit 8eb5bc9

Please sign in to comment.