Skip to content

Commit

Permalink
fix: type declaration
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Dec 18, 2023
1 parent 357b083 commit 51ab4aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 5 additions & 3 deletions server/parsers/ppl_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { MessageParser } from '../types';

const extractPPLQueries = (content: string) => {
return Array.from(content.matchAll(/(^|[\n\r]|:)\s*(source\s*=\s*.+)/gi)).map(
(match) => match[2]
);
};

export const PPLParsers = {
export const PPLParsers: MessageParser = {
id: 'ppl_visualization_message',
async parserProvider(interaction) {
const ppls: string[] = interaction.additional_info?.["PPLTool.output"]?.flatMap((item: string) => {
const ppls: string[] = (interaction.additional_info?.["PPLTool.output"] as string[] | null)?.flatMap((item: string) => {
let ppl: string = ""
try {
const outputResp = JSON.parse(item);
Expand All @@ -22,7 +24,7 @@ export const PPLParsers = {
}

return extractPPLQueries(ppl);
});
}) || [];

if (!ppls.length) return [];

Expand Down
14 changes: 6 additions & 8 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ import {
searchSavedObject,
visualizationSavedObject,
} from './saved_objects/observability_saved_object';
import { ObservabilityPluginSetup, ObservabilityPluginStart } from './types';
import { ObservabilityPluginSetup, ObservabilityPluginStart, AssistantPluginSetup } from './types';
import { PPLParsers } from './parsers/ppl_parser';

export class ObservabilityPlugin
implements Plugin<ObservabilityPluginSetup, ObservabilityPluginStart, {
assistantDashboards?: {
registerMessageParser: () => void
}
}> {
implements Plugin<ObservabilityPluginSetup, ObservabilityPluginStart> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup, deps) {
public setup(core: CoreSetup, deps: {
assistantDashboards?: AssistantPluginSetup
}) {
const { assistantDashboards } = deps;
this.logger.debug('Observability: Setup');
const router = core.http.createRouter();
Expand Down Expand Up @@ -127,7 +125,7 @@ export class ObservabilityPlugin
},
}));

assistantDashboards.registerMessageParser(PPLParsers);
assistantDashboards?.registerMessageParser(PPLParsers);

return {};
}
Expand Down
8 changes: 8 additions & 0 deletions server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@
export interface ObservabilityPluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ObservabilityPluginStart {}

/**
* Introduce a compile dependency on dashboards-assistant
* as observerability need some types from the plugin.
* It will gives an type error when dashboards-assistant is not installed so add a ts-ignore to suppress the error.
*/
// @ts-ignore
export type { AssistantPluginSetup, MessageParser } from "../../dashboards-assistant/server";

0 comments on commit 51ab4aa

Please sign in to comment.