Skip to content

Commit

Permalink
bug fixes related to mds suppport
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Aug 30, 2024
1 parent c0f2bf8 commit b607bec
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 16 deletions.
2 changes: 1 addition & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"server": true,
"ui": true,
"supportedOSDataSourceVersions": ">=2.16.0",
"requiredOSDataSourcePlugins": ["opensearch_security_analytics"]
"requiredOSDataSourcePlugins": ["opensearch-security-analytics"]
}
2 changes: 1 addition & 1 deletion public/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const PageHeader: React.FC<PageHeaderProps> = ({
}) => {
const { HeaderControl } = getNavigationUI();
const { setAppBadgeControls, setAppRightControls, setAppDescriptionControls } = getApplication();

return getUseUpdatedUx() ? (
<>
<HeaderControl setMountPoint={setAppBadgeControls} controls={appBadgeControls} />
Expand Down
39 changes: 30 additions & 9 deletions public/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Toast } from '@opensearch-project/oui/src/eui_components/toast/global_toast_list';
import { AppMountParameters, CoreStart, SavedObject } from 'opensearch-dashboards/public';
import { SaContextConsumer } from '../../services';
import { DEFAULT_DATE_RANGE, DATE_TIME_FILTER_KEY, ROUTES } from '../../utils/constants';
import { DEFAULT_DATE_RANGE, DATE_TIME_FILTER_KEY, ROUTES, dataSourceObservable } from '../../utils/constants';
import { CoreServicesConsumer } from '../../components/core_services';
import Findings from '../Findings';
import Detectors from '../Detectors';
Expand Down Expand Up @@ -64,6 +64,7 @@ import { ThreatIntelSource } from '../ThreatIntel/containers/ThreatIntelSource/T
import * as pluginManifest from "../../../opensearch_dashboards.json";
import { DataSourceAttributes } from "../../../../../src/plugins/data_source/common/data_sources";
import semver from "semver";
import queryString from "query-string";

enum Navigation {
SecurityAnalytics = 'Security Analytics',
Expand Down Expand Up @@ -136,19 +137,40 @@ export default class Main extends Component<MainProps, MainState> {
const defaultDateTimeFilter = cachedDateTimeFilter
? JSON.parse(cachedDateTimeFilter)
: {
startTime: DEFAULT_DATE_RANGE.start,
endTime: DEFAULT_DATE_RANGE.end,
};
startTime: DEFAULT_DATE_RANGE.start,
endTime: DEFAULT_DATE_RANGE.end,
};
let dataSourceId = "";
let dataSourceLabel = "";
if (props.multiDataSourceEnabled) {
const { dataSourceId: parsedDataSourceId, dataSourceLabel: parsedDataSourceLabel } = queryString.parse(
this.props.location.search
) as {
dataSourceId: string;
dataSourceLabel: string;
};
dataSourceId = parsedDataSourceId;
dataSourceLabel = parsedDataSourceLabel || "";

if (dataSourceId) {
dataSourceObservable.next({ id: dataSourceId, label: dataSourceLabel });
}
}

this.state = {
getStartedDismissedOnce: false,
selectedNavItemId: Navigation.Overview,
dateTimeFilter: defaultDateTimeFilter,
showFlyoutData: null,
dataSourceLoading: props.multiDataSourceEnabled,
selectedDataSource: { id: '' },
/**
* undefined: need data source picker to help to determine which data source to use.
* empty string: using the local cluster.
* string: using the selected data source.
*/
dataSourceLoading: dataSourceId === undefined ? props.multiDataSourceEnabled : false,
selectedDataSource: { id: dataSourceId },
dataSourceMenuReadOnly: false,
};

DataStore.detectors.setHandlers(this.showCallout, this.showToast);
DataStore.findings.setFlyoutCallback(this.showFlyout);
}
Expand Down Expand Up @@ -237,7 +259,7 @@ export default class Main extends Component<MainProps, MainState> {
selectedDataSource: { ...sources[0] },
});
}

dataSourceObservable.next({ id: this.state.selectedDataSource.id, label: this.state.selectedDataSource.label });
if (dataSourceLoading) {
this.setState({ dataSourceLoading: false });
}
Expand Down Expand Up @@ -403,7 +425,6 @@ export default class Main extends Component<MainProps, MainState> {
dataSourceMenuReadOnly,
} = this.state;
const sideNav: EuiSideNavItemType<{ style: any }>[] = this.getSideNavItems();

const dataSourceContextValue: DataSourceContextType = {
dataSource: selectedDataSource,
setDataSource: this.onDataSourceSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const DetectorsWidget: React.FC<DetectorsWidgetProps> = ({
);

return (
<WidgetContainer title={`Detectors (${detectors.length})`} actions={actions}>
<WidgetContainer title={`Threat detectors (${detectors.length})`} actions={actions}>
<TableWidget
columns={getColumns(detectorIdToHit, showDetectorDetails)}
items={detectors}
Expand Down
27 changes: 27 additions & 0 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import {
AppMountParameters,
AppUpdater,
CoreSetup,
CoreStart,
DEFAULT_APP_CATEGORIES,
Expand All @@ -24,6 +25,7 @@ import {
ROUTES,
THREAT_ALERTS_NAV_ID,
THREAT_INTEL_NAV_ID,
dataSourceObservable,
setDarkMode,
} from './utils/constants';
import { SecurityAnalyticsPluginSetup, SecurityAnalyticsPluginStart } from './index';
Expand All @@ -39,6 +41,7 @@ import {
setApplication,
setBreadCrumbsSetter,
} from './services/utils/constants';
import { BehaviorSubject } from 'rxjs';

export interface SecurityAnalyticsPluginSetupDeps {
data: DataPublicPluginSetup;
Expand All @@ -62,6 +65,15 @@ export class SecurityAnalyticsPlugin
private initializerContext: PluginInitializerContext<SecurityAnalyticsPluginConfigType>
) {}

private updateDefaultRouteOfManagementApplications: AppUpdater = () => {
const hash = `#/?dataSourceId=${dataSourceObservable.value?.id || ""}`;
return {
defaultPath: hash,
};
};

private appStateUpdater = new BehaviorSubject<AppUpdater>(this.updateDefaultRouteOfManagementApplications);

public setup(
core: CoreSetup<SecurityAnalyticsPluginStartDeps>,
{ dataSourceManagement }: SecurityAnalyticsPluginSetupDeps
Expand Down Expand Up @@ -93,6 +105,7 @@ export class SecurityAnalyticsPlugin
id: OVERVIEW_NAV_ID,
title: 'Overview',
order: 0,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.LANDING_PAGE);
},
Expand All @@ -103,6 +116,7 @@ export class SecurityAnalyticsPlugin
title: 'Threat alerts',
order: 9070,
category: DEFAULT_APP_CATEGORIES.investigate,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.ALERTS);
},
Expand All @@ -113,6 +127,7 @@ export class SecurityAnalyticsPlugin
title: 'Findings',
order: 9080,
category: DEFAULT_APP_CATEGORIES.investigate,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.FINDINGS);
},
Expand All @@ -123,6 +138,7 @@ export class SecurityAnalyticsPlugin
title: 'Correlations',
order: 9080,
category: DEFAULT_APP_CATEGORIES.investigate,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.CORRELATIONS);
},
Expand All @@ -133,6 +149,7 @@ export class SecurityAnalyticsPlugin
title: 'Threat detectors',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.DETECTORS);
},
Expand All @@ -143,6 +160,7 @@ export class SecurityAnalyticsPlugin
title: 'Detection rules',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.RULES);
},
Expand All @@ -153,6 +171,7 @@ export class SecurityAnalyticsPlugin
title: 'Correlation rules',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.CORRELATION_RULES);
},
Expand All @@ -163,6 +182,7 @@ export class SecurityAnalyticsPlugin
title: 'Threat intelligence',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.THREAT_INTEL_OVERVIEW);
},
Expand All @@ -173,11 +193,18 @@ export class SecurityAnalyticsPlugin
title: 'Log types',
order: 9080,
category: DEFAULT_APP_CATEGORIES.configure,
updater$: this.appStateUpdater,
mount: async (params: AppMountParameters) => {
return mountWrapper(params, ROUTES.LOG_TYPES);
},
});

dataSourceObservable.subscribe((dataSourceOption) => {
if (dataSourceOption) {
this.appStateUpdater.next(this.updateDefaultRouteOfManagementApplications);
}
});

const navlinks = [
{ id: OVERVIEW_NAV_ID, showInAllNavGroup: true },
{ id: THREAT_ALERTS_NAV_ID, showInAllNavGroup: true },
Expand Down
16 changes: 14 additions & 2 deletions public/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { DetectorInput, PeriodSchedule } from '../../models/interfaces';
import { DetectorHit } from '../../server/models/interfaces';
import _ from 'lodash';
import { euiPaletteColorBlind } from '@elastic/eui';
import { DataSourceOption } from 'src/plugins/data_source_management/public';
import { BehaviorSubject } from 'rxjs';
import { i18n } from "@osd/i18n";

export const DATE_MATH_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
export const MAX_RECENTLY_USED_TIME_RANGES = 5;
Expand Down Expand Up @@ -77,7 +80,7 @@ export const BREADCRUMBS = Object.freeze({
SECURITY_ANALYTICS: { text: 'Security Analytics', href: '#/' },
OVERVIEW: { text: 'Overview', href: `#${ROUTES.OVERVIEW}` },
FINDINGS: { text: 'Findings', href: `#${ROUTES.FINDINGS}` },
DETECTORS: { text: 'Detectors', href: `#${ROUTES.DETECTORS}` },
DETECTORS: { text: 'Threat detectors', href: `#${ROUTES.DETECTORS}` },
DETECTORS_CREATE: { text: 'Create detector', href: `#${ROUTES.DETECTORS_CREATE}` },
EDIT_DETECTOR_DETAILS: { text: 'Edit detector details' },
DETECTORS_DETAILS: (name: string, detectorId: string) => ({
Expand All @@ -89,7 +92,7 @@ export const BREADCRUMBS = Object.freeze({
href: `#${ROUTES.EDIT_DETECTOR_DETAILS}/${detectorId}`,
}),
RULES: { text: 'Detection rules', href: `#${ROUTES.RULES}` },
ALERTS: { text: 'Alerts', href: `#${ROUTES.ALERTS}` },
ALERTS: { text: 'Threat alerts', href: `#${ROUTES.ALERTS}` },
RULES_CREATE: { text: 'Create detection rule', href: `#${ROUTES.RULES_CREATE}` },
RULES_EDIT: { text: 'Edit rule', href: `#${ROUTES.RULES_EDIT}` },
RULES_DUPLICATE: { text: 'Duplicate rule', href: `#${ROUTES.RULES_DUPLICATE}` },
Expand Down Expand Up @@ -241,3 +244,12 @@ export enum AlertTabId {
ThreatIntel = 'threat-intel',
Correlations = 'correlations',
}

const LocalCluster: DataSourceOption = {
label: i18n.translate("dataSource.localCluster", {
defaultMessage: "Local cluster",
}),
id: "",
};

export const dataSourceObservable = new BehaviorSubject<DataSourceOption>(LocalCluster);
5 changes: 4 additions & 1 deletion public/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@elastic/eui';
import moment from 'moment';
import { PeriodSchedule } from '../../models/interfaces';
import React from 'react';
import React, { useContext, useEffect } from 'react';
import {
BREADCRUMBS,
DEFAULT_EMPTY_DATA,
Expand Down Expand Up @@ -48,6 +48,9 @@ import { compile } from 'vega-lite';
import { Handler } from 'vega-tooltip';
import { expressionInterpreter as vegaExpressionInterpreter } from 'vega-interpreter/build/vega-interpreter';
import { getBreadCrumbsSetter, getUseUpdatedUx } from '../services/utils/constants';
import { useHistory } from 'react-router-dom';
import queryString from "query-string";
import { DataSourceContext } from '../services/DataSourceContext';

export const parseStringsToOptions = (strings: string[]) => {
return strings.map((str) => ({ id: str, label: str }));
Expand Down
2 changes: 1 addition & 1 deletion types/Overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ export interface DetectorItem {
detectorName: string;
status: string;
logTypes: string;
}
}

0 comments on commit b607bec

Please sign in to comment.