Skip to content

Commit

Permalink
Fix alert count not saving, fix entries being queries on stack mgmt p…
Browse files Browse the repository at this point in the history
…age if FF disabled, fixed modelId override only if FF is enabled, and renamed assistant_all user
  • Loading branch information
spong committed Sep 24, 2024
1 parent 29decc2 commit ac494d7
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"username": "elastic",
"password": "changeme"
},
"assistant_system": {
"username": "assistant_system",
"assistant_all": {
"username": "assistant_all",
"password": "changeme"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ X-Kbn-Context: {{appContext.security}}
"text": "My favorite food is Dan Bing"
}

### Create Index Entry (Admin Global)
POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries
kbn-xsrf: "true"
Content-Type: application/json
Elastic-Api-Version: {{elasticApiVersion}}
Authorization: Basic {{auth.admin.username}} {{auth.admin.password}}
X-Kbn-Context: {{appContext.security}}

{
"type": "index",
"name": "SlackConnector (Admin Global)",
"namespace": "default",
"index": "slackbot-test",
"field": "semantic_text",
"description": "Use this index to search for the user's Slack messages.",
"queryDescription":
"The free text search that the user wants to perform over this dataset. So if asking \"what are my slack messages from last week about failed tests\", the query would be \"A test has failed! failing test failed test\"",
"outputFields": ["author", "text", "timestamp"],
"users": []
}

### Create Index Entry (Admin)
POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries
kbn-xsrf: "true"
Expand All @@ -35,24 +56,27 @@ X-Kbn-Context: {{appContext.security}}
"outputFields": ["author", "text", "timestamp"]
}

### Create Index Entry (Assistant System)
### Create Index Entry (Assistant All)
POST http://{{host}}:{{port}}{{basePath}}/internal/elastic_assistant/knowledge_base/entries
kbn-xsrf: "true"
Content-Type: application/json
Elastic-Api-Version: {{elasticApiVersion}}
Authorization: Basic {{auth.assistant_system.username}} {{auth.assistant_system.password}}
Authorization: Basic {{auth.assistant_all.username}} {{auth.assistant_all.password}}
X-Kbn-Context: {{appContext.security}}

{
"type": "index",
"name": "SlackConnector (Assistant System)",
"name": "SlackConnector (Assistant All)",
"namespace": "default",
"index": "slackbot-test",
"field": "semantic_text",
"description": "Use this index to search for the user's Slack messages.",
"queryDescription":
"The free text search that the user wants to perform over this dataset. So if asking \"what are my slack messages from last week about failed tests\", the query would be \"A test has failed! failing test failed test\"",
"outputFields": ["author", "text", "timestamp"]
"queryDescription": "The free text search that the user wants to perform over this dataset. So if asking \"what are my slack messages from last week about failed tests\", the query would be \"A test has failed! failing test failed test\"",
"outputFields": [
"author",
"text",
"timestamp"
]
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Authorization: Basic {{auth.admin.username}} {{auth.admin.password}}
"imageUrl": ""
}

### Create assistant_admin Role - All Spaces, All Features
PUT http://{{host}}:{{port}}{{basePath}}/api/security/role/assistant_admin
### Create Assistant All Role - All Spaces, All Features
PUT http://{{host}}:{{port}}{{basePath}}/api/security/role/assistant_all
kbn-xsrf: "true"
Content-Type: application/json
Elastic-Api-Version: {{elasticApiVersion}}
Expand Down Expand Up @@ -100,20 +100,20 @@ Authorization: Basic {{auth.admin.username}} {{auth.admin.password}}
]
}

### Create assistant_system User - All Spaces, All Features
POST http://{{host}}:{{port}}{{basePath}}/internal/security/users/assistant_system
### Create Assistant All User - All Spaces, All Features
POST http://{{host}}:{{port}}{{basePath}}/internal/security/users/assistant_all
kbn-xsrf: "true"
Content-Type: application/json
Elastic-Api-Version: {{elasticApiVersion}}
Authorization: Basic {{auth.admin.username}} {{auth.admin.password}}

{
"password": "{{auth.assistant_system.password}}",
"username": "{{auth.assistant_system.username}}",
"full_name": "Assistant System",
"password": "{{auth.assistant_all.password}}",
"username": "{{auth.assistant_all.username}}",
"full_name": "Assistant All",
"email": "",
"roles": [
"assistant_admin"
"assistant_all"
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface UseKnowledgeBaseEntriesParams {
query?: FindKnowledgeBaseEntriesRequestQuery;
signal?: AbortSignal | undefined;
toasts?: IToasts;
enabled?: boolean; // For disabling if FF is off
}

const defaultQuery: FindKnowledgeBaseEntriesRequestQuery = {
Expand Down Expand Up @@ -54,6 +55,7 @@ export const useKnowledgeBaseEntries = ({
query = defaultQuery,
signal,
toasts,
enabled = false,
}: UseKnowledgeBaseEntriesParams) =>
useQuery(
KNOWLEDGE_BASE_ENTRY_QUERY_KEY,
Expand All @@ -68,6 +70,7 @@ export const useKnowledgeBaseEntries = ({
}
),
{
enabled,
keepPreviousData: true,
initialData: { page: 1, perPage: 100, total: 0, data: [] },
onError: (error: IHttpFetchError<ResponseErrorBody>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { AlertsSettingsManagement } from '../../alerts/settings/alerts_settings_
import { useKnowledgeBaseEntries } from '../../assistant/api/knowledge_base/entries/use_knowledge_base_entries';
import { useAssistantContext } from '../../assistant_context';
import { useKnowledgeBaseTable } from './use_knowledge_base_table';
import { AssistantSettingsBottomBar } from '../../assistant/settings/assistant_settings_bottom_bar';
import {
useSettingsUpdater,
DEFAULT_CONVERSATIONS,
Expand All @@ -48,22 +49,55 @@ import {
} from './helpers';
import { useCreateKnowledgeBaseEntry } from '../../assistant/api/knowledge_base/entries/use_create_knowledge_base_entry';
import { useUpdateKnowledgeBaseEntries } from '../../assistant/api/knowledge_base/entries/use_update_knowledge_base_entries';
import { SETTINGS_UPDATED_TOAST_TITLE } from '../../assistant/settings/translations';

export const KnowledgeBaseSettingsManagement: React.FC = React.memo(() => {
const {
assistantFeatures: { assistantKnowledgeBaseByDefault: enableKnowledgeBaseByDefault },
http,
toasts,
} = useAssistantContext();
const [hasPendingChanges, setHasPendingChanges] = useState(false);

// Only needed for legacy settings management
const { knowledgeBase, setUpdatedKnowledgeBaseSettings } = useSettingsUpdater(
DEFAULT_CONVERSATIONS, // Knowledge Base settings do not require conversations
DEFAULT_PROMPTS, // Knowledge Base settings do not require prompts
false, // Knowledge Base settings do not require conversations
false // Knowledge Base settings do not require prompts
const { knowledgeBase, setUpdatedKnowledgeBaseSettings, resetSettings, saveSettings } =
useSettingsUpdater(
DEFAULT_CONVERSATIONS, // Knowledge Base settings do not require conversations
DEFAULT_PROMPTS, // Knowledge Base settings do not require prompts
false, // Knowledge Base settings do not require conversations
false // Knowledge Base settings do not require prompts
);

const handleUpdateKnowledgeBaseSettings = useCallback(
(updatedKnowledgeBase) => {
setHasPendingChanges(true);
setUpdatedKnowledgeBaseSettings(updatedKnowledgeBase);
},
[setUpdatedKnowledgeBaseSettings]
);

const handleSave = useCallback(
async (param?: { callback?: () => void }) => {
await saveSettings();
toasts?.addSuccess({
iconType: 'check',
title: SETTINGS_UPDATED_TOAST_TITLE,
});
setHasPendingChanges(false);
param?.callback?.();
},
[saveSettings, toasts]
);

const onCancelClick = useCallback(() => {
resetSettings();
setHasPendingChanges(false);
}, [resetSettings]);

const onSaveButtonClicked = useCallback(() => {
handleSave();
}, [handleSave]);

const { isFlyoutOpen: isFlyoutVisible, openFlyout, closeFlyout } = useFlyoutModalVisibility();

const [selectedEntry, setSelectedEntry] =
Expand Down Expand Up @@ -100,7 +134,11 @@ export const KnowledgeBaseSettingsManagement: React.FC = React.memo(() => {
closeFlyout();
}, [closeFlyout]);

const { data: entries } = useKnowledgeBaseEntries({ http, toasts });
const { data: entries } = useKnowledgeBaseEntries({
http,
toasts,
enabled: enableKnowledgeBaseByDefault,
});
const { getColumns } = useKnowledgeBaseTable();
const columns = useMemo(
() =>
Expand Down Expand Up @@ -169,10 +207,17 @@ export const KnowledgeBaseSettingsManagement: React.FC = React.memo(() => {

if (!enableKnowledgeBaseByDefault) {
return (
<KnowledgeBaseSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
/>
<>
<KnowledgeBaseSettings
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={handleUpdateKnowledgeBaseSettings}
/>
<AssistantSettingsBottomBar
hasPendingChanges={hasPendingChanges}
onCancelClick={onCancelClick}
onSaveButtonClicked={onSaveButtonClicked}
/>
</>
);
}

Expand Down Expand Up @@ -208,7 +253,12 @@ export const KnowledgeBaseSettingsManagement: React.FC = React.memo(() => {
<EuiSpacer size="m" />
<AlertsSettingsManagement
knowledgeBase={knowledgeBase}
setUpdatedKnowledgeBaseSettings={setUpdatedKnowledgeBaseSettings}
setUpdatedKnowledgeBaseSettings={handleUpdateKnowledgeBaseSettings}
/>
<AssistantSettingsBottomBar
hasPendingChanges={hasPendingChanges}
onCancelClick={onCancelClick}
onSaveButtonClicked={onSaveButtonClicked}
/>
<Flyout
flyoutVisible={isFlyoutVisible}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ export const postKnowledgeBaseRoute = (router: ElasticAssistantPluginRouter) =>
const core = ctx.core;
const soClient = core.savedObjects.getClient();
const kbResource = request.params.resource;
const modelIdOverride = request.query.modelId;

// FF Check for V2 KB
const v2KnowledgeBaseEnabled = isV2KnowledgeBaseEnabled({ context: ctx, request });
// Only allow modelId override if FF is enabled as this will re-write the ingest pipeline and break any previous KB entries
// This is only really needed for API integration tests
const modelIdOverride = v2KnowledgeBaseEnabled ? request.query.modelId : undefined;

try {
const knowledgeBaseDataClient =
Expand Down

0 comments on commit ac494d7

Please sign in to comment.