Skip to content

Commit

Permalink
Merge branch 'main' into unskip-osquery-serverless-tier-e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
szwarckonrad authored Feb 23, 2024
2 parents f76f082 + c2b3173 commit 2a9741f
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { FlyoutPanels } from './flyout_panels';

import { removeSpaces } from '../lib';

import { noTimeFieldLabel, noTimeFieldValue } from '../lib/extract_time_fields';

import {
DataViewEditorContext,
RollupIndicesCapsResponse,
Expand Down Expand Up @@ -109,7 +111,9 @@ const IndexPatternEditorFlyoutContentComponent = ({
id: editData.id,
name: editData.name,
allowHidden: editData.getAllowHidden(),
...(editData.timeFieldName
...(editData.timeFieldName === noTimeFieldValue
? { timestampField: { label: noTimeFieldLabel, value: noTimeFieldValue } }
: editData.timeFieldName
? {
timestampField: { label: editData.timeFieldName, value: editData.timeFieldName },
}
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/data_view_editor/public/lib/extract_time_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import { i18n } from '@kbn/i18n';
import { DataViewField } from '@kbn/data-views-plugin/public';
import { TimestampOption } from '../types';

export const noTimeFieldLabel = i18n.translate(
'indexPatternEditor.createIndexPattern.stepTime.noTimeFieldOptionLabel',
{
defaultMessage: "--- I don't want to use the time filter ---",
}
);
export const noTimeFieldValue = '';

export function extractTimeFields(
fields: DataViewField[],
requireTimestampField: boolean = false
Expand All @@ -20,15 +28,9 @@ export function extractTimeFields(
return [];
}

const noTimeFieldLabel = i18n.translate(
'indexPatternEditor.createIndexPattern.stepTime.noTimeFieldOptionLabel',
{
defaultMessage: "--- I don't want to use the time filter ---",
}
);
const noTimeFieldOption = {
display: noTimeFieldLabel,
fieldName: '',
fieldName: noTimeFieldValue,
};

const timeFields = dateFields.map((field) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,55 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.getVisibleText('indexPatternTitle')).to.contain(`Index Star`);
});
});

it('prefills the form with previously saved values', async () => {
await PageObjects.settings.editIndexPattern('logs*', 'utc_time', 'Logs UTC', true);

await PageObjects.settings.clickEditIndexButton();
await PageObjects.header.waitUntilLoadingHasFinished();

await retry.waitFor('time field', async () => {
const timeFieldInput = await PageObjects.settings.getTimeFieldNameField();
return (await timeFieldInput.getAttribute('value')) === 'utc_time';
});
expect(await (await PageObjects.settings.getNameField()).getAttribute('value')).to.be(
'Logs UTC'
);
expect(
await (await PageObjects.settings.getIndexPatternField()).getAttribute('value')
).to.be('logs*');

await testSubjects.click('closeFlyoutButton');
await PageObjects.header.waitUntilLoadingHasFinished();
expect(await testSubjects.getVisibleText('currentIndexPatternTimeField')).to.be('utc_time');

await PageObjects.settings.editIndexPattern(
'logstash-*',
PageObjects.settings.noTimeFieldOption,
'Just logs',
true
);

await PageObjects.settings.clickEditIndexButton();
await PageObjects.header.waitUntilLoadingHasFinished();

await retry.waitFor('time field', async () => {
const timeFieldInput = await PageObjects.settings.getTimeFieldNameField();
return (
(await timeFieldInput.getAttribute('value')) === PageObjects.settings.noTimeFieldOption
);
});
expect(await (await PageObjects.settings.getNameField()).getAttribute('value')).to.be(
'Just logs'
);
expect(
await (await PageObjects.settings.getIndexPatternField()).getAttribute('value')
).to.be('logstash-*');

await testSubjects.click('closeFlyoutButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await testSubjects.missingOrFail('currentIndexPatternTimeField');
});
});

describe('index pattern edit', function () {
Expand Down
7 changes: 7 additions & 0 deletions test/functional/page_objects/settings_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ export class SettingsPageObject extends FtrService {
return this.testSubjects.find('createIndexPatternTitleInput');
}

async getTimeFieldNameField() {
const wrapperElement = await this.testSubjects.find('timestampField');
return wrapperElement.findByTestSubject('comboBoxSearchInput');
}

noTimeFieldOption = "--- I don't want to use the time filter ---";

async selectTimeFieldOption(selection: string) {
const testSubj = 'timestampField';
const timefield = await this.testSubjects.find(testSubj);
Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/enterprise_search/server/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,11 @@ export const registerEnterpriseSearchIntegrations = (
'connector_client',
],
uiInternalPath:
'/app/enterprise_search/content/search_indices/new_index/connector?service_type=salesforce',
'/app/enterprise_search/content/search_indices/new_index/connector?service_type=onedrive',
icons: [
{
type: 'svg',
src: http.basePath.prepend(
'/plugins/enterpriseSearch/assets/source_icons/salesforce_sandbox.svg'
),
src: http.basePath.prepend('/plugins/enterpriseSearch/assets/source_icons/onedrive.svg'),
},
],
shipper: 'enterprise_search',
Expand Down Expand Up @@ -977,7 +975,7 @@ export const registerEnterpriseSearchIntegrations = (
},
],
shipper: 'enterprise_search',
isBeta: false,
isBeta: true,
});

customIntegrations.registerCustomIntegration({
Expand Down
18 changes: 0 additions & 18 deletions x-pack/plugins/infra/public/common/alerts/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import React from 'react';
import { EuiText, EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { ALERTS_DOC_HREF } from '../../../common/alerts/constants';
import { LinkToAlertsHomePage } from '../links/link_to_alerts_page';
import { ALERTS_DOC_HREF } from '../../shared/alerts/constants';

export const AlertsTooltipContent = React.memo(() => {
const onClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import { pipe } from 'fp-ts/lib/pipeable';
import { fold } from 'fp-ts/lib/Either';
import { constant, identity } from 'fp-ts/lib/function';
import { useCallback } from 'react';
import {
ALERT_STATUS_ACTIVE,
ALERT_STATUS_RECOVERED,
ALERT_STATUS_UNTRACKED,
} from '@kbn/rule-data-utils';
import { ContentTabIds } from '../types';
import { useUrlState } from '../../../utils/use_url_state';
import { ASSET_DETAILS_URL_STATE_KEY } from '../constants';
import { ALERT_STATUS_ALL } from '../../shared/alerts/constants';

export const DEFAULT_STATE: AssetDetailsUrlState = {
tabId: ContentTabIds.OVERVIEW,
Expand Down Expand Up @@ -55,6 +61,13 @@ const TabIdRT = rt.union([
rt.literal(ContentTabIds.OSQUERY),
]);

const AlertStatusRT = rt.union([
rt.literal(ALERT_STATUS_ALL),
rt.literal(ALERT_STATUS_ACTIVE),
rt.literal(ALERT_STATUS_RECOVERED),
rt.literal(ALERT_STATUS_UNTRACKED),
]);

const AssetDetailsUrlStateRT = rt.partial({
autoRefresh: rt.partial({
isPaused: rt.boolean,
Expand All @@ -70,6 +83,7 @@ const AssetDetailsUrlStateRT = rt.partial({
metadataSearch: rt.string,
logsSearch: rt.string,
profilingSearch: rt.string,
alertStatus: AlertStatusRT,
});

const AssetDetailsUrlRT = rt.union([AssetDetailsUrlStateRT, rt.null]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiButtonEmpty, EuiLink } from '@elastic/eui';
import type { TimeRange } from '@kbn/es-query';
import { ALERTS_PATH } from '../../../common/alerts/constants';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { ALERTS_PATH } from '../../shared/alerts/constants';

export interface LinkToAlertsPageProps {
assetName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React, { useMemo, useState } from 'react';

import React, { useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, type EuiAccordionProps } from '@elastic/eui';
import { useSummaryTimeRange } from '@kbn/observability-plugin/public';
import type { TimeRange } from '@kbn/es-query';
import type { InventoryItemType } from '@kbn/metrics-data-access-plugin/common';
import { findInventoryFields } from '@kbn/metrics-data-access-plugin/common';
import { usePluginConfig } from '../../../../containers/plugin_config_context';
import type { AlertsEsQuery } from '../../../../common/alerts/types';
import { createAlertsEsQuery } from '../../../../common/alerts/create_alerts_es_query';
import { infraAlertFeatureIds } from '../../../../pages/metrics/hosts/components/tabs/config';
import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana';
import { LinkToAlertsRule } from '../../links/link_to_alerts';
import { LinkToAlertsPage } from '../../links/link_to_alerts_page';
import { AlertFlyout } from '../../../../alerting/inventory/components/alert_flyout';
import { useBoolean } from '../../../../hooks/use_boolean';
import { ALERT_STATUS_ALL } from '../../../../common/alerts/constants';
import { AlertsSectionTitle } from '../../components/section_titles';
import { useAssetDetailsRenderPropsContext } from '../../hooks/use_asset_details_render_props';
import { CollapsibleSection } from './section/collapsible_section';
import { AlertsClosedContent } from './alerts_closed_content';
import { type AlertsCount } from '../../../../hooks/use_alerts_count';
import { AlertsOverview } from '../../../shared/alerts/alerts_overview';

export const AlertsSummaryContent = ({
assetName,
Expand All @@ -43,16 +38,6 @@ export const AlertsSummaryContent = ({
useState<EuiAccordionProps['forceState']>('open');
const [activeAlertsCount, setActiveAlertsCount] = useState<number | undefined>(undefined);

const alertsEsQueryByStatus = useMemo(
() =>
createAlertsEsQuery({
dateRange,
hostNodeNames: [assetName],
status: ALERT_STATUS_ALL,
}),
[assetName, dateRange]
);

const onLoaded = (alertsCount?: AlertsCount) => {
const { activeAlertCount = 0 } = alertsCount ?? {};
const hasActiveAlerts = activeAlertCount > 0;
Expand Down Expand Up @@ -87,11 +72,7 @@ export const AlertsSummaryContent = ({
</EuiFlexGroup>
}
>
<MemoAlertSummaryWidget
onLoaded={onLoaded}
alertsQuery={alertsEsQueryByStatus}
dateRange={dateRange}
/>
<AlertsOverview onLoaded={onLoaded} dateRange={dateRange} assetName={assetName} />
</CollapsibleSection>
{featureFlags.inventoryThresholdAlertRuleEnabled && (
<AlertFlyout
Expand All @@ -105,36 +86,3 @@ export const AlertsSummaryContent = ({
</>
);
};

interface MemoAlertSummaryWidgetProps {
alertsQuery: AlertsEsQuery;
dateRange: TimeRange;
onLoaded: (alertsCount?: AlertsCount) => void;
}

const MemoAlertSummaryWidget = React.memo(
({ alertsQuery, dateRange, onLoaded }: MemoAlertSummaryWidgetProps) => {
const { services } = useKibanaContextForPlugin();

const summaryTimeRange = useSummaryTimeRange(dateRange);

const { charts, triggersActionsUi } = services;
const { getAlertSummaryWidget: AlertSummaryWidget } = triggersActionsUi;

const chartProps = {
baseTheme: charts.theme.useChartsBaseTheme(),
};

return (
<AlertSummaryWidget
chartProps={chartProps}
featureIds={infraAlertFeatureIds}
filter={alertsQuery}
timeRange={summaryTimeRange}
onLoaded={onLoaded}
fullSize
hideChart
/>
);
}
);
Loading

0 comments on commit 2a9741f

Please sign in to comment.