Skip to content

Commit

Permalink
[Entity Analytics] Refactor: move common/risk_engine and `common/as…
Browse files Browse the repository at this point in the history
…set_criticality` under `common/entity_analytics` (#172849)

## Summary

As elsewhere move our code under one folder and update codeowners. 

This is also driven by me wanting to create a common entity analytics
util that will live in `common/entity_analytics` but not won't belong in
asset criticality or risk engine.
  • Loading branch information
hop-dev authored Dec 11, 2023
1 parent 76bcfd3 commit 0de5941
Show file tree
Hide file tree
Showing 62 changed files with 88 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ x-pack/plugins/security_solution/public/threat_intelligence @elastic/protections
x-pack/test/threat_intelligence_cypress @elastic/protections-experience

## Security Solution sub teams - Entity Analytics
x-pack/plugins/security_solution/common/risk_engine @elastic/security-entity-analytics @elastic/security-entity-analytics
x-pack/plugins/security_solution/common/entity_analytics @elastic/security-entity-analytics
x-pack/plugins/security_solution/common/search_strategy/security_solution/risk_score @elastic/security-entity-analytics
x-pack/plugins/security_solution/public/entity_analytics @elastic/security-entity-analytics
x-pack/plugins/security_solution/public/explore/components/risk_score @elastic/security-entity-analytics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { IEsSearchResponse } from '@kbn/data-plugin/common';

import type { Inspect, Maybe, SortField } from '../../../common';
import type { RiskInputs } from '../../../../risk_engine';
import type { RiskInputs } from '../../../../entity_analytics/risk_engine';

export interface HostsRiskScoreStrategyResponse extends IEsSearchResponse {
inspect?: Maybe<Inspect>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
RiskScoreEntity,
getRiskScoreLatestIndex,
getRiskScoreTimeSeriesIndex,
} from '../../../../risk_engine';
} from '../../../../entity_analytics/risk_engine';
export { RiskQueries } from '../../../../api/search_strategy';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { RiskScoreEntity } from '../../../../../../../common/risk_engine';
import { RiskScoreEntity } from '../../../../../../../common/entity_analytics/risk_engine';
import { renderHook } from '@testing-library/react-hooks';
import { wrapper } from '../../../mocks';
import { useLensAttributes } from '../../../use_lens_attributes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
InitRiskEngineResponse,
DisableRiskEngineResponse,
} from '../../../server/lib/entity_analytics/types';
import type { RiskScorePreviewRequestSchema } from '../../../common/risk_engine/risk_score_preview/request_schema';
import type { RiskScorePreviewRequestSchema } from '../../../common/entity_analytics/risk_engine/risk_score_preview/request_schema';
import type { EntityAnalyticsPrivileges } from '../../../common/api/entity_analytics/common';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { useQuery } from '@tanstack/react-query';
import dateMath from '@kbn/datemath';
import { fetchRiskScorePreview } from '../api';
import type { RiskScorePreviewRequestSchema } from '../../../../common/risk_engine/risk_score_preview/request_schema';
import type { RiskScorePreviewRequestSchema } from '../../../../common/entity_analytics/risk_engine/risk_score_preview/request_schema';

export const useRiskScorePreview = ({
data_view_id: dataViewId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useCallback } from 'react';
import { fetchRiskEngineStatus } from '../api';
import { RiskEngineStatus } from '../../../../common/risk_engine/types';
import { RiskEngineStatus } from '../../../../common/entity_analytics/risk_engine/types';
import { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features';
const FETCH_RISK_ENGINE_STATUS = ['GET', 'FETCH_RISK_ENGINE_STATUS'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useRiskEnginePrivileges } from '../../api/hooks/use_risk_engine_privile
import {
RISK_ENGINE_REQUIRED_ES_CLUSTER_PRIVILEGES,
RISK_ENGINE_REQUIRED_ES_INDEX_PRIVILEGES,
} from '../../../../common/risk_engine';
} from '../../../../common/entity_analytics/risk_engine';

const getMissingIndexPrivileges = (
privileges: EntityAnalyticsPrivileges['privileges']['elasticsearch']['index']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { useRiskEngineStatus } from '../api/hooks/use_risk_engine_status';
import { useInitRiskEngineMutation } from '../api/hooks/use_init_risk_engine_mutation';
import { useEnableRiskEngineMutation } from '../api/hooks/use_enable_risk_engine_mutation';
import { useDisableRiskEngineMutation } from '../api/hooks/use_disable_risk_engine_mutation';
import { RiskEngineStatus, MAX_SPACES_COUNT } from '../../../common/risk_engine';
import { RiskEngineStatus, MAX_SPACES_COUNT } from '../../../common/entity_analytics/risk_engine';

import { RiskInformationFlyout } from '../../explore/components/risk_score/risk_information';
import { useOnOpenCloseHandler } from '../../helper_hooks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@elastic/eui';
import type { BoolQuery, TimeRange, Query } from '@kbn/es-query';
import { buildEsQuery } from '@kbn/es-query';
import { RiskScoreEntity, type RiskScore } from '../../../common/risk_engine';
import { RiskScoreEntity, type RiskScore } from '../../../common/entity_analytics/risk_engine';
import { RiskScorePreviewTable } from './risk_score_preview_table';
import * as i18n from '../translations';
import { useRiskScorePreview } from '../api/hooks/use_preview_risk_scores';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import type { RiskSeverity } from '../../../common/search_strategy';
import { RiskScoreLevel } from '../../explore/components/risk_score/severity/common';

import { HostDetailsLink, UserDetailsLink } from '../../common/components/links';
import { RiskScoreEntity, type RiskScore as IRiskScore } from '../../../common/risk_engine';
import {
RiskScoreEntity,
type RiskScore as IRiskScore,
} from '../../../common/entity_analytics/risk_engine';

type RiskScoreColumn = EuiBasicTableColumn<IRiskScore> & {
field: keyof IRiskScore;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/x-pack/plugins/security_solution/public/entity_analytics'],
coverageDirectory:
'<rootDir>/target/kibana-coverage/jest/x-pack/plugins/security_solution/public/entity_analytics',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
'<rootDir>/x-pack/plugins/security_solution/public/entity_analytics/**/*.{ts,tsx}',
],
moduleNameMapper: require('../../server/__mocks__/module_name_map'),
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { i18n } from '@kbn/i18n';
import type { RiskScoreEntity } from '../../../../../common/risk_engine';
import type { RiskScoreEntity } from '../../../../../common/entity_analytics/risk_engine';
import { getRiskEntityTranslation } from '../translations';

export const BETA = i18n.translate('xpack.securitySolution.riskScore.technicalPreviewLabel', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { Filter } from '@kbn/es-query';
import { HeaderSection } from '../../../../common/components/header_section';

import * as i18n from './translations';
import type { RiskInputs } from '../../../../../common/risk_engine';
import { RiskScoreEntity } from '../../../../../common/risk_engine';
import type { RiskInputs } from '../../../../../common/entity_analytics/risk_engine';
import { RiskScoreEntity } from '../../../../../common/entity_analytics/risk_engine';
import type { HostRiskScore, UserRiskScore } from '../../../../../common/search_strategy';
import { ALERTS_TABLE_REGISTRY_CONFIG_IDS } from '../../../../../common/constants';
import { AlertsTableComponent } from '../../../../detections/components/alerts_table';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import type { SimpleRiskInput } from '../../../../common/risk_engine';
import { RiskCategories } from '../../../../common/risk_engine';
import type { SimpleRiskInput } from '../../../../common/entity_analytics/risk_engine';
import { RiskCategories } from '../../../../common/entity_analytics/risk_engine';
import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { RiskInputsPanel } from '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { css } from '@emotion/react';
import { FormattedMessage } from '@kbn/i18n-react';
import { get } from 'lodash/fp';
import { ALERT_RULE_NAME } from '@kbn/rule-data-utils';
import type { RiskInputs } from '../../../../common/risk_engine';
import type { RiskInputs } from '../../../../common/entity_analytics/risk_engine';
import { ActionColumn } from './components/action_column';
import { PreferenceFormattedDate } from '../../../common/components/formatted_date';
import { RiskInputsUtilityBar } from './components/utility_bar';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import type { FlyoutPanelProps } from '@kbn/expandable-flyout';
import type { RiskInputs } from '../../../../common/risk_engine';
import type { RiskInputs } from '../../../../common/entity_analytics/risk_engine';
import { RiskInputsPanelContent } from './content';

export interface RiskInputsPanelProps extends Record<string, unknown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { i18n } from '@kbn/i18n';
import { InspectButton, InspectButtonContainer } from '../../../../common/components/inspect';
import { ONE_WEEK_IN_HOURS } from '../../../../timelines/components/side_panel/new_user_detail/constants';
import { FormattedRelativePreferenceDate } from '../../../../common/components/formatted_date';
import { RiskScoreEntity } from '../../../../../common/risk_engine';
import { RiskScoreEntity } from '../../../../../common/entity_analytics/risk_engine';
import type { RiskScoreState } from '../../../../explore/containers/risk_score';
import { VisualizationEmbeddable } from '../../../../common/components/visualization_actions/visualization_embeddable';
import { getRiskScoreSummaryAttributes } from '../../../../common/components/visualization_actions/lens_attributes/common/risk_scores/risk_score_summary';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useGlobalTime } from '../../../common/containers/use_global_time';
import { AnomalyTableProvider } from '../../../common/components/ml/anomaly/anomaly_table_provider';
import { buildUserNamesFilter } from '../../../../common/search_strategy';
import { useRiskScore } from '../../../explore/containers/risk_score';
import { RiskScoreEntity } from '../../../../common/risk_engine';
import { RiskScoreEntity } from '../../../../common/entity_analytics/risk_engine';
import { FlyoutLoading } from '../../shared/components/flyout_loading';
import { RiskInputsPanelKey } from '../risk_inputs_left';
import { FlyoutNavigation } from '../../shared/components/flyout_navigation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { RiskScoreState } from '../../../../explore/containers/risk_score';
import type { RiskScoreEntity, UserRiskScore } from '../../../../../common/search_strategy';
import { RiskSeverity } from '../../../../../common/search_strategy';
import { RiskCategories } from '../../../../../common/risk_engine';
import { RiskCategories } from '../../../../../common/entity_analytics/risk_engine';

const userRiskScore: UserRiskScore = {
'@timestamp': '626569200000',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiButtonIcon, EuiPopover, EuiPopoverTitle, EuiText } from '@elastic/eu
import React, { useCallback, useState } from 'react';
import * as i18n from './translations';
import { RiskScoreDocLink } from '../../explore/components/risk_score/risk_score_onboarding/risk_score_doc_link';
import type { RiskScoreEntity } from '../../../common/risk_engine';
import type { RiskScoreEntity } from '../../../common/entity_analytics/risk_engine';

export const RiskScoreInfoTooltip: React.FC<{
toolTipContent: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Logger, ElasticsearchClient } from '@kbn/core/server';
import { mappingFromFieldMap } from '@kbn/alerting-plugin/common';
import type { AssetCriticalityRecord } from '../../../../common/api/entity_analytics/asset_criticality';
import { createOrUpdateIndex } from '../utils/create_or_update_index';
import { getAssetCriticalityIndex } from '../../../../common/asset_criticality';
import { getAssetCriticalityIndex } from '../../../../common/entity_analytics/asset_criticality';
import { assetCriticalityFieldMap } from './configurations';

interface AssetCriticalityClientOpts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { KibanaRequest } from '@kbn/core/server';
import type { SecurityPluginStart } from '@kbn/security-plugin/server';
import { checkAndFormatPrivileges } from '../utils/check_and_format_privileges';
import { ASSET_CRITICALITY_REQUIRED_ES_INDEX_PRIVILEGES } from '../../../../common/asset_criticality';
import { ASSET_CRITICALITY_REQUIRED_ES_INDEX_PRIVILEGES } from '../../../../common/entity_analytics/asset_criticality';

export const getUserAssetCriticalityPrivileges = async (
request: KibanaRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { SecurityPluginStart } from '@kbn/security-plugin/server';
import {
RISK_ENGINE_REQUIRED_ES_CLUSTER_PRIVILEGES,
RISK_ENGINE_REQUIRED_ES_INDEX_PRIVILEGES,
} from '../../../../common/risk_engine';
} from '../../../../common/entity_analytics/risk_engine';
import { checkAndFormatPrivileges } from '../utils/check_and_format_privileges';

export const getUserRiskEnginePrivileges = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import type { Logger, ElasticsearchClient, SavedObjectsClientContract } from '@kbn/core/server';
import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server';
import type { InitRiskEngineResult } from '../../../../common/risk_engine';
import type { InitRiskEngineResult } from '../../../../common/entity_analytics/risk_engine';
import {
RiskEngineStatus,
MAX_SPACES_COUNT,
RiskScoreEntity,
} from '../../../../common/risk_engine';
} from '../../../../common/entity_analytics/risk_engine';
import { removeLegacyTransforms, getLegacyTransforms } from '../utils/transforms';
import {
updateSavedObjectAttribute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ALERT_RISK_SCORE,
ALERT_RULE_NAME,
} from '@kbn/rule-registry-plugin/common/technical_rule_data_field_names';
import { RiskCategories } from '../../../../common/risk_engine';
import { RiskCategories } from '../../../../common/entity_analytics/risk_engine';
import type {
CalculateRiskScoreAggregations,
CalculateScoresResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import type {
IdentifierType,
RiskWeights,
RiskScore,
} from '../../../../common/risk_engine';
import { RiskCategories } from '../../../../common/risk_engine';
} from '../../../../common/entity_analytics/risk_engine';
import { RiskCategories } from '../../../../common/entity_analytics/risk_engine';
import { withSecuritySpan } from '../../../utils/with_security_span';
import { getAfterKeyForIdentifierType, getFieldForIdentifierAgg } from './helpers';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* 2.0.
*/
import type { FieldMap } from '@kbn/alerts-as-data-utils';
import type { IdentifierType } from '../../../../common/risk_engine';
import { RiskScoreEntity, riskScoreBaseIndexName } from '../../../../common/risk_engine';
import type { IdentifierType } from '../../../../common/entity_analytics/risk_engine';
import {
RiskScoreEntity,
riskScoreBaseIndexName,
} from '../../../../common/entity_analytics/risk_engine';
import type { IIndexPatternString } from '../utils/create_datastream';

const commonRiskFields: FieldMap = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import type { AfterKey, AfterKeys, IdentifierType } from '../../../../common/risk_engine';
import type {
AfterKey,
AfterKeys,
IdentifierType,
} from '../../../../common/entity_analytics/risk_engine';
import type { CalculateAndPersistScoresResponse } from '../types';

export const getFieldForIdentifierAgg = (identifierType: IdentifierType): string =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { BulkOperationContainer } from '@elastic/elasticsearch/lib/api/types';
import type { Logger, ElasticsearchClient } from '@kbn/core/server';
import type { IdentifierType, RiskScore } from '../../../../common/risk_engine';
import type { IdentifierType, RiskScore } from '../../../../common/entity_analytics/risk_engine';

interface WriterBulkResponse {
errors: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { createDataStream } from '../utils/create_datastream';
import type { RiskEngineDataWriter as Writer } from './risk_engine_data_writer';
import { RiskEngineDataWriter } from './risk_engine_data_writer';
import { getRiskScoreLatestIndex } from '../../../../common/risk_engine';
import { getRiskScoreLatestIndex } from '../../../../common/entity_analytics/risk_engine';
import { getLatestTransformId, createTransform } from '../utils/transforms';
import { getRiskInputsIndex } from './get_risk_inputs_index';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { RiskScoreService } from './risk_score_service';
import type { RiskScore } from '../../../../common/risk_engine';
import type { RiskScore } from '../../../../common/entity_analytics/risk_engine';

const createRiskScoreMock = (overrides: Partial<RiskScore> = {}): RiskScore => ({
'@timestamp': '2023-02-15T00:15:19.231Z',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { RiskWeightTypes, RiskCategories } from '../../../../common/risk_engine';
import { RiskWeightTypes, RiskCategories } from '../../../../common/entity_analytics/risk_engine';
import {
buildCategoryAssignment,
buildCategoryWeights,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import type {
RiskCategoryRiskWeight,
RiskWeight,
RiskWeights,
} from '../../../../common/risk_engine';
import { RiskCategories, RiskWeightTypes } from '../../../../common/risk_engine';
} from '../../../../common/entity_analytics/risk_engine';
import { RiskCategories, RiskWeightTypes } from '../../../../common/entity_analytics/risk_engine';

const RISK_CATEGORIES = Object.values(RiskCategories);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
DEFAULT_RISK_SCORE_PAGE_SIZE,
RISK_SCORE_CALCULATION_URL,
} from '../../../../../common/constants';
import { riskScoreCalculationRequestSchema } from '../../../../../common/risk_engine/risk_score_calculation/request_schema';
import { riskScoreCalculationRequestSchema } from '../../../../../common/entity_analytics/risk_engine/risk_score_calculation/request_schema';
import type { SecuritySolutionPluginRouter } from '../../../../types';
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
import { riskScoreServiceFactory } from '../risk_score_service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import { loggerMock } from '@kbn/logging-mocks';

import { RISK_SCORE_PREVIEW_URL } from '../../../../../common/constants';
import { RiskCategories, RiskWeightTypes } from '../../../../../common/risk_engine';
import {
RiskCategories,
RiskWeightTypes,
} from '../../../../../common/entity_analytics/risk_engine';
import {
serverMock,
requestContextMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
DEFAULT_RISK_SCORE_PAGE_SIZE,
RISK_SCORE_PREVIEW_URL,
} from '../../../../../common/constants';
import { riskScorePreviewRequestSchema } from '../../../../../common/risk_engine/risk_score_preview/request_schema';
import { riskScorePreviewRequestSchema } from '../../../../../common/entity_analytics/risk_engine/risk_score_preview/request_schema';
import type { SecuritySolutionPluginRouter } from '../../../../types';
import { buildRouteValidation } from '../../../../utils/build_validation/route_validation';
import { riskScoreServiceFactory } from '../risk_score_service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@kbn/core/server';
import { addSpaceIdToPath } from '@kbn/spaces-plugin/server';

import type { Range } from '../../../../../common/risk_engine';
import type { Range } from '../../../../../common/entity_analytics/risk_engine';

export const convertDateToISOString = (dateString: string): string => {
const date = datemath.parse(dateString);
Expand Down
Loading

0 comments on commit 0de5941

Please sign in to comment.