Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Pass dataSourceId for alert summary/insight #322

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions public/components/incontext_insight/generate_popover_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { useEffectOnce } from 'react-use';
import { METRIC_TYPE } from '@osd/analytics';
import { MessageActions } from '../../tabs/chat/messages/message_action';
import { IncontextInsight as IncontextInsightInput } from '../../types';
import { ContextObj, IncontextInsight as IncontextInsightInput } from '../../types';
import { getNotifications } from '../../services';
import { HttpSetup } from '../../../../../src/core/public';
import { SUMMARY_ASSISTANT_API } from '../../../common/constants/llm';
Expand Down Expand Up @@ -53,7 +53,7 @@ export const GeneratePopoverBody: React.FC<{

const onGenerateSummary = (summarizationQuestion: string) => {
const summarize = async () => {
let contextObj;
let contextObj: ContextObj | undefined;
try {
contextObj = (await incontextInsight.contextProvider?.()) ?? undefined;
} catch (e) {
Expand All @@ -67,6 +67,8 @@ export const GeneratePopoverBody: React.FC<{
return;
}
const contextContent = contextObj?.context || '';
const dataSourceId = contextObj?.dataSourceId;
const dataSourceQuery = dataSourceId ? { dataSourceId } : {};
let summaryType: string;
const endIndex = incontextInsight.key.indexOf('_', 0);
if (endIndex !== -1) {
Expand All @@ -89,6 +91,7 @@ export const GeneratePopoverBody: React.FC<{
question: summarizationQuestion,
context: contextContent,
}),
query: dataSourceQuery,
})
.then((response) => {
const summaryContent = response.summary;
Expand All @@ -97,6 +100,7 @@ export const GeneratePopoverBody: React.FC<{
setInsightAvailable(insightAgentIdExists);
if (insightAgentIdExists) {
onGenerateInsightBasedOnSummary(
dataSourceQuery,
summaryType,
insightType,
summaryContent,
Expand All @@ -120,6 +124,7 @@ export const GeneratePopoverBody: React.FC<{
};

const onGenerateInsightBasedOnSummary = (
dataSourceQuery: {},
summaryType: string,
insightType: string,
summaryContent: string,
Expand All @@ -136,6 +141,7 @@ export const GeneratePopoverBody: React.FC<{
context,
question: insightQuestion,
}),
query: dataSourceQuery,
})
.then((response) => {
setInsight(response);
Expand Down
1 change: 1 addition & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export type IncontextInsights = Map<string, IncontextInsight>;
export interface ContextObj {
context: string;
additionalInfo: Record<string, string>;
dataSourceId?: string;
}

export interface IncontextInsight {
Expand Down
Loading