Skip to content

Commit

Permalink
Merge branch '8.10' into backport/8.10/pr-164122
Browse files Browse the repository at this point in the history
  • Loading branch information
mitodrummer authored Aug 23, 2023
2 parents 134fce8 + 916b1eb commit fd63c4b
Show file tree
Hide file tree
Showing 67 changed files with 1,005 additions and 841 deletions.
Binary file modified docs/user/alerting/images/rule-types-es-query-conditions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/user/alerting/images/rule-types-es-query-invalid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/user/alerting/images/rule-types-es-query-valid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion docs/user/alerting/rule-types/es-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Fill in the name and optional tags, then select
Define properties to detect the condition.

[role="screenshot"]
image::user/alerting/images/rule-types-es-query-conditions.png[Eight clauses define the condition to detect]
image::user/alerting/images/rule-types-es-query-conditions.png[Define the condition to detect]
// NOTE: This is an autogenerated screenshot. Do not edit it directly.

Define your query::
If you chose the query DSL option, you must specify indices to query and a time field that is used for the time window. You must then define a query in {es} query DSL. Only the `query`, `fields`, `_source` and `runtime_mappings` fields are used, other DSL fields are not considered.
Expand Down Expand Up @@ -122,11 +123,13 @@ Use the *Test query* feature to verify that your query DSL is valid.
+
[role="screenshot"]
image::user/alerting/images/rule-types-es-query-valid.png[Test {es} query returns number of matches when valid]
// NOTE: This is an autogenerated screenshot. Do not edit it directly.

* An error message is shown if the query is invalid.
+
[role="screenshot"]
image::user/alerting/images/rule-types-es-query-invalid.png[Test {es} query shows error when invalid]
// NOTE: This is an autogenerated screenshot. Do not edit it directly.

[float]
=== Handling multiple matches of the same document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const AssistantHeader: React.FC<Props> = ({
<EuiFlexItem grow={false}>
<AssistantTitle
{...currentTitle}
isDisabled={isDisabled}
docLinks={docLinks}
selectedConversation={currentConversation}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import { ConnectorSelectorInline } from '../../connectorland/connector_selector_
* information about the assistant feature and access to documentation.
*/
export const AssistantTitle: React.FC<{
isDisabled?: boolean;
title: string | JSX.Element;
titleIcon: string;
docLinks: Omit<DocLinksStart, 'links'>;
selectedConversation: Conversation | undefined;
}> = ({ title, titleIcon, docLinks, selectedConversation }) => {
}> = ({ isDisabled = false, title, titleIcon, docLinks, selectedConversation }) => {
const selectedConnectorId = selectedConversation?.apiConfig?.connectorId;

const { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } = docLinks;
Expand Down Expand Up @@ -116,7 +117,7 @@ export const AssistantTitle: React.FC<{
</EuiFlexItem>
<EuiFlexItem grow={false}>
<ConnectorSelectorInline
isDisabled={selectedConversation === undefined}
isDisabled={isDisabled || selectedConversation === undefined}
onConnectorModalVisibilityChange={() => {}}
onConnectorSelectionChange={() => {}}
selectedConnectorId={selectedConnectorId}
Expand Down
14 changes: 3 additions & 11 deletions x-pack/packages/kbn-elastic-assistant/impl/assistant/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const AssistantComponent: React.FC<Props> = ({
setConversationId,
}) => {
const {
actionTypeRegistry,
assistantTelemetry,
augmentMessageCodeBlocks,
conversations,
Expand All @@ -98,11 +97,7 @@ const AssistantComponent: React.FC<Props> = ({
const { createConversation } = useConversation();

// Connector details
const {
data: connectors,
isSuccess: areConnectorsFetched,
refetch: refetchConnectors,
} = useLoadConnectors({ http });
const { data: connectors, isSuccess: areConnectorsFetched } = useLoadConnectors({ http });
const defaultConnectorId = useMemo(() => getDefaultConnector(connectors)?.id, [connectors]);
const defaultProvider = useMemo(
() =>
Expand Down Expand Up @@ -171,14 +166,10 @@ const AssistantComponent: React.FC<Props> = ({
}, [areConnectorsFetched, connectors?.length, currentConversation, setLastConversationId]);

const { comments: connectorComments, prompt: connectorPrompt } = useConnectorSetup({
actionTypeRegistry,
http,
refetchConnectors,
conversation: blockBotConversation,
onSetupComplete: () => {
bottomRef.current?.scrollIntoView({ behavior: 'auto' });
},
conversation: blockBotConversation,
isConnectorConfigured: !!connectors?.length,
});

const currentTitle: { title: string | JSX.Element; titleIcon: string } =
Expand Down Expand Up @@ -475,6 +466,7 @@ const AssistantComponent: React.FC<Props> = ({
<EuiFlexGroup justifyContent="spaceAround">
<EuiFlexItem grow={false}>
<ConnectorMissingCallout
isConnectorConfigured={connectors?.length > 0}
isSettingsModalVisible={isSettingsModalVisible}
setIsSettingsModalVisible={setIsSettingsModalVisible}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ import React from 'react';
import { AssistantProvider, useAssistantContext } from '.';
import { httpServiceMock } from '@kbn/core-http-browser-mocks';
import { actionTypeRegistryMock } from '@kbn/triggers-actions-ui-plugin/public/application/action_type_registry.mock';
import { AssistantAvailability } from '../..';

const actionTypeRegistry = actionTypeRegistryMock.create();
const mockGetInitialConversations = jest.fn(() => ({}));
const mockGetComments = jest.fn(() => []);
const mockHttp = httpServiceMock.createStartContract({ basePath: '/test' });
const mockAssistantAvailability: AssistantAvailability = {
hasAssistantPrivilege: false,
hasConnectorsAllPrivilege: true,
hasConnectorsReadPrivilege: true,
isAssistantEnabled: true,
};

const ContextWrapper: React.FC = ({ children }) => (
<AssistantProvider
actionTypeRegistry={actionTypeRegistry}
assistantAvailability={mockAssistantAvailability}
augmentMessageCodeBlocks={jest.fn()}
baseAllow={[]}
baseAllowReplacement={[]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
SYSTEM_PROMPT_LOCAL_STORAGE_KEY,
} from './constants';
import { CONVERSATIONS_TAB, SettingsTabs } from '../assistant/settings/assistant_settings';
import { AssistantTelemetry } from './types';
import { AssistantAvailability, AssistantTelemetry } from './types';

export interface ShowAssistantOverlayProps {
showOverlay: boolean;
Expand All @@ -48,6 +48,7 @@ type ShowAssistantOverlay = ({
}: ShowAssistantOverlayProps) => void;
export interface AssistantProviderProps {
actionTypeRegistry: ActionTypeRegistryContract;
assistantAvailability: AssistantAvailability;
assistantTelemetry?: AssistantTelemetry;
augmentMessageCodeBlocks: (currentConversation: Conversation) => CodeBlockDetails[][];
baseAllow: string[];
Expand Down Expand Up @@ -79,6 +80,7 @@ export interface AssistantProviderProps {

export interface UseAssistantContext {
actionTypeRegistry: ActionTypeRegistryContract;
assistantAvailability: AssistantAvailability;
assistantTelemetry?: AssistantTelemetry;
augmentMessageCodeBlocks: (currentConversation: Conversation) => CodeBlockDetails[][];
allQuickPrompts: QuickPrompt[];
Expand Down Expand Up @@ -126,6 +128,7 @@ const AssistantContext = React.createContext<UseAssistantContext | undefined>(un

export const AssistantProvider: React.FC<AssistantProviderProps> = ({
actionTypeRegistry,
assistantAvailability,
assistantTelemetry,
augmentMessageCodeBlocks,
baseAllow,
Expand Down Expand Up @@ -244,6 +247,7 @@ export const AssistantProvider: React.FC<AssistantProviderProps> = ({
const value = useMemo(
() => ({
actionTypeRegistry,
assistantAvailability,
assistantTelemetry,
augmentMessageCodeBlocks,
allQuickPrompts: localStorageQuickPrompts ?? [],
Expand Down Expand Up @@ -279,6 +283,7 @@ export const AssistantProvider: React.FC<AssistantProviderProps> = ({
}),
[
actionTypeRegistry,
assistantAvailability,
assistantTelemetry,
augmentMessageCodeBlocks,
baseAllow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ export interface AssistantTelemetry {
reportAssistantMessageSent: (params: { conversationId: string; role: string }) => void;
reportAssistantQuickPrompt: (params: { conversationId: string; promptTitle: string }) => void;
}

export interface AssistantAvailability {
// True when user is Enterprise, or Security Complete PLI for serverless. When false, the Assistant is disabled and unavailable
isAssistantEnabled: boolean;
// When true, the Assistant is hidden and unavailable
hasAssistantPrivilege: boolean;
// When true, user has `All` privilege for `Connectors and Actions` (show/execute/delete/save ui capabilities)
hasConnectorsAllPrivilege: boolean;
// When true, user has `Read` privilege for `Connectors and Actions` (show/execute ui capabilities)
hasConnectorsReadPrivilege: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,46 @@
* 2.0.
*/

import React from 'react';
import React, { useCallback } from 'react';
import { EuiCard, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui';

import { GenAiLogo } from '@kbn/stack-connectors-plugin/public/common';
import * as i18n from '../translations';
import { useAssistantContext } from '../../assistant_context';

export interface ConnectorButtonProps {
setIsConnectorModalVisible: React.Dispatch<React.SetStateAction<boolean>>;
setIsConnectorModalVisible?: React.Dispatch<React.SetStateAction<boolean>>;
}

/**
* Simple button component for adding a connector. Note: component is basic and does not handle connector
* add logic. Must pass in `setIsConnectorModalVisible`, see ConnectorSetup component if wanting to manage
* connector add logic.
* add logic. See ConnectorSetup component if wanting to manage connector add logic.
*/
export const ConnectorButton: React.FC<ConnectorButtonProps> = React.memo<ConnectorButtonProps>(
({ setIsConnectorModalVisible }) => {
const { assistantAvailability } = useAssistantContext();

const title = assistantAvailability.hasConnectorsAllPrivilege
? i18n.ADD_CONNECTOR_TITLE
: i18n.ADD_CONNECTOR_MISSING_PRIVILEGES_TITLE;
const description = assistantAvailability.hasConnectorsAllPrivilege
? i18n.ADD_CONNECTOR_DESCRIPTION
: i18n.ADD_CONNECTOR_MISSING_PRIVILEGES_DESCRIPTION;

const onClick = useCallback(() => {
setIsConnectorModalVisible?.(true);
}, [setIsConnectorModalVisible]);

return (
<EuiFlexGroup gutterSize="l" justifyContent="spaceAround">
<EuiFlexItem grow={false}>
<EuiCard
data-test-subj="connectorButton"
layout="horizontal"
icon={<EuiIcon size="xl" type={GenAiLogo} />}
title={i18n.ADD_CONNECTOR_TITLE}
description={i18n.ADD_CONNECTOR_DESCRIPTION}
onClick={() => setIsConnectorModalVisible(true)}
title={title}
description={description}
onClick={assistantAvailability.hasConnectorsAllPrivilege ? onClick : undefined}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { render } from '@testing-library/react';
import { ConnectorMissingCallout } from '.';
import { AssistantAvailability } from '../../..';
import { TestProviders } from '../../mock/test_providers/test_providers';

describe('connectorMissingCallout', () => {
describe('when connectors and actions privileges', () => {
describe('are `READ`', () => {
const assistantAvailability: AssistantAvailability = {
hasAssistantPrivilege: true,
hasConnectorsAllPrivilege: false,
hasConnectorsReadPrivilege: true,
isAssistantEnabled: true,
};

it('should show connector privileges required button if no connectors exist', async () => {
const { queryByTestId } = render(
<TestProviders assistantAvailability={assistantAvailability}>
<ConnectorMissingCallout
isConnectorConfigured={false}
isSettingsModalVisible={false}
setIsSettingsModalVisible={jest.fn()}
/>
</TestProviders>
);

expect(queryByTestId('connectorButton')).toBeInTheDocument();
});

it('should NOT show connector privileges required button if at least one connector exists', async () => {
const { queryByTestId } = render(
<TestProviders assistantAvailability={assistantAvailability}>
<ConnectorMissingCallout
isConnectorConfigured={true}
isSettingsModalVisible={false}
setIsSettingsModalVisible={jest.fn()}
/>
</TestProviders>
);

expect(queryByTestId('connectorButton')).not.toBeInTheDocument();
});
});

describe('are `NONE`', () => {
const assistantAvailability: AssistantAvailability = {
hasAssistantPrivilege: true,
hasConnectorsAllPrivilege: false,
hasConnectorsReadPrivilege: false,
isAssistantEnabled: true,
};

it('should show connector privileges required button', async () => {
const { queryByTestId } = render(
<TestProviders assistantAvailability={assistantAvailability}>
<ConnectorMissingCallout
isConnectorConfigured={true}
isSettingsModalVisible={false}
setIsSettingsModalVisible={jest.fn()}
/>
</TestProviders>
);

expect(queryByTestId('connectorButton')).toBeInTheDocument();
});
});
});
});
Loading

0 comments on commit fd63c4b

Please sign in to comment.