Skip to content

Commit

Permalink
[8.16] [Security solution] Remove legacy ESQL quick prompt (#201276) (#…
Browse files Browse the repository at this point in the history
…202540)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Security solution] Remove legacy ESQL quick prompt
(#201276)](#201276)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-02T16:47:18Z","message":"[Security
solution] Remove legacy ESQL quick prompt
(#201276)","sha":"30ceb1a0533364e6915bf544827d59cf441bcbf5","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:
SecuritySolution","backport:prev-major","Team:Security Generative
AI"],"title":"[Security solution] Remove legacy ESQL quick
prompt","number":201276,"url":"https://github.com/elastic/kibana/pull/201276","mergeCommit":{"message":"[Security
solution] Remove legacy ESQL quick prompt
(#201276)","sha":"30ceb1a0533364e6915bf544827d59cf441bcbf5"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201276","number":201276,"mergeCommit":{"message":"[Security
solution] Remove legacy ESQL quick prompt
(#201276)","sha":"30ceb1a0533364e6915bf544827d59cf441bcbf5"}}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
  • Loading branch information
kibanamachine and stephmilovic authored Dec 2, 2024
1 parent 264b11d commit 216722b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { KibanaRequest } from '@kbn/core-http-server';
import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server';
import type { MlPluginSetup } from '@kbn/ml-plugin/server';
import { DeleteByQueryRequest } from '@elastic/elasticsearch/lib/api/types';
import { i18n } from '@kbn/i18n';
import { getResourceName } from '.';
import { knowledgeBaseIngestPipeline } from '../ai_assistant_data_clients/knowledge_base/ingest_pipeline';
import { GetElser } from '../types';

Expand Down Expand Up @@ -106,3 +109,45 @@ export const deletePipeline = async ({ esClient, id }: DeletePipelineParams): Pr

return response.acknowledged;
};

export const removeLegacyQuickPrompt = async (esClient: ElasticsearchClient) => {
try {
const deleteQuery: DeleteByQueryRequest = {
index: `${getResourceName('prompts')}-*`,
query: {
bool: {
must: [
{
term: {
name: ESQL_QUERY_GENERATION_TITLE,
},
},
{
term: {
prompt_type: 'quick',
},
},
{
term: {
is_default: true,
},
},
],
},
},
};
return esClient.deleteByQuery(deleteQuery);
} catch (e) {
// swallow any errors
return {
total: 0,
};
}
};

const ESQL_QUERY_GENERATION_TITLE = i18n.translate(
'xpack.elasticAssistantPlugin.assistant.quickPrompts.esqlQueryGenerationTitle',
{
defaultMessage: 'ES|QL Query Generation',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { hasAIAssistantLicense } from '../routes/helpers';

const TOTAL_FIELDS_LIMIT = 2500;

function getResourceName(resource: string) {
export function getResourceName(resource: string) {
return `.kibana-elastic-ai-assistant-${resource}`;
}

Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/elastic_assistant/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { RequestContextFactory } from './routes/request_context_factory';
import { PLUGIN_ID } from '../common/constants';
import { registerRoutes } from './routes/register_routes';
import { appContextService } from './services/app_context';
import { createGetElserId } from './ai_assistant_service/helpers';
import { createGetElserId, removeLegacyQuickPrompt } from './ai_assistant_service/helpers';

export class ElasticAssistantPlugin
implements
Expand Down Expand Up @@ -109,6 +109,12 @@ export class ElasticAssistantPlugin
this.getElserId = createGetElserId(this.mlTrainedModelsProvider);
}
});
removeLegacyQuickPrompt(core.elasticsearch.client.asInternalUser)
.then((res) => {
if (res?.total)
this.logger.info(`Removed ${res.total} legacy quick prompts from AI Assistant`);
})
.catch(() => {});

return {
actions: plugins.actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { APP_UI_ID } from '../../../../common';
import * as i18n from './translations';
import {
KNOWLEDGE_BASE_CATEGORY,
PROMPT_CONTEXT_ALERT_CATEGORY,
PROMPT_CONTEXT_DETECTION_RULES_CATEGORY,
PROMPT_CONTEXT_EVENT_CATEGORY,
Expand All @@ -34,16 +33,6 @@ export const BASE_SECURITY_QUICK_PROMPTS: PromptResponse[] = [
promptType: PromptTypeEnum.quick,
consumer: APP_UI_ID,
},
{
name: i18n.ESQL_QUERY_GENERATION_TITLE,
content: i18n.ESQL_QUERY_GENERATION_PROMPT,
color: '#9170B8',
categories: [KNOWLEDGE_BASE_CATEGORY],
isDefault: true,
id: i18n.ESQL_QUERY_GENERATION_TITLE,
promptType: PromptTypeEnum.quick,
consumer: APP_UI_ID,
},
{
name: i18n.RULE_CREATION_TITLE,
content: i18n.RULE_CREATION_PROMPT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ export const ALERT_SUMMARIZATION_PROMPT = i18n.translate(
}
);

export const ESQL_QUERY_GENERATION_TITLE = i18n.translate(
'xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationTitle',
{
defaultMessage: 'ES|QL Query Generation',
}
);

export const ESQL_QUERY_GENERATION_PROMPT = i18n.translate(
'xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationPrompt',
{
defaultMessage:
"As an expert user of Elastic Security, please generate an accurate and valid ESQL query to detect the use case below. Your response should be formatted to be able to use immediately in an Elastic Security timeline or detection rule. Take your time with the answer, check your knowledge really well on all the functions I am asking for. For ES|QL answers specifically, you should only ever answer with what's available in your private knowledge. I cannot afford for queries to be inaccurate. Assume I am using the Elastic Common Schema and Elastic Agent.\n\nEnsure the answers are formatted in a way which is easily copyable as a separate code block in markdown.",
}
);

export const RULE_CREATION_TITLE = i18n.translate(
'xpack.securitySolution.assistant.quickPrompts.ruleCreationTitle',
{
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -37429,8 +37429,6 @@
"xpack.securitySolution.assistant.quickPrompts.alertSummarizationTitle": "Synthèse de l’alerte",
"xpack.securitySolution.assistant.quickPrompts.AutomationPrompt": "Quelle intégration d’Elastic Agent activée par Fleet dois-je utiliser pour collecter des logs et des évènements de :",
"xpack.securitySolution.assistant.quickPrompts.AutomationTitle": "Conseil sur l’intégration d’agent",
"xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationPrompt": "En tant qu'utilisateur expert d'Elastic Security, veuillez générer une requête ESQL valide et précise pour détecter le cas d'utilisation ci-dessous. Votre réponse doit être formatée pour pouvoir être utilisée immédiatement dans une chronologie ou une règle de détection d’Elastic Security. Prenez votre temps pour répondre, vérifiez bien vos connaissances et toutes les fonctions que je vous demande. Pour les réponses ES|QL en particulier, vous devez toujours répondre uniquement avec ce qui est disponible dans vos connaissances personnelles. Je ne peux pas me permettre que les requêtes soient inexactes. Supposez que j'utilise le Elastic Common Schema et l'agent Elastic. Veillez à ce que les réponses soient formatées de manière à pouvoir être facilement copiées sous la forme d'un bloc de code distinct dans le markdown.",
"xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationTitle": "Génération de requête ES|QL",
"xpack.securitySolution.assistant.quickPrompts.ruleCreationPrompt": "En tant qu’utilisateur expert d’Elastic Security, veuillez générer une requête EQL valide et précise pour détecter le cas d’utilisation ci-dessous. Votre réponse doit être formatée pour pouvoir être utilisée immédiatement dans une chronologie ou une règle de détection d’Elastic Security. Si Elastic Security a déjà une règle prédéfinie pour le cas d’utilisation ou pour un cas similaire, veuillez fournir un lien vers cette règle et la décrire.",
"xpack.securitySolution.assistant.quickPrompts.ruleCreationTitle": "Génération de requête",
"xpack.securitySolution.assistant.quickPrompts.splQueryConversionPrompt": "J’ai la requête suivante d’une plateforme SIEM précédente. En tant qu’utilisateur expert d’Elastic Security, veuillez suggérer un équivalent EQL Elastic. Je dois être capable de la copier immédiatement dans une chronologie Elastic Security.",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -37397,8 +37397,6 @@
"xpack.securitySolution.assistant.quickPrompts.alertSummarizationTitle": "アラート要約",
"xpack.securitySolution.assistant.quickPrompts.AutomationPrompt": "ログやイベントの収集には、どのFleet対応Elasticエージェント統合を使用すべきですか。",
"xpack.securitySolution.assistant.quickPrompts.AutomationTitle": "エージェント統合のアドバイス",
"xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationPrompt": "Elasticセキュリティのエキスパートユーザーとして、以下のユースケースを検出するための正確で有効なESQLクエリを作成してください。回答は、Elasticセキュリティのタイムラインまたは検出ルールですぐに使用できるように書式設定してください。答えに時間をかけて、求められているすべての機能について、あなたの知識をよく確認してください。ES|QLの回答は、特に、あなたの個人的な知識で利用可能なもののみを答えてください。クエリが不正確であることは許容できません。Elastic Common SchemaとElasticエージェントを使用していると仮定します。回答がマークダウンの独立したコードブロックとして簡単にコピーできるように書式設定されていることを確認してください。",
"xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationTitle": "ES|QLクエリ生成",
"xpack.securitySolution.assistant.quickPrompts.ruleCreationPrompt": "Elasticセキュリティのエキスパートユーザーとして、以下のユースケースを検出するための正確で有効なEQLクエリを作成してください。回答は、Elasticセキュリティのタイムラインまたは検出ルールですぐに使用できるように書式設定してください。そのユースケースに対応するルールがすでにElasticセキュリティに組み込まれている場合、または類似のルールが組み込まれている場合は、そのルールへのリンクと説明を入力してください。",
"xpack.securitySolution.assistant.quickPrompts.ruleCreationTitle": "クエリ生成",
"xpack.securitySolution.assistant.quickPrompts.splQueryConversionPrompt": "以前のSIEMプラットフォームから次のクエリを受け取りました。Elasticセキュリティのエキスパートユーザーとして、同等のElastic EQLを提案してください。すぐにそれをElasticのセキュリティタイムラインにコピーできます。",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -37465,8 +37465,6 @@
"xpack.securitySolution.assistant.quickPrompts.alertSummarizationTitle": "告警汇总",
"xpack.securitySolution.assistant.quickPrompts.AutomationPrompt": "我应使用哪个启用 Fleet 的 Elastic 代理集成从以下项中收集日志和事件:",
"xpack.securitySolution.assistant.quickPrompts.AutomationTitle": "代理集成建议",
"xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationPrompt": "作为 Elastic Security 的专家用户,请生成准确、有效的 ESQL 查询来检测以下用例。应对您的响应进行格式化,以便可以立即在 Elastic Security 时间线或检测规则中使用。请花点时间提供答案,检验您是否清楚了解我所询问的所有功能。具体来说,对于 ES|QL 答案,您应仅根据自己的个人观点进行解答。我无法承担查询不准确的后果。假设我正使用 Elastic Common Schema 和 Elastic 代理。确保以可轻松复制为 Markdown 中的独立代码块的方式设置答案的格式。",
"xpack.securitySolution.assistant.quickPrompts.esqlQueryGenerationTitle": "ES|QL 查询生成",
"xpack.securitySolution.assistant.quickPrompts.ruleCreationPrompt": "作为 Elastic Security 的专家用户,请生成准确、有效的 EQL 查询来检测以下用例。应对您的响应进行格式化,以便可以立即在 Elastic Security 时间线或检测规则中使用。如果 Elastic Security 已经为此用例预构建了规则,或具有类似规则,请提供该规则的链接并做出描述。",
"xpack.securitySolution.assistant.quickPrompts.ruleCreationTitle": "查询生成",
"xpack.securitySolution.assistant.quickPrompts.splQueryConversionPrompt": "我具有以下来自之前 SIEM 平台的查询。作为 Elastic Security 的专家用户,请提议一个 Elastic EQL 等价查询。我应能够立即将其复制到 Elastic Security 时间线。",
Expand Down

0 comments on commit 216722b

Please sign in to comment.