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

[Security Assistant] Enables automatic setup of Knowledge Base and LangGraph code paths for 8.15 #188168

Merged
merged 26 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9965507
Enables kbDataClient and LangGraph code paths
spong Jul 11, 2024
150cfe3
Up ML node memory for ci-cloud-deploy, and enable assistantModelEvalu…
spong Jul 11, 2024
5e7f13d
Merge branch 'main' of github.com:elastic/kibana into bye-bye-feature…
spong Jul 11, 2024
eb44c75
Invoke lint remover
spong Jul 12, 2024
88740c7
Merge branch 'main' of github.com:elastic/kibana into bye-bye-feature…
spong Jul 12, 2024
b3b3d02
Merge branch 'main' of github.com:elastic/kibana into bye-bye-feature…
spong Jul 15, 2024
27125f5
Remove RAG on alerts UI setting, and more test cleanup
spong Jul 15, 2024
0b4ec40
fix post actions tests
stephmilovic Jul 15, 2024
5a38b3b
fix lint
stephmilovic Jul 15, 2024
8d94c76
Removing kb and rag telemetry, and performs kb availability check
spong Jul 15, 2024
2aca94b
Merge branch 'main' of github.com:elastic/kibana into bye-bye-feature…
spong Jul 15, 2024
bd60ffb
Removes knowledge_history from prompts
spong Jul 15, 2024
e185808
Prompt update and removing unused constants
spong Jul 15, 2024
5207172
Merge branch 'main' of github.com:elastic/kibana into bye-bye-feature…
spong Jul 16, 2024
fe0992c
Test fix
spong Jul 16, 2024
18d089b
rm test, fix prompt, rm unused function
stephmilovic Jul 16, 2024
6cf9940
Merge branch 'bye-bye-feature-flag' of github.com:spong/kibana into b…
stephmilovic Jul 16, 2024
970cac9
Test and lint fixes
spong Jul 16, 2024
5fb60f8
Removed unused functions and update todo
spong Jul 16, 2024
9d1295f
fix chat complete test
stephmilovic Jul 16, 2024
42dda8e
Merge branch 'main' of github.com:elastic/kibana into bye-bye-feature…
spong Jul 17, 2024
1abd1de
Merge with main and updating new kb settings management page
spong Jul 17, 2024
5826016
Remove cloud deploy settings and FF change in prep for merging
spong Jul 17, 2024
4cebdfb
Memory limit update typo
spong Jul 17, 2024
c604db8
Increase bulk add timout
spong Jul 17, 2024
e9722a4
Merge branch 'main' into bye-bye-feature-flag
spong Jul 17, 2024
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
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/cloud/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
],
"id": "ml",
"size": {
"value": 1024,
spong marked this conversation as resolved.
Show resolved Hide resolved
"value": 4096,
"resource": "memory"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export const ExecuteConnectorRequestBody = z.object({
alertsIndexPattern: z.string().optional(),
allow: z.array(z.string()).optional(),
allowReplacement: z.array(z.string()).optional(),
isEnabledKnowledgeBase: z.boolean().optional(),
isEnabledRAGAlerts: z.boolean().optional(),
replacements: Replacements,
size: z.number().optional(),
langSmithProject: z.string().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ paths:
type: array
items:
type: string
isEnabledKnowledgeBase:
type: boolean
isEnabledRAGAlerts:
type: boolean
replacements:
$ref: '../conversations/common_attributes.schema.yaml#/components/schemas/Replacements'
size:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,6 @@ describe('AlertsSettings', () => {
jest.clearAllMocks();
});

it('updates the knowledgeBase settings when the switch is toggled', () => {
const knowledgeBase: KnowledgeBaseConfig = {
isEnabledRAGAlerts: false,
isEnabledKnowledgeBase: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
};
const setUpdatedKnowledgeBaseSettings = jest.fn();

render(
<AlertsSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
/>
);

const alertsSwitch = screen.getByTestId('alertsSwitch');
fireEvent.click(alertsSwitch);

expect(setUpdatedKnowledgeBaseSettings).toHaveBeenCalledWith({
isEnabledRAGAlerts: true,
isEnabledKnowledgeBase: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
});
});

it('updates the knowledgeBase settings when the alerts range slider is changed', () => {
const setUpdatedKnowledgeBaseSettings = jest.fn();
const knowledgeBase: KnowledgeBaseConfig = {
Expand All @@ -66,22 +41,4 @@ describe('AlertsSettings', () => {
latestAlerts: 10,
});
});

it('enables the alerts range slider when knowledgeBase.isEnabledRAGAlerts is true', () => {
const setUpdatedKnowledgeBaseSettings = jest.fn();
const knowledgeBase: KnowledgeBaseConfig = {
isEnabledRAGAlerts: true, // <-- true
isEnabledKnowledgeBase: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
};

render(
<AlertsSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
/>
);

expect(screen.getByTestId('alertsRange')).not.toBeDisabled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import {
EuiFormRow,
EuiRange,
EuiSpacer,
EuiSwitch,
EuiSwitchEvent,
EuiText,
useGeneratedHtmlId,
} from '@elastic/eui';
import { css } from '@emotion/react';
import React, { useCallback } from 'react';
import React from 'react';

import { KnowledgeBaseConfig } from '../../assistant/types';
import * as i18n from '../../knowledge_base/translations';
Expand All @@ -36,16 +34,6 @@ interface Props {
const AlertsSettingsComponent = ({ knowledgeBase, setUpdatedKnowledgeBaseSettings }: Props) => {
const inputRangeSliderId = useGeneratedHtmlId({ prefix: 'inputRangeSlider' });

const onEnableAlertsChange = useCallback(
(event: EuiSwitchEvent) => {
setUpdatedKnowledgeBaseSettings({
...knowledgeBase,
isEnabledRAGAlerts: event.target.checked,
});
},
[knowledgeBase, setUpdatedKnowledgeBaseSettings]
);

return (
<>
<EuiFormRow
Expand All @@ -57,14 +45,7 @@ const AlertsSettingsComponent = ({ knowledgeBase, setUpdatedKnowledgeBaseSetting
}
`}
>
<EuiSwitch
checked={knowledgeBase.isEnabledRAGAlerts}
compressed
data-test-subj="alertsSwitch"
label={i18n.ALERTS_LABEL}
onChange={onEnableAlertsChange}
showLabel={false}
/>
<></>
</EuiFormRow>

<EuiSpacer size="xs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ const apiConfig: Record<'openai' | 'bedrock' | 'gemini', ApiConfig> = {
};

const fetchConnectorArgs: FetchConnectorExecuteAction = {
isEnabledRAGAlerts: false,
apiConfig: apiConfig.openai,
isEnabledKnowledgeBase: true,
assistantStreamingEnabled: true,
http: mockHttp,
message: 'This is a test',
Expand Down Expand Up @@ -75,7 +73,7 @@ describe('API tests', () => {
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...staticDefaults,
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","actionTypeId":".gen-ai","replacements":{},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","actionTypeId":".gen-ai","replacements":{}}',
}
);
});
Expand All @@ -87,12 +85,12 @@ describe('API tests', () => {
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...streamingDefaults,
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gen-ai","replacements":{},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gen-ai","replacements":{}}',
}
);
});

it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is bedrock and isEnabledKnowledgeBase is true', async () => {
it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is bedrock', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.bedrock,
Expand All @@ -104,53 +102,15 @@ describe('API tests', () => {
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".bedrock","replacements":{},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".bedrock","replacements":{}}',
}
);
});

it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is bedrock and isEnabledKnowledgeBase is false and isEnabledRAGAlerts is true', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.bedrock,
isEnabledKnowledgeBase: false,
isEnabledRAGAlerts: true,
};

await fetchConnectorExecuteAction(testProps);

expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".bedrock","replacements":{},"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true}',
}
);
});

it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is gemini and isEnabledKnowledgeBase is true', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.gemini,
};

await fetchConnectorExecuteAction(testProps);

expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gemini","replacements":{},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
}
);
});

it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is gemini and isEnabledKnowledgeBase is false and isEnabledRAGAlerts is true', async () => {
it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is gemini', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.gemini,
isEnabledKnowledgeBase: false,
isEnabledRAGAlerts: true,
};

await fetchConnectorExecuteAction(testProps);
Expand All @@ -159,16 +119,15 @@ describe('API tests', () => {
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gemini","replacements":{},"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true}',
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gemini","replacements":{}}',
}
);
});

it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is .bedrock and isEnabledKnowledgeBase is false', async () => {
it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is .bedrock', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.bedrock,
isEnabledKnowledgeBase: false,
};

await fetchConnectorExecuteAction(testProps);
Expand All @@ -177,15 +136,14 @@ describe('API tests', () => {
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".bedrock","replacements":{},"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false}',
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".bedrock","replacements":{}}',
}
);
});

it('calls the api with the expected optional request parameters', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
isEnabledRAGAlerts: true,
assistantStreamingEnabled: false,
alertsIndexPattern: '.alerts-security.alerts-default',
replacements: { auuid: 'real.hostname' },
Expand All @@ -198,7 +156,7 @@ describe('API tests', () => {
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...staticDefaults,
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","actionTypeId":".gen-ai","replacements":{"auuid":"real.hostname"},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":true,"alertsIndexPattern":".alerts-security.alerts-default","size":30}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","actionTypeId":".gen-ai","replacements":{"auuid":"real.hostname"},"alertsIndexPattern":".alerts-security.alerts-default","size":30}',
}
);
});
Expand Down Expand Up @@ -239,7 +197,6 @@ describe('API tests', () => {

const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
isEnabledKnowledgeBase: false,
};

const result = await fetchConnectorExecuteAction(testProps);
Expand All @@ -258,7 +215,6 @@ describe('API tests', () => {
});
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
isEnabledKnowledgeBase: false,
};

const result = await fetchConnectorExecuteAction(testProps);
Expand All @@ -281,7 +237,7 @@ describe('API tests', () => {
expect(result).toEqual({ response: API_ERROR, isStream: false, isError: true });
});

it('returns the original when isEnabledKnowledgeBase is true, and `content` is not JSON', async () => {
it('returns the original when `content` is not JSON', async () => {
const response = 'plain text content';

(mockHttp.fetch as jest.Mock).mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export * from './prompts';

export interface FetchConnectorExecuteAction {
conversationId: string;
isEnabledRAGAlerts: boolean;
alertsIndexPattern?: string;
isEnabledKnowledgeBase: boolean;
assistantStreamingEnabled: boolean;
apiConfig: ApiConfig;
http: HttpSetup;
Expand All @@ -40,9 +38,7 @@ export interface FetchConnectorExecuteResponse {

export const fetchConnectorExecuteAction = async ({
conversationId,
isEnabledRAGAlerts,
spong marked this conversation as resolved.
Show resolved Hide resolved
alertsIndexPattern,
isEnabledKnowledgeBase,
assistantStreamingEnabled,
http,
message,
Expand All @@ -56,7 +52,6 @@ export const fetchConnectorExecuteAction = async ({
const isStream = assistantStreamingEnabled;

const optionalRequestParams = getOptionalRequestParams({
isEnabledRAGAlerts,
alertsIndexPattern,
size,
});
Expand All @@ -68,8 +63,6 @@ export const fetchConnectorExecuteAction = async ({
conversationId,
actionTypeId: apiConfig.actionTypeId,
replacements,
isEnabledKnowledgeBase,
isEnabledRAGAlerts,
langSmithProject:
traceOptions?.langSmithProject === '' ? undefined : traceOptions?.langSmithProject,
langSmithApiKey:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,8 @@ describe('helpers', () => {
});

describe('getOptionalRequestParams', () => {
it('should return an empty object when alerts is false', () => {
const params = {
isEnabledRAGAlerts: false, // <-- false
alertsIndexPattern: 'indexPattern',
size: 10,
};

const result = getOptionalRequestParams(params);

expect(result).toEqual({});
});

it('should return the optional request params when alerts is true', () => {
const params = {
isEnabledRAGAlerts: true,
alertsIndexPattern: 'indexPattern',
size: 10,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,15 @@ interface OptionalRequestParams {
}

export const getOptionalRequestParams = ({
isEnabledRAGAlerts,
alertsIndexPattern,
size,
}: {
isEnabledRAGAlerts: boolean;
alertsIndexPattern?: string;
size?: number;
}): OptionalRequestParams => {
const optionalAlertsIndexPattern = alertsIndexPattern ? { alertsIndexPattern } : undefined;
const optionalSize = size ? { size } : undefined;

// the settings toggle must be enabled:
if (!isEnabledRAGAlerts) {
return {}; // don't send any optional params
}

return {
...optionalAlertsIndexPattern,
...optionalSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import { Conversation } from '../assistant_context/types';
import { getGenAiConfig } from '../connectorland/helpers';
import { AssistantAnimatedIcon } from './assistant_animated_icon';
import { useFetchAnonymizationFields } from './api/anonymization_fields/use_fetch_anonymization_fields';
import { InstallKnowledgeBaseButton } from '../knowledge_base/install_knowledge_base_button';
import { SetupKnowledgeBaseButton } from '../knowledge_base/setup_knowledge_base_button';
import { useFetchPrompts } from './api/prompts/use_fetch_prompts';

export interface Props {
Expand Down Expand Up @@ -778,7 +778,7 @@ const AssistantComponent: React.FC<Props> = ({
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<InstallKnowledgeBaseButton />
<SetupKnowledgeBaseButton />
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
Expand Down
Loading