Skip to content

Commit

Permalink
Merge branch '8.x' into backport/8.x/pr-202606
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan authored Dec 5, 2024
2 parents f32a771 + 0d4df88 commit 5749f8a
Show file tree
Hide file tree
Showing 163 changed files with 3,187 additions and 1,439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import { useInitializeFromLocalStorage } from './use_initialize_from_local_storage';
import { localStorageMock } from '../../__mocks__';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
*/

import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import type { RenderHookResult } from '@testing-library/react-hooks';
import { renderHook, RenderHookResult } from '@testing-library/react';
import type { UseSectionsParams, UseSectionsResult } from './use_sections';
import { useSections } from './use_sections';
import { useExpandableFlyoutState } from '../..';

jest.mock('../..');

describe('useSections', () => {
let hookResult: RenderHookResult<UseSectionsParams, UseSectionsResult>;
let hookResult: RenderHookResult<UseSectionsResult, UseSectionsParams>;

it('should return undefined for all values if no registeredPanels', () => {
(useExpandableFlyoutState as jest.Mock).mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { renderHook } from '@testing-library/react-hooks';
import { renderHook } from '@testing-library/react';
import {
FULL_WIDTH_PADDING,
MAX_RESOLUTION_BREAKPOINT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface ConnectorConfigurationProps {
isLoading: boolean;
saveConfig: (configuration: Record<string, string | number | boolean | null>) => void;
saveAndSync?: (configuration: Record<string, string | number | boolean | null>) => void;
onEditStateChange?: (isEdit: boolean) => void;
stackManagementLink?: string;
subscriptionLink?: string;
children?: React.ReactNode;
Expand Down Expand Up @@ -94,6 +95,7 @@ export const ConnectorConfigurationComponent: FC<
isLoading,
saveConfig,
saveAndSync,
onEditStateChange,
subscriptionLink,
stackManagementLink,
}) => {
Expand All @@ -110,6 +112,15 @@ export const ConnectorConfigurationComponent: FC<
);
const [isEditing, setIsEditing] = useState(false);

useEffect(
function propogateEditState() {
if (onEditStateChange) {
onEditStateChange(isEditing);
}
},
[isEditing, onEditStateChange]
);

useEffect(() => {
if (!isDeepEqual(configuration, configurationRef.current)) {
configurationRef.current = configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';

import { useActions, useValues } from 'kea';

Expand All @@ -21,6 +21,7 @@ import {
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { useKibana } from '@kbn/kibana-react-plugin/public';

import { ConnectorConfigurationComponent, ConnectorStatus } from '@kbn/search-connectors';

Expand All @@ -40,6 +41,8 @@ export const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ title, set
const { connector } = useValues(ConnectorViewLogic);
const { updateConnectorConfiguration } = useActions(ConnectorViewLogic);
const { setFormDirty } = useActions(NewConnectorLogic);
const { overlays } = useKibana().services;
const [isFormEditing, setIsFormEditing] = useState<boolean>(false);
const { status } = useValues(ConnectorConfigurationApiLogic);
const isSyncing = false;

Expand Down Expand Up @@ -77,6 +80,7 @@ export const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ title, set
connectorId: connector.id,
});
}}
onEditStateChange={setIsFormEditing}
/>
<EuiSpacer size="m" />
{isSyncing && (
Expand Down Expand Up @@ -111,7 +115,38 @@ export const ConfigurationStep: React.FC<ConfigurationStepProps> = ({ title, set
<EuiSpacer size="m" />
<EuiButton
data-test-subj="enterpriseSearchStartStepGenerateConfigurationButton"
onClick={() => {
onClick={async () => {
if (isFormEditing) {
const confirmResponse = await overlays?.openConfirm(
i18n.translate('xpack.enterpriseSearch.configureConnector.unsavedPrompt.body', {
defaultMessage:
'You are still editing connector configuration, are you sure you want to continue without saving? You can complete the setup later in the connector configuration page, but this guided flow offers more help.',
}),
{
title: i18n.translate(
'xpack.enterpriseSearch.configureConnector.unsavedPrompt.title',
{
defaultMessage: 'Connector configuration is not saved',
}
),
cancelButtonText: i18n.translate(
'xpack.enterpriseSearch.configureConnector.unsavedPrompt.cancel',
{
defaultMessage: 'Continue setup',
}
),
confirmButtonText: i18n.translate(
'xpack.enterpriseSearch.configureConnector.unsavedPrompt.confirm',
{
defaultMessage: 'Leave the page',
}
),
}
);
if (!confirmResponse) {
return;
}
}
setFormDirty(false);
setCurrentStep('finish');
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import React from 'react';

import { useActions, useValues } from 'kea';

import { EuiComboBox, EuiFormRow, EuiHorizontalRule, EuiRadioGroup } from '@elastic/eui';
import {
EuiComboBox,
EuiFormRow,
EuiHorizontalRule,
EuiRadioGroup,
useGeneratedHtmlId,
} from '@elastic/eui';

import { RoleOptionLabel } from '../../../shared/role_mapping';

Expand All @@ -31,6 +37,8 @@ export const GroupAssignmentSelector: React.FC = () => {
const { includeInAllGroups, availableGroups, selectedGroups, selectedOptions } =
useValues(RoleMappingsLogic);

const groupAssigmentLabelId = useGeneratedHtmlId();

const hasGroupAssignment = selectedGroups.size > 0 || includeInAllGroups;

const groupOptions = [
Expand All @@ -51,11 +59,12 @@ export const GroupAssignmentSelector: React.FC = () => {
<EuiHorizontalRule />
<EuiFormRow>
<EuiRadioGroup
data-test-subj="enterpriseSearchGroupAssignmentSelectorRadioGroup"
options={groupOptions}
idSelected={includeInAllGroups ? 'all' : 'specific'}
onChange={(id) => handleAllGroupsSelectionChange(id === 'all')}
legend={{
children: <span>{GROUP_ASSIGNMENT_LABEL}</span>,
children: <span id={groupAssigmentLabelId}>{GROUP_ASSIGNMENT_LABEL}</span>,
}}
/>
</EuiFormRow>
Expand All @@ -69,6 +78,7 @@ export const GroupAssignmentSelector: React.FC = () => {
}}
fullWidth
isDisabled={includeInAllGroups}
aria-labelledby={groupAssigmentLabelId}
/>
</EuiFormRow>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type ValidFeatureId,
} from '@kbn/rule-data-utils';

export const apmAlertingConsumers: ValidFeatureId[] = [
export const APM_ALERTING_CONSUMERS: ValidFeatureId[] = [
AlertConsumers.LOGS,
AlertConsumers.APM,
AlertConsumers.SLO,
Expand All @@ -20,4 +20,4 @@ export const apmAlertingConsumers: ValidFeatureId[] = [
AlertConsumers.ALERTS,
];

export const apmAlertingRuleTypeIds: string[] = [...OBSERVABILITY_RULE_TYPE_IDS];
export const APM_ALERTING_RULE_TYPE_IDS: string[] = [...OBSERVABILITY_RULE_TYPE_IDS];
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
import React from 'react';
import { i18n } from '@kbn/i18n';
import { Query } from '@kbn/es-query';
import { EuiFormErrorText } from '@elastic/eui';
import { Query, fromKueryExpression } from '@kbn/es-query';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ApmPluginStartDeps } from '../../../plugin';
import { useAdHocApmDataView } from '../../../hooks/use_adhoc_apm_data_view';
Expand All @@ -26,7 +27,7 @@ export function ApmRuleUnifiedSearchBar({
setRuleParams: (key: string, value: any) => void;
}) {
const { services } = useKibana<ApmPluginStartDeps>();

const [queryError, setQueryError] = React.useState<string>();
const {
unifiedSearch: {
ui: { SearchBar },
Expand All @@ -38,27 +39,38 @@ export function ApmRuleUnifiedSearchBar({

const handleSubmit = (payload: { query?: Query }) => {
const { query } = payload;
setRuleParams('searchConfiguration', { query });
try {
setQueryError(undefined);
fromKueryExpression(query?.query as string);
setRuleParams('searchConfiguration', { query });
} catch (e) {
setQueryError(e.message);
}
};

return (
<SearchBar
appName={i18n.translate('xpack.apm.appName', {
defaultMessage: 'APM',
})}
iconType="search"
placeholder={placeholder || searchbarPlaceholder}
indexPatterns={dataView ? [dataView] : undefined}
showQueryInput={true}
showQueryMenu={false}
showFilterBar={false}
showDatePicker={false}
showSubmitButton={false}
displayStyle="inPage"
onQueryChange={handleSubmit}
onQuerySubmit={handleSubmit}
dataTestSubj="apmRuleUnifiedSearchBar"
query={ruleParams.searchConfiguration?.query}
/>
<>
<SearchBar
appName={i18n.translate('xpack.apm.appName', {
defaultMessage: 'APM',
})}
iconType="search"
placeholder={placeholder || searchbarPlaceholder}
indexPatterns={dataView ? [dataView] : undefined}
showQueryInput={true}
showQueryMenu={false}
showFilterBar={false}
showDatePicker={false}
showSubmitButton={false}
displayStyle="inPage"
onQueryChange={handleSubmit}
onQuerySubmit={handleSubmit}
dataTestSubj="apmRuleUnifiedSearchBar"
query={ruleParams.searchConfiguration?.query}
/>
{queryError && (
<EuiFormErrorText data-test-subj="apmSearchBarErrorCallout">{queryError}</EuiFormErrorText>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { BoolQuery } from '@kbn/es-query';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import {
apmAlertingConsumers,
apmAlertingRuleTypeIds,
APM_ALERTING_CONSUMERS,
APM_ALERTING_RULE_TYPE_IDS,
} from '../../../../common/alerting/config/apm_alerting_feature_ids';
import { ApmPluginStartDeps } from '../../../plugin';
import { useAnyOfApmParams } from '../../../hooks/use_apm_params';
Expand Down Expand Up @@ -111,8 +111,8 @@ export function AlertsOverview() {
alertsTableConfigurationRegistry={alertsTableConfigurationRegistry}
id={'service-overview-alerts'}
configurationId={AlertConsumers.OBSERVABILITY}
ruleTypeIds={apmAlertingRuleTypeIds}
consumers={apmAlertingConsumers}
ruleTypeIds={APM_ALERTING_RULE_TYPE_IDS}
consumers={APM_ALERTING_CONSUMERS}
query={esQuery}
showAlertStatusWithFlapping
cellContext={{ observabilityRuleTypeRegistry }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DataTier } from '@kbn/observability-shared-plugin/common';
import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys';
import { estypes } from '@elastic/elasticsearch';
import { getDataTierFilterCombined } from '@kbn/apm-data-access-plugin/server/utils';
import { apmAlertingRuleTypeIds } from '../../../common/alerting/config/apm_alerting_feature_ids';
import { APM_ALERTING_RULE_TYPE_IDS } from '../../../common/alerting/config/apm_alerting_feature_ids';
import type { MinimalAPMRouteHandlerResources } from '../../routes/apm_routes/register_apm_server_routes';

export type ApmAlertsClient = Awaited<ReturnType<typeof getApmAlertsClient>>;
Expand All @@ -32,7 +32,9 @@ export async function getApmAlertsClient({

const ruleRegistryPluginStart = await plugins.ruleRegistry.start();
const alertsClient = await ruleRegistryPluginStart.getRacClientWithRequest(request);
const apmAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(apmAlertingRuleTypeIds);
const apmAlertsIndices = await alertsClient.getAuthorizedAlertsIndices(
APM_ALERTING_RULE_TYPE_IDS
);

if (!apmAlertsIndices || isEmpty(apmAlertsIndices)) {
throw Error('No alert indices exist for "apm"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ALERT_STATUS_ACTIVE,
ALERT_UUID,
} from '@kbn/rule-data-utils';
import { observabilityFeatureId } from '@kbn/observability-shared-plugin/common';
import { APM_ALERTING_CONSUMERS } from '../../../../common/alerting/config/apm_alerting_feature_ids';
import { SERVICE_NAME } from '../../../../common/es_fields/apm';
import { ServiceGroup } from '../../../../common/service_groups';
import { ApmAlertsClient } from '../../../lib/helpers/get_apm_alerts_client';
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function getServicesAlerts({
query: {
bool: {
filter: [
...termsQuery(ALERT_RULE_PRODUCER, 'apm', observabilityFeatureId),
...termsQuery(ALERT_RULE_PRODUCER, ...APM_ALERTING_CONSUMERS),
...termQuery(ALERT_STATUS, ALERT_STATUS_ACTIVE),
...rangeQuery(start, end),
...kqlQuery(kuery),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import { Chart, Axis, AreaSeries, Position, ScaleType, Settings } from '@elastic
import { useActiveCursor } from '@kbn/charts-plugin/public';
import { EuiSkeletonText } from '@elastic/eui';
import { getBrushData } from '@kbn/observability-utils-browser/chart/utils';
import { Group } from '@kbn/observability-alerting-rule-utils';
import { ALERT_GROUP } from '@kbn/rule-data-utils';
import { SERVICE_NAME } from '@kbn/observability-shared-plugin/common';
import { AnnotationEvent } from './annotation_event';
import { TIME_LINE_THEME } from './timeline_theme';
import { useFetchEvents } from '../../../../hooks/use_fetch_events';
Expand All @@ -27,19 +24,10 @@ export const EventsTimeLine = () => {
const baseTheme = dependencies.start.charts.theme.useChartsBaseTheme();

const { globalParams, updateInvestigationParams } = useInvestigation();
const { alert } = useInvestigation();

const filter = useMemo(() => {
const group = (alert?.[ALERT_GROUP] as unknown as Group[])?.find(
({ field }) => field === SERVICE_NAME
);
return group ? `{"${SERVICE_NAME}":"${alert?.[SERVICE_NAME]}"}` : '';
}, [alert]);

const { data: events, isLoading } = useFetchEvents({
rangeFrom: globalParams.timeRange.from,
rangeTo: globalParams.timeRange.to,
filter,
});

const chartRef = useRef(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"@kbn/calculate-auto",
"@kbn/ml-random-sampler-utils",
"@kbn/charts-plugin",
"@kbn/observability-alerting-rule-utils",
"@kbn/observability-utils-browser",
"@kbn/usage-collection-plugin",
"@kbn/inference-common",
Expand Down
Loading

0 comments on commit 5749f8a

Please sign in to comment.