Skip to content

Commit be79b98

Browse files
authored
Merge branch 'main' into presentation/migrate_add_trigger_action
2 parents 9860f94 + 6536c76 commit be79b98

30 files changed

Lines changed: 962 additions & 114 deletions

File tree

config/serverless.security.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,6 @@ xpack.alerting.rules.run.ruleTypeOverrides:
211211
# These features are disabled in Serverless until fully tested
212212
xpack.securitySolution.enableExperimental:
213213
- privilegedUserMonitoringDisabled
214+
215+
# AI Assistant config
216+
aiAssistantManagementSelection.preferredAIAssistantType: 'security'

src/platform/packages/shared/serverless/settings/security_project/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export const SECURITY_PROJECT_SETTINGS = [
2626
settings.SECURITY_SOLUTION_ENABLE_GRAPH_VISUALIZATION_SETTING,
2727
settings.SECURITY_SOLUTION_ENABLE_ASSET_INVENTORY_SETTING,
2828
settings.SECURITY_SOLUTION_ENABLE_CLOUD_CONNECTOR_SETTING,
29+
settings.AI_ASSISTANT_PREFERRED_AI_ASSISTANT_TYPE,
2930
];

src/platform/plugins/shared/ai_assistant_management/selection/common/ai_assistant_type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
export enum AIAssistantType {
1111
Observability = 'observability',
12+
Security = 'security',
1213
Default = 'default',
1314
Never = 'never',
1415
}

src/platform/plugins/shared/ai_assistant_management/selection/kibana.jsonc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
"aiAssistantManagementSelection"
1414
],
1515
"requiredPlugins": [
16-
"management"
16+
"management",
1717
],
1818
"optionalPlugins": [
1919
"home",
2020
"serverless",
21-
"features"
21+
"features",
22+
"cloud"
2223
],
2324
"requiredBundles": [
2425
"kibanaReact"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { CoreStart, PluginInitializerContext } from '@kbn/core/public';
11+
import { AIAssistantManagementPlugin } from './plugin';
12+
import { AIAssistantType } from '../common/ai_assistant_type';
13+
import { PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY } from '../common/ui_setting_keys';
14+
15+
describe('AI Assistant Management Selection Plugin', () => {
16+
it('uses the correct setting key to get the correct value from uiSettings', async () => {
17+
const plugin = new AIAssistantManagementPlugin({
18+
config: {
19+
get: jest.fn(),
20+
},
21+
env: { packageInfo: { buildFlavor: 'traditional', branch: 'main' } },
22+
} as unknown as PluginInitializerContext);
23+
24+
const coreStart = {
25+
uiSettings: {
26+
get: jest.fn((key: string) => {
27+
if (key === PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY) {
28+
return AIAssistantType.Default;
29+
}
30+
}),
31+
},
32+
} as unknown as CoreStart;
33+
34+
const result = plugin.start(coreStart);
35+
36+
const collected: any[] = [];
37+
const subscription = result.aiAssistantType$.subscribe((value) => {
38+
collected.push(value);
39+
});
40+
subscription.unsubscribe();
41+
42+
const allCalls = (coreStart.uiSettings.get as jest.Mock).mock.calls;
43+
expect(allCalls).toEqual([['aiAssistant:preferredAIAssistantType']]);
44+
expect(collected).toEqual([AIAssistantType.Default]);
45+
});
46+
});

src/platform/plugins/shared/ai_assistant_management/selection/server/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const configSchema = schema.object({
1818
schema.literal(AIAssistantType.Default),
1919
schema.literal(AIAssistantType.Never),
2020
schema.literal(AIAssistantType.Observability),
21+
schema.literal(AIAssistantType.Security),
2122
],
2223
{ defaultValue: AIAssistantType.Default }
2324
),
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { PluginInitializerContext, CoreSetup } from '@kbn/core/server';
11+
import type { AIAssistantManagementSelectionPluginServerDependenciesSetup } from './types';
12+
import { AIAssistantType } from '../common/ai_assistant_type';
13+
import { PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY } from '../common/ui_setting_keys';
14+
import { classicSetting } from './src/settings/classic_setting';
15+
import { observabilitySolutionSetting } from './src/settings/observability_setting';
16+
import { securitySolutionSetting } from './src/settings/security_setting';
17+
import { AIAssistantManagementSelectionPlugin } from './plugin';
18+
19+
describe('plugin', () => {
20+
beforeEach(() => {
21+
jest.clearAllMocks();
22+
});
23+
describe('stateless', () => {
24+
beforeEach(() => {
25+
jest.clearAllMocks();
26+
});
27+
const initializerContext = {
28+
env: {
29+
packageInfo: {
30+
buildFlavor: 'serverless',
31+
},
32+
},
33+
config: {
34+
get: jest.fn(),
35+
},
36+
} as unknown as PluginInitializerContext;
37+
38+
const coreSetup = {
39+
uiSettings: {
40+
register: jest.fn(),
41+
},
42+
capabilities: {
43+
registerProvider: jest.fn(),
44+
},
45+
} as unknown as CoreSetup;
46+
47+
const setupDeps = {
48+
management: {
49+
sections: {
50+
getSection: jest.fn(),
51+
},
52+
},
53+
serverless: {
54+
uiSettings: {
55+
register: jest.fn(),
56+
},
57+
},
58+
};
59+
60+
it('registers correct uiSettings for serverless oblt', () => {
61+
(initializerContext.config.get as jest.Mock).mockReturnValue({
62+
preferredAIAssistantType: AIAssistantType.Observability,
63+
});
64+
const aiAssistantManagementSelectionPlugin = new AIAssistantManagementSelectionPlugin(
65+
initializerContext
66+
);
67+
aiAssistantManagementSelectionPlugin.setup(coreSetup, {
68+
...setupDeps,
69+
cloud: {
70+
serverless: {
71+
projectType: 'observability',
72+
},
73+
},
74+
} as unknown as AIAssistantManagementSelectionPluginServerDependenciesSetup);
75+
76+
expect(coreSetup.uiSettings.register).toHaveBeenCalledTimes(1);
77+
78+
expect(coreSetup.uiSettings.register).toHaveBeenCalledWith({
79+
[PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY]: {
80+
...observabilitySolutionSetting,
81+
value: AIAssistantType.Observability,
82+
},
83+
});
84+
});
85+
86+
it('registers correct uiSettings for serverless security', () => {
87+
(initializerContext.config.get as jest.Mock).mockReturnValue({
88+
preferredAIAssistantType: AIAssistantType.Security,
89+
});
90+
const aiAssistantManagementSelectionPlugin = new AIAssistantManagementSelectionPlugin(
91+
initializerContext
92+
);
93+
aiAssistantManagementSelectionPlugin.setup(coreSetup, {
94+
...setupDeps,
95+
cloud: {
96+
serverless: {
97+
projectType: 'security',
98+
},
99+
},
100+
} as unknown as AIAssistantManagementSelectionPluginServerDependenciesSetup);
101+
102+
expect(coreSetup.uiSettings.register).toHaveBeenCalledTimes(1);
103+
104+
expect(coreSetup.uiSettings.register).toHaveBeenCalledWith({
105+
[PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY]: {
106+
...securitySolutionSetting,
107+
value: AIAssistantType.Security,
108+
},
109+
});
110+
});
111+
112+
it('registers correct uiSettings for serverless search', () => {
113+
(initializerContext.config.get as jest.Mock).mockReturnValue({
114+
preferredAIAssistantType: undefined,
115+
});
116+
const aiAssistantManagementSelectionPlugin = new AIAssistantManagementSelectionPlugin(
117+
initializerContext
118+
);
119+
aiAssistantManagementSelectionPlugin.setup(coreSetup, {
120+
...setupDeps,
121+
cloud: {
122+
serverless: {
123+
projectType: 'search',
124+
},
125+
},
126+
} as unknown as AIAssistantManagementSelectionPluginServerDependenciesSetup);
127+
128+
expect(coreSetup.uiSettings.register).toHaveBeenCalledTimes(1);
129+
expect(coreSetup.uiSettings.register).toHaveBeenCalledWith({
130+
[PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY]: {
131+
...classicSetting,
132+
value: AIAssistantType.Default,
133+
},
134+
});
135+
});
136+
});
137+
138+
describe('stateful', () => {
139+
it('uses the correct setting key to get the correct value from uiSettings', async () => {
140+
const initializerContext = {
141+
env: {
142+
packageInfo: {
143+
buildFlavor: 'classic',
144+
},
145+
},
146+
config: {
147+
get: jest.fn().mockReturnValue({
148+
preferredAIAssistantType: AIAssistantType.Observability,
149+
}),
150+
},
151+
} as unknown as PluginInitializerContext;
152+
const aiAssistantManagementSelectionPlugin = new AIAssistantManagementSelectionPlugin(
153+
initializerContext
154+
);
155+
156+
const coreSetup = {
157+
uiSettings: {
158+
register: jest.fn(),
159+
},
160+
capabilities: {
161+
registerProvider: jest.fn(),
162+
},
163+
} as unknown as CoreSetup;
164+
165+
const setupDeps = {
166+
management: {
167+
sections: {
168+
getSection: jest.fn(),
169+
},
170+
},
171+
serverless: {
172+
uiSettings: {
173+
register: jest.fn(),
174+
},
175+
},
176+
} as unknown as AIAssistantManagementSelectionPluginServerDependenciesSetup;
177+
178+
aiAssistantManagementSelectionPlugin.setup(coreSetup, setupDeps);
179+
180+
expect(coreSetup.uiSettings.register).toHaveBeenCalledTimes(1);
181+
expect(coreSetup.uiSettings.register).toHaveBeenCalledWith({
182+
[PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY]: {
183+
...classicSetting,
184+
value: AIAssistantType.Observability,
185+
},
186+
});
187+
});
188+
});
189+
});

0 commit comments

Comments
 (0)