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] Support log pattern if there is dsl and index passed for alert summary. #340

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export const GeneratePopoverBody: React.FC<{
? 'os_insight'
: 'user_insight'
: undefined;
const index = contextObj?.additionalInfo?.index;
const dsl = contextObj?.additionalInfo?.dsl;

await httpSetup
?.post(SUMMARY_ASSISTANT_API.SUMMARIZE, {
Expand All @@ -110,6 +112,8 @@ export const GeneratePopoverBody: React.FC<{
insightType,
question: summarizationQuestion,
context: contextContent,
index,
dsl,
}),
query: dataSourceQuery,
})
Expand Down
18 changes: 13 additions & 5 deletions server/routes/summary_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getAgentIdByConfigName, searchAgent } from './get_agent';
import { AssistantServiceSetup } from '../services/assistant_service';

const SUMMARY_AGENT_CONFIG_ID = 'os_summary';
const LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID = 'os_summary_with_logPattern';
const OS_INSIGHT_AGENT_CONFIG_ID = 'os_insight';
const DATA2SUMMARY_AGENT_CONFIG_ID = 'os_data2summary';
let osInsightAgentId: string | undefined;
Expand All @@ -29,6 +30,8 @@ export function registerSummaryAssistantRoutes(
insightType: schema.maybe(schema.string()),
question: schema.string(),
context: schema.maybe(schema.string()),
index: schema.maybe(schema.string()),
dsl: schema.maybe(schema.string()),
}),
query: schema.object({
dataSourceId: schema.maybe(schema.string()),
Expand All @@ -41,9 +44,15 @@ export function registerSummaryAssistantRoutes(
dataSourceId: req.query.dataSourceId,
});
const assistantClient = assistantService.getScopedClient(req, context);
const response = await assistantClient.executeAgentByConfigName(SUMMARY_AGENT_CONFIG_ID, {
const agentConfigId =
req.body.index && req.body.dsl
? LOG_PATTERN_SUMMARY_AGENT_CONFIG_ID
: SUMMARY_AGENT_CONFIG_ID;
const response = await assistantClient.executeAgentByConfigName(agentConfigId, {
context: req.body.context,
question: req.body.question,
index: req.body.index,
input: req.body.dsl,
});
let summary;
let insightAgentIdExists = false;
Expand Down Expand Up @@ -114,14 +123,13 @@ export function registerSummaryAssistantRoutes(
question: req.body.question,
});
try {
let result = response.body.inference_results[0].output[0].result;
result = JSON.parse(result).output.text;
return res.ok({ body: result });
return res.ok({ body: response.body.inference_results[0].output[0].result });
} catch (e) {
return res.internalError();
} finally {
// Reset userInsightAgentId in case users update their insight agent.
// Reset both agents id in case of update
userInsightAgentId = undefined;
osInsightAgentId = undefined;
}
})
);
Expand Down
Loading