Skip to content

Commit 251b717

Browse files
Merge branch 'main' into alerty-summary-table
2 parents c4cb1b7 + cb0202e commit 251b717

6 files changed

Lines changed: 136 additions & 15 deletions

File tree

x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.test.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { Logger } from '@kbn/logging';
2525
import { eventLogClientMock } from '@kbn/event-log-plugin/server/event_log_client.mock';
2626
import type { ActionTypeRegistry } from '../../../../action_type_registry';
2727
import { getAllUnsecured } from './get_all';
28+
import type { InferenceInferenceEndpointInfo } from '@elastic/elasticsearch/lib/api/types';
2829

2930
jest.mock('@kbn/core-saved-objects-utils-server', () => {
3031
const actual = jest.requireActual('@kbn/core-saved-objects-utils-server');
@@ -585,6 +586,84 @@ describe('getAll()', () => {
585586

586587
expect(logger.warn).not.toHaveBeenCalled();
587588
});
589+
590+
test('filters out inference connectors without endpoints', async () => {
591+
unsecuredSavedObjectsClient.find.mockResolvedValueOnce({
592+
total: 1,
593+
per_page: 10,
594+
page: 1,
595+
saved_objects: [],
596+
});
597+
598+
scopedClusterClient.asInternalUser.search.mockResponse(
599+
// @ts-expect-error not full search response
600+
{
601+
aggregations: {
602+
testPreconfigured01: { doc_count: 2 },
603+
testPreconfigured02: { doc_count: 2 },
604+
},
605+
}
606+
);
607+
608+
scopedClusterClient.asInternalUser.inference.get.mockResolvedValueOnce({
609+
endpoints: [{ inference_id: '2' } as InferenceInferenceEndpointInfo],
610+
});
611+
612+
actionsClient = new ActionsClient({
613+
logger,
614+
actionTypeRegistry,
615+
unsecuredSavedObjectsClient,
616+
scopedClusterClient,
617+
kibanaIndices,
618+
actionExecutor,
619+
bulkExecutionEnqueuer,
620+
request,
621+
authorization: authorization as unknown as ActionsAuthorization,
622+
inMemoryConnectors: [
623+
{
624+
id: 'testPreconfigured01',
625+
actionTypeId: '.inference',
626+
name: 'test1',
627+
config: {
628+
inferenceId: '1',
629+
},
630+
secrets: {},
631+
isDeprecated: false,
632+
isMissingSecrets: false,
633+
isPreconfigured: false,
634+
isSystemAction: true,
635+
},
636+
{
637+
id: 'testPreconfigured02',
638+
actionTypeId: '.inference',
639+
name: 'test2',
640+
config: {
641+
inferenceId: '2',
642+
},
643+
secrets: {},
644+
isDeprecated: false,
645+
isMissingSecrets: false,
646+
isPreconfigured: false,
647+
isSystemAction: true,
648+
},
649+
],
650+
connectorTokenClient: connectorTokenClientMock.create(),
651+
getEventLogClient,
652+
});
653+
654+
const result = await actionsClient.getAll({ includeSystemActions: true });
655+
expect(result).toEqual([
656+
{
657+
actionTypeId: '.inference',
658+
id: 'testPreconfigured02',
659+
isDeprecated: false,
660+
isPreconfigured: false,
661+
isSystemAction: true,
662+
name: 'test2',
663+
referencedByCount: 2,
664+
},
665+
]);
666+
});
588667
});
589668

590669
describe('getAllSystemConnectors()', () => {

x-pack/platform/plugins/shared/actions/server/application/connector/methods/get_all/get_all.ts

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,17 @@ async function getAllHelper({
113113

114114
const mergedResult = [
115115
...savedObjectsActions,
116-
...inMemoryConnectors.map((inMemoryConnector) => ({
117-
id: inMemoryConnector.id,
118-
actionTypeId: inMemoryConnector.actionTypeId,
119-
name: inMemoryConnector.name,
120-
isPreconfigured: inMemoryConnector.isPreconfigured,
121-
isDeprecated: isConnectorDeprecated(inMemoryConnector),
122-
isSystemAction: inMemoryConnector.isSystemAction,
123-
...(inMemoryConnector.exposeConfig ? { config: inMemoryConnector.config } : {}),
124-
})),
116+
...(await filterInferenceConnectors(esClient, inMemoryConnectors)).map((connector) => {
117+
return {
118+
id: connector.id,
119+
actionTypeId: connector.actionTypeId,
120+
name: connector.name,
121+
isPreconfigured: connector.isPreconfigured,
122+
isDeprecated: isConnectorDeprecated(connector),
123+
isSystemAction: connector.isSystemAction,
124+
...(connector.exposeConfig ? { config: connector.config } : {}),
125+
};
126+
}),
125127
].sort((a, b) => a.name.localeCompare(b.name));
126128

127129
const connectors = await injectExtraFindData({
@@ -238,3 +240,37 @@ async function injectExtraFindData({
238240
referencedByCount: aggregationResult.aggregations[connector.id].doc_count,
239241
}));
240242
}
243+
244+
/**
245+
* Filters out inference connectors that do not have an endpoint.
246+
* It requires a connector config in order to retrieve the inference id.
247+
*
248+
* @param esClient
249+
* @param connectors
250+
* @returns
251+
*/
252+
export async function filterInferenceConnectors(
253+
esClient: ElasticsearchClient,
254+
connectors: InMemoryConnector[]
255+
): Promise<InMemoryConnector[]> {
256+
let result = connectors;
257+
258+
if (result.some((connector) => connector.actionTypeId === '.inference')) {
259+
try {
260+
// Get all inference endpoints to filter out inference connector without endpoints
261+
const inferenceEndpoints = await esClient.inference.get();
262+
result = result.filter((connector) => {
263+
if (connector.actionTypeId !== '.inference') return true;
264+
265+
const inferenceEndpoint = inferenceEndpoints.endpoints.find(
266+
(endpoint) => endpoint.inference_id === connector.config?.inferenceId
267+
);
268+
return inferenceEndpoint !== undefined;
269+
});
270+
} catch (e) {
271+
// If we can't get the inference endpoints, we just return all connectors
272+
}
273+
}
274+
275+
return result;
276+
}

x-pack/platform/plugins/shared/stack_connectors/public/connector_types/inference/inference.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('actionTypeRegistry.get() works', () => {
3131
test('connector type static data is as expected', () => {
3232
expect(actionTypeModel.id).toEqual(ACTION_TYPE_ID);
3333
expect(actionTypeModel.selectMessage).toBe(
34-
'Use the Elastic Managed LLM for your chat and RAG usecases.'
34+
'Use the Elastic Managed LLM for your chat and RAG use cases.'
3535
);
3636
expect(actionTypeModel.actionTypeTitle).toBe('AI Connector');
3737
});

x-pack/platform/plugins/shared/stack_connectors/public/connector_types/inference/inference.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function getConnectorType(): InferenceConnector {
3131
iconClass: 'sparkles',
3232
isExperimental: true,
3333
selectMessage: i18n.translate('xpack.stackConnectors.components.inference.selectMessageText', {
34-
defaultMessage: 'Use the Elastic Managed LLM for your chat and RAG usecases.',
34+
defaultMessage: 'Use the Elastic Managed LLM for your chat and RAG use cases.',
3535
}),
3636
actionTypeTitle: INFERENCE_CONNECTOR_TITLE,
3737
validateParams: async (

x-pack/platform/plugins/shared/triggers_actions_ui/public/common/get_add_connector_flyout.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
*/
77

88
import React from 'react';
9+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
910
import { ConnectorProvider } from '../application/context/connector_context';
1011
import { CreateConnectorFlyout } from '../application/sections/action_connector_form';
1112
import { CreateConnectorFlyoutProps } from '../application/sections/action_connector_form/create_connector_flyout';
1213
import { ConnectorServices } from '../types';
1314

15+
const queryClient = new QueryClient();
16+
1417
export const getAddConnectorFlyoutLazy = (
1518
props: CreateConnectorFlyoutProps & { connectorServices: ConnectorServices }
1619
) => {
1720
return (
18-
<ConnectorProvider value={{ services: props.connectorServices }}>
19-
<CreateConnectorFlyout {...props} />
20-
</ConnectorProvider>
21+
<QueryClientProvider client={queryClient}>
22+
<ConnectorProvider value={{ services: props.connectorServices }}>
23+
<CreateConnectorFlyout {...props} />
24+
</ConnectorProvider>
25+
</QueryClientProvider>
2126
);
2227
};

x-pack/test/observability_functional/apps/observability/pages/alerts/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
7676
},
7777
};
7878

79-
describe('Observability alerts >', function () {
79+
// Failing: See https://github.com/elastic/kibana/issues/217739
80+
describe.skip('Observability alerts >', function () {
8081
this.tags('includeFirefox');
8182
const testSubjects = getService('testSubjects');
8283
const retry = getService('retry');

0 commit comments

Comments
 (0)