diff --git a/src/plugins/discover/public/context_awareness/README.md b/src/plugins/discover/public/context_awareness/README.md new file mode 100644 index 0000000000000..3bb70dbb93e73 --- /dev/null +++ b/src/plugins/discover/public/context_awareness/README.md @@ -0,0 +1,193 @@ +# Discover context awareness + +**If you're looking for available extension point definitions, they're located in the `Profile` interface in [`types.ts`](types.ts).** + +## Summary + +The Discover context awareness framework allows Discover's UI and functionality to adapt to the surrounding context of the page, including solution type, data source, current search parameters, etc., in order to provide curated data exploration experiences across a variety of data types and scenarios. Support for this is implemented through a system of profiles that map to distinct context levels, and extension points that provide interfaces for customizing specific aspects of Discover. + +## Concepts + +### Context levels + +There are currently three context levels supported in Discover: + +- Root context: + - Based on the current solution type. + - Resolved at application initialization. + - Runs synchronously or asynchronously. +- Data source context: + - Based on the current ES|QL query or data view. + - Resolved on ES|QL query or data view change, before data fetching occurs. + - Runs synchronously or asynchronously. +- Document context: + - Based on individual ES|QL records or ES documents. + - Resolved individually for each ES|QL record or ES document after data fetching runs. + - Runs synchronously only. + +### Composable profiles + +Discover uses a concept called "composable profiles" to support context awareness. Composable profiles are implementations of a core `Profile` interface (or a subset of it) containing all of the available extension points Discover supports. A composable profile can be implemented at any context level through a "profile provider", responsible for defining the composable profile and its associated context resolution method, called `resolve`. Each provider's `resolve` method is passed a parameters object specific to its context level, which it uses to determine if its associated `profile` is a match. In cases where it is a match, the `resolve` method also returns related metadata in a `context` object. + +Within Discover there is always one resolved root profile, one resolved data source profile (as long as search results exist), and a resolved document profile for each search result in the data grid. Profile providers have access to the `context` objects of higher level providers within their `resolve` method (`root` > `data source` > `document`), making it possible to create context-dependent profiles. For example, an `oblt-logs-data-source` profile which is used when the current solution type is Observability, and the current data source contains logs data. + +Definitions for the core `Profile` interface are located in the [`types.ts`](types.ts) file. + +Definitions for the available profile provider types are located in the [`profiles`](./profiles) folder. + +### Merged accessors + +Composable profiles operate similarly to middleware in that each of their extension point implementations are passed a `prev` argument, which can be called to access the results from profiles at previous context levels, and allows overwriting or composing a final result from the previous results. The function Discover calls to trigger the extension point merging process and obtain a final result from the combined profiles is referred to as a "merged accessor". + +The merging order for profiles is based on the context level hierarchy (`root` > `data source` > `document`), meaning the root profile is passed a base implementation as its `prev` argument, the data source profile is passed the root implementation as `prev` (if one exists, otherwise the base implementation), and document profiles are passed the data source implementation as `prev` (if one exists, otherwise the root or base implementation). + +The following diagram illustrates the extension point merging process: +![image](./docs/merged_accessors.png) + +Definitions for composable profiles and the merging routine are located in the [`composable_profile.ts`](./composable_profile.ts) file. + +### Supporting services + +The context awareness framework is driven by two main supporting services called `ProfileService` and `ProfilesManager`. + +Each context level has a dedicated profile service, e.g. `RootProfileService`, which is responsible for accepting profile provider registrations and looping over each provider in order during context resolution to identify a matching profile. Each resolution call can result in only one matching profile, which is the first to return a match based on execution order. + +A single `ProfilesManager` is instantiated on Discover load, or one per saved search panel in a dashboard. The profiles manager is responsible for the following: + +- Managing state associated with the current Discover context. +- Coordinating profile services and exposing resolution methods for each context level. +- Providing access to the combined set of resolved profiles. +- Deduplicating profile resolution attempts with identical parameters. +- Error handling and fallback behaviour on profile resolution failure. + +`ProfileService` definitions and implementation are located in the [`profiles_service.ts`](./profile_service.ts) file. + +The `ProfilesManager` implementation is located in the [`profiles_manager.ts`](./profiles_manager.ts) file. + +### Putting it all together + +The following diagram models the overall Discover context awareness framework and how each of the above concepts come together: +![image](./docs/architecture.png) + +## Code organization + +One of the core ideas of the context awareness framework is that Discover is still a single application which should know about which profiles it supports and directly import the code needed to support them. This is why profile registrations are all handled internally to the plugin instead of having a registration system exposed through the plugin contract. This approach comes with several main benefits: + +- There is a single, central place where all profile registrations happen, which is much easier to maintan versus scattered registrations. +- The Data Discovery team remains aware of which profiles exist and what changes are made. This is critical to ensure the Data Discovery team is able to provide adequate customer and SDH support for Discover. +- Common code and utilities can be easily shared across profiles since they need to be accessible to Discover by default, rather than being scattered throughout various plugin codebases. + +It also comes with an important drawback: **Discover cannot depend on other plugins (e.g. solution plugins) to import code for profiles due to the dependency graph issues it would create.** + +This means that in an ideal situation, the code for Discover profiles should either live directly within the Discover codebase, or within dedicated packages which Discover imports from: + +- When adding solution specific code directly to the Discover codebase, it should be done in an organized way in order to support shared ownership. For example, the [`profile_providers/security`](./profile_providers/security) folder contains code specific to Security Solution maintained profiles, and an override has been added to the [`CODEOWNERS`](/.github/CODEOWNERS) file to reflect the shared ownership of this folder. +- When creating a dedicated package for some profile code, the maintaining team can retain full ownership over the package, and Discover is only responsible for importing the functionality and adding it to the associated profile registration. + +There are situations where neither of the above two options are viable, such as when migrating large pieces of functionality from a solution plugin to a Discover profile, which could be time consuming and involve moving huge amounts of code to packages. For these situations, there's a [discover_shared](/src/plugins/discover_shared) plugin specifically to support inversion of control for Discover profile features (see the [`README`](/src/plugins/discover_shared/README.md) for more details). + +By ensuring all Discover profiles use the same IoC mechanism, changes or improvements to the system can be centralized, and areas that use it can easily be located. In general, this should be used as a last resort when the benefits of importing directly from packages aren't worth the effort to migrate the code, and ideally teams who use it should have a plan to later refactor the code into packages. + +## Registering a profile + +In order to register a Discover profile, follow these steps: + +1. Identify at which [context level](#context-levels) your profile should be implemented. +2. Create a subfolder for your profile provider within the [`profile_providers`](./profile_providers) folder. Common Discover providers should be created within the `profile_providers/common` subfolder, while solution specific providers should be created within a `profile_providers/{SOLUTION_TYPE}` subfolder, e.g. `profile_providers/security/security_root_profile`. +3. Create a `profile.ts(x)` file within your provider subfolder that exports a factory function which optionally accepts a `ProfileProviderServices` parameter and returns your provider implementation, e.g. `createSecurityRootProfileProvider(services: ProfileProviderServices) => RootProfileProvider`. +4. **If your provider is not ready for GA or should only be enabled for specific configurations, make sure to set the `isExperimental` flag to `true` in your profile provider.** This will ensure the profile is disabled by default, and can be enabled in `kibana.yml` like this: `discover.experimental.enabledProfiles: [{YOUR_PROFILE_ID}]`. +5. Call and return the result of your provider factory function from the corresponding factory function in [`register_profile_providers.ts`](./profile_providers/register_profile_providers.ts), e.g. `createRootProfileProviders`. The order of providers in the returned array determines the execution order during context resolution. + +Existing providers can be extended using the [`extendProfileProvider`](./profile_providers/extend_profile_provider.ts) utility, allowing multiple sub profiles to be composed from a shared parent profile. + +Example profile provider implementations are located in [`profile_providers/example`](./profile_providers/example). + +## Example implementation + +```ts +/** + * profile_providers/common/example_data_source_profile/profile.tsx + */ + +import React from 'react'; +import { getFieldValue } from '@kbn/discover-utils'; +import { isOfAggregateQueryType } from '@kbn/es-query'; +import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils'; +import { DataSourceType, isDataSourceType } from '../../../../../common/data_sources'; +import { DataSourceCategory, DataSourceProfileProvider } from '../../../profiles'; +import { ProfileProviderServices } from '../../profile_provider_services'; + +// Export profile provider factory function, optionally accepting ProfileProviderServices, +// and returning a profile provider for a specific context level +export const createExampleDataSourceProfileProvider = ( + services: ProfileProviderServices +): DataSourceProfileProvider => ({ + // All profiles must have a unique ID + profileId: 'example-data-source-profile', + + // Set isExperimental flag to true if profile should be disabled by default + isExperimental: true, + + // The composable profile definition + profile: { + // Each available method maps to a Discover extension point + getCellRenderers: (prev) => () => ({ + // Calling prev() provides access to results from previous context levels, + // making it possible to compose a result from multiple profiles + ...prev(), + + // Extend the previous results with a cell renderer for the message field + message: (props) => { + const message = getFieldValue(props.row, 'message'); + return Custom message cell: {message}; + }, + }), + }, + + // The method responsible for context resolution, + // passed a params object with props specific to the context level, + // as well as providing access to higher level context objects + resolve: (params) => { + let indexPattern: string | undefined; + + // Extract the index pattern from the current ES|QL query or data view + if (isDataSourceType(params.dataSource, DataSourceType.Esql)) { + if (!isOfAggregateQueryType(params.query)) { + return { isMatch: false }; + } + + indexPattern = getIndexPatternFromESQLQuery(params.query.esql); + } else if (isDataSourceType(params.dataSource, DataSourceType.DataView) && params.dataView) { + indexPattern = params.dataView.getIndexPattern(); + } + + // If the profile is not a match, return isMatch: false in the result + if (indexPattern !== 'my-example-logs') { + return { isMatch: false }; + } + + // If the profile is a match, return isMatch: true in the result, + // plus a context object containing details of the current context + return { + isMatch: true, + context: { category: DataSourceCategory.Logs }, + }; + }, +}); + +/** + * profile_providers/register_profile_providers.ts + */ + +// Locate the factory function for the matching context level +const createDataSourceProfileProviders = (providerServices: ProfileProviderServices) => [ + // Call the profile provider factory function and return its result in the array + createExampleDataSourceProfileProvider(providerServices), + ...createLogsDataSourceProfileProviders(providerServices), +]; + +/** + * Navigate to Discover and execute the following ES|QL query + * to resolve the profile: `FROM my-example-logs` + */ +``` diff --git a/src/plugins/discover/public/context_awareness/composable_profile.ts b/src/plugins/discover/public/context_awareness/composable_profile.ts index f058d0949992d..84c8b6afca0b3 100644 --- a/src/plugins/discover/public/context_awareness/composable_profile.ts +++ b/src/plugins/discover/public/context_awareness/composable_profile.ts @@ -9,19 +9,36 @@ import type { Profile } from './types'; +/** + * A partial profile implementation + */ export type PartialProfile = Partial; +/** + * An accessor function that allows retrieving the extension point result from previous profiles + */ export type ComposableAccessor = (getPrevious: T) => T; +/** + * A partial profile implementation that supports composition across multiple profiles + */ export type ComposableProfile = { [TKey in keyof TProfile]?: ComposableAccessor; }; +/** + * Merges extension point implementations from multiple profiles into a single accessor function + * @param profiles The profiles to merge + * @param key The key of the extension point to merge + * @param baseImpl The base implementation for the extension point + * @returns The merged extension point accessor function + */ export const getMergedAccessor = ( profiles: ComposableProfile[], key: TKey, baseImpl: Profile[TKey] ) => { + // root, data source, and document profiles are merged in order return profiles.reduce((nextAccessor, profile) => { const currentAccessor = profile[key]; return currentAccessor ? currentAccessor(nextAccessor) : nextAccessor; diff --git a/src/plugins/discover/public/context_awareness/docs/architecture.png b/src/plugins/discover/public/context_awareness/docs/architecture.png new file mode 100644 index 0000000000000..082b5e9fb0154 Binary files /dev/null and b/src/plugins/discover/public/context_awareness/docs/architecture.png differ diff --git a/src/plugins/discover/public/context_awareness/docs/merged_accessors.png b/src/plugins/discover/public/context_awareness/docs/merged_accessors.png new file mode 100644 index 0000000000000..79d5b08610a4d Binary files /dev/null and b/src/plugins/discover/public/context_awareness/docs/merged_accessors.png differ diff --git a/src/plugins/discover/public/context_awareness/hooks/use_additional_cell_actions.ts b/src/plugins/discover/public/context_awareness/hooks/use_additional_cell_actions.ts index fbd87511e186b..e2f1a62cafdbb 100644 --- a/src/plugins/discover/public/context_awareness/hooks/use_additional_cell_actions.ts +++ b/src/plugins/discover/public/context_awareness/hooks/use_additional_cell_actions.ts @@ -23,6 +23,11 @@ import { useProfileAccessor } from './use_profile_accessor'; export const DISCOVER_CELL_ACTION_TYPE = 'discover-cellAction-type'; +/** + * Hook to register additional cell actions based on the resolved profiles + * @param options Additional cell action options + * @returns The current cell actions metadata + */ export const useAdditionalCellActions = ({ dataSource, dataView, diff --git a/src/plugins/discover/public/context_awareness/hooks/use_profile_accessor.ts b/src/plugins/discover/public/context_awareness/hooks/use_profile_accessor.ts index e09f5f54b05e5..e8fe6db600521 100644 --- a/src/plugins/discover/public/context_awareness/hooks/use_profile_accessor.ts +++ b/src/plugins/discover/public/context_awareness/hooks/use_profile_accessor.ts @@ -13,6 +13,12 @@ import type { GetProfilesOptions } from '../profiles_manager'; import { useProfiles } from './use_profiles'; import type { Profile } from '../types'; +/** + * Hook to retrieve an extension point accessor based on the resolved profiles + * @param key The key of the extension point + * @param options Options to get the resolved profiles + * @returns The resolved accessor function + */ export const useProfileAccessor = ( key: TKey, options: GetProfilesOptions = {} diff --git a/src/plugins/discover/public/context_awareness/hooks/use_profiles.ts b/src/plugins/discover/public/context_awareness/hooks/use_profiles.ts index e6b30d6267985..1b2d4fbd52f33 100644 --- a/src/plugins/discover/public/context_awareness/hooks/use_profiles.ts +++ b/src/plugins/discover/public/context_awareness/hooks/use_profiles.ts @@ -11,6 +11,11 @@ import { useEffect, useMemo, useState } from 'react'; import { useDiscoverServices } from '../../hooks/use_discover_services'; import type { GetProfilesOptions } from '../profiles_manager'; +/** + * Hook to retreive the resolved profiles + * @param options Profiles options + * @returns The resolved profiles + */ export const useProfiles = ({ record }: GetProfilesOptions = {}) => { const { profilesManager } = useDiscoverServices(); const [profiles, setProfiles] = useState(() => profilesManager.getProfiles({ record })); diff --git a/src/plugins/discover/public/context_awareness/hooks/use_root_profile.ts b/src/plugins/discover/public/context_awareness/hooks/use_root_profile.ts index b0d355fbba23a..2ffccc6d786b2 100644 --- a/src/plugins/discover/public/context_awareness/hooks/use_root_profile.ts +++ b/src/plugins/discover/public/context_awareness/hooks/use_root_profile.ts @@ -10,6 +10,11 @@ import { useEffect, useState } from 'react'; import { useDiscoverServices } from '../../hooks/use_discover_services'; +/** + * Hook to trigger and wait for root profile resolution + * @param options Options object + * @returns If the root profile is loading + */ export const useRootProfile = ({ solutionNavId }: { solutionNavId: string | null }) => { const { profilesManager } = useDiscoverServices(); const [rootProfileLoading, setRootProfileLoading] = useState(true); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/accessors/get_doc_viewer.tsx b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/accessors/get_doc_viewer.tsx similarity index 94% rename from src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/accessors/get_doc_viewer.tsx rename to src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/accessors/get_doc_viewer.tsx index dd851725bf748..1d433b5272d7b 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/accessors/get_doc_viewer.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/accessors/get_doc_viewer.tsx @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { UnifiedDocViewerLogsOverview } from '@kbn/unified-doc-viewer-plugin/public'; import React from 'react'; -import type { DocumentProfileProvider } from '../../../profiles'; +import type { DocumentProfileProvider } from '../../../../profiles'; export const getDocViewer: DocumentProfileProvider['profile']['getDocViewer'] = (prev) => (params) => { diff --git a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/accessors/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/accessors/index.ts similarity index 100% rename from src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/accessors/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/accessors/index.ts diff --git a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/index.ts similarity index 100% rename from src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/index.ts diff --git a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/profile.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/profile.test.ts similarity index 97% rename from src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/profile.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/profile.test.ts index b6432bca6e4c9..87c5ac137380e 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/profile.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/profile.test.ts @@ -15,8 +15,8 @@ import { DocumentType, RootContext, SolutionType, -} from '../../profiles'; -import { createContextAwarenessMocks } from '../../__mocks__'; +} from '../../../profiles'; +import { createContextAwarenessMocks } from '../../../__mocks__'; import { createLogDocumentProfileProvider } from './profile'; const mockServices = createContextAwarenessMocks().profileProviderServices; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/profile.tsx b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/profile.tsx similarity index 92% rename from src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/profile.tsx rename to src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/profile.tsx index 564aaf3a3410c..5ff4857b5bf75 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/log_document_profile/profile.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/log_document_profile/profile.tsx @@ -8,8 +8,8 @@ */ import { DataTableRecord } from '@kbn/discover-utils'; -import { DocumentProfileProvider, DocumentType } from '../../profiles'; -import { ProfileProviderServices } from '../profile_provider_services'; +import { DocumentProfileProvider, DocumentType } from '../../../profiles'; +import { ProfileProviderServices } from '../../profile_provider_services'; import { getDocViewer } from './accessors'; export const createLogDocumentProfileProvider = ( diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_cell_renderers.tsx b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx similarity index 75% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_cell_renderers.tsx rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx index 433e9cde27219..49950368300bf 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_cell_renderers.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_cell_renderers.tsx @@ -7,9 +7,9 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { LOG_LEVEL_FIELDS } from '../../../../../common/data_types/logs/constants'; -import { getLogLevelBadgeCell } from '../../../../components/data_types/logs/log_level_badge_cell'; -import type { DataSourceProfileProvider } from '../../../profiles'; +import { LOG_LEVEL_FIELDS } from '../../../../../../common/data_types/logs/constants'; +import { getLogLevelBadgeCell } from '../../../../../components/data_types/logs/log_level_badge_cell'; +import type { DataSourceProfileProvider } from '../../../../profiles'; export const getCellRenderers: DataSourceProfileProvider['profile']['getCellRenderers'] = (prev) => () => ({ diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_default_app_state.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_default_app_state.ts similarity index 88% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_default_app_state.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_default_app_state.ts index f14e962969544..d9c08af91f5d8 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_default_app_state.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_default_app_state.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { DataSourceProfileProvider } from '../../../profiles'; -import { DefaultAppStateColumn } from '../../../types'; +import type { DataSourceProfileProvider } from '../../../../profiles'; +import { DefaultAppStateColumn } from '../../../../types'; export const createGetDefaultAppState = ({ defaultColumns, diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_row_additional_leading_controls.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_row_additional_leading_controls.ts similarity index 94% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_row_additional_leading_controls.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_row_additional_leading_controls.ts index d91f1b4dc2b83..c13b474f05b70 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_row_additional_leading_controls.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_row_additional_leading_controls.ts @@ -10,7 +10,7 @@ import { createDegradedDocsControl, createStacktraceControl } from '@kbn/discover-utils'; import { retrieveMetadataColumns } from '@kbn/esql-utils'; import { AggregateQuery, isOfAggregateQueryType } from '@kbn/es-query'; -import type { DataSourceProfileProvider } from '../../../profiles'; +import type { DataSourceProfileProvider } from '../../../../profiles'; export const getRowAdditionalLeadingControls: DataSourceProfileProvider['profile']['getRowAdditionalLeadingControls'] = (prev) => (params) => { diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_row_indicator_provider.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_row_indicator_provider.ts similarity index 91% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_row_indicator_provider.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_row_indicator_provider.ts index 79dc6003c6453..2a76ebc59a27a 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/get_row_indicator_provider.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/get_row_indicator_provider.ts @@ -13,8 +13,8 @@ import { getLogLevelColor, } from '@kbn/discover-utils'; import type { UnifiedDataTableProps } from '@kbn/unified-data-table'; -import { LOG_LEVEL_FIELDS } from '../../../../../common/data_types/logs/constants'; -import type { DataSourceProfileProvider } from '../../../profiles'; +import { LOG_LEVEL_FIELDS } from '../../../../../../common/data_types/logs/constants'; +import type { DataSourceProfileProvider } from '../../../../profiles'; export const getRowIndicatorProvider: DataSourceProfileProvider['profile']['getRowIndicatorProvider'] = diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/index.ts similarity index 88% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/index.ts index 2de55b06e4a68..720a1add3c926 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/accessors/index.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/accessors/index.ts @@ -10,3 +10,4 @@ export { getRowIndicatorProvider } from './get_row_indicator_provider'; export { createGetDefaultAppState } from './get_default_app_state'; export { getCellRenderers } from './get_cell_renderers'; +export { getRowAdditionalLeadingControls } from './get_row_additional_leading_controls'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/consts.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/consts.ts similarity index 93% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/consts.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/consts.ts index 209b37059ab00..6020eaf6fae27 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/consts.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/consts.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { DefaultAppStateColumn } from '../../types'; +import type { DefaultAppStateColumn } from '../../../types'; export const LOG_LEVEL_COLUMN: DefaultAppStateColumn = { name: 'log.level', width: 150 }; export const MESSAGE_COLUMN: DefaultAppStateColumn = { name: 'message' }; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/create_profile_providers.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/create_profile_providers.ts similarity index 95% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/create_profile_providers.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/create_profile_providers.ts index 34991d7304164..57edf87e81150 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/create_profile_providers.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/create_profile_providers.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { ProfileProviderServices } from '../profile_provider_services'; +import type { ProfileProviderServices } from '../../profile_provider_services'; import { createLogsDataSourceProfileProvider } from './profile'; import { createApacheErrorLogsDataSourceProfileProvider, diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/index.ts similarity index 100% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/index.ts diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/profile.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/profile.test.ts similarity index 98% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/profile.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/profile.test.ts index e6ed227be8763..0240736000c66 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/profile.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/profile.test.ts @@ -10,9 +10,9 @@ import { buildDataTableRecord } from '@kbn/discover-utils'; import type { EuiThemeComputed } from '@elastic/eui'; import { createStubIndexPattern } from '@kbn/data-views-plugin/common/data_view.stub'; -import { createDataViewDataSource, createEsqlDataSource } from '../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../profiles'; -import { createContextAwarenessMocks } from '../../__mocks__'; +import { createDataViewDataSource, createEsqlDataSource } from '../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; +import { createContextAwarenessMocks } from '../../../__mocks__'; import { createLogsDataSourceProfileProvider } from './profile'; const mockServices = createContextAwarenessMocks().profileProviderServices; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/profile.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/profile.ts similarity index 75% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/profile.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/profile.ts index f4f0f06e37ad0..7b9d5ef3e5961 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/profile.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/profile.ts @@ -7,12 +7,14 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceCategory, DataSourceProfileProvider } from '../../profiles'; -import { ProfileProviderServices } from '../profile_provider_services'; -import { getRowIndicatorProvider } from './accessors'; -import { extractIndexPatternFrom } from '../extract_index_pattern_from'; -import { getCellRenderers } from './accessors'; -import { getRowAdditionalLeadingControls } from './accessors/get_row_additional_leading_controls'; +import { DataSourceCategory, DataSourceProfileProvider } from '../../../profiles'; +import { ProfileProviderServices } from '../../profile_provider_services'; +import { + getCellRenderers, + getRowIndicatorProvider, + getRowAdditionalLeadingControls, +} from './accessors'; +import { extractIndexPatternFrom } from '../../extract_index_pattern_from'; export const createLogsDataSourceProfileProvider = ( services: ProfileProviderServices diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/apache_error_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/apache_error_logs.test.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/apache_error_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/apache_error_logs.test.ts index 1674cab3fff19..9b3e64e520be3 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/apache_error_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/apache_error_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createApacheErrorLogsDataSourceProfileProvider } from './apache_error_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/apache_error_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/apache_error_logs.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/apache_error_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/apache_error_logs.ts index f83e3169fee6d..15e8dbc0cc991 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/apache_error_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/apache_error_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { CLIENT_IP_COLUMN, LOG_LEVEL_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/aws_s3access_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/aws_s3access_logs.test.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/aws_s3access_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/aws_s3access_logs.test.ts index 8897124433c14..fc97e67b1bee7 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/aws_s3access_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/aws_s3access_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createAwsS3accessLogsDataSourceProfileProvider } from './aws_s3access_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/aws_s3access_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/aws_s3access_logs.ts similarity index 90% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/aws_s3access_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/aws_s3access_logs.ts index 4e226cb44ec81..e068c2de16173 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/aws_s3access_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/aws_s3access_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { CLIENT_IP_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/create_resolve.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/create_resolve.ts similarity index 91% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/create_resolve.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/create_resolve.ts index aede1907f2975..75598e0d96c74 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/create_resolve.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/create_resolve.ts @@ -8,8 +8,8 @@ */ import { createRegExpPatternFrom, testPatternAgainstAllowedList } from '@kbn/data-view-utils'; -import { DataSourceCategory, DataSourceProfileProvider } from '../../../profiles'; -import { extractIndexPatternFrom } from '../../extract_index_pattern_from'; +import { DataSourceCategory, DataSourceProfileProvider } from '../../../../profiles'; +import { extractIndexPatternFrom } from '../../../extract_index_pattern_from'; export const createResolve = (baseIndexPattern: string): DataSourceProfileProvider['resolve'] => { const testIndexPattern = testPatternAgainstAllowedList([ diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/index.ts similarity index 100% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/index.ts diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/kubernetes_container_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/kubernetes_container_logs.test.ts similarity index 90% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/kubernetes_container_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/kubernetes_container_logs.test.ts index 954e724e8f739..301ef9ca52a86 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/kubernetes_container_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/kubernetes_container_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createKubernetesContainerLogsDataSourceProfileProvider } from './kubernetes_container_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/kubernetes_container_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/kubernetes_container_logs.ts similarity index 90% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/kubernetes_container_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/kubernetes_container_logs.ts index 6b5da24992b98..3f6540ace614d 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/kubernetes_container_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/kubernetes_container_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { LOG_LEVEL_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_access_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_access_logs.test.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_access_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_access_logs.test.ts index 172371418b95f..0265c17152177 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_access_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_access_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createNginxAccessLogsDataSourceProfileProvider } from './nginx_access_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_access_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_access_logs.ts similarity index 90% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_access_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_access_logs.ts index ffd98f31c453f..8d7af45d6b24c 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_access_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_access_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { CLIENT_IP_COLUMN, HOST_NAME_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_error_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_error_logs.test.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_error_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_error_logs.test.ts index 7908c5e680ce5..7ce8e49337a51 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_error_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_error_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createNginxErrorLogsDataSourceProfileProvider } from './nginx_error_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_error_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_error_logs.ts similarity index 88% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_error_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_error_logs.ts index 71a2b395b7478..b6a05cce4ecb7 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/nginx_error_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/nginx_error_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { LOG_LEVEL_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/system_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/system_logs.test.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/system_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/system_logs.test.ts index 4c3a1e93edf80..760546b89bc51 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/system_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/system_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createSystemLogsDataSourceProfileProvider } from './system_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/system_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/system_logs.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/system_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/system_logs.ts index 46fffa6879bfb..023cb578221fb 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/system_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/system_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { HOST_NAME_COLUMN, LOG_LEVEL_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/windows_logs.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/windows_logs.test.ts similarity index 89% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/windows_logs.test.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/windows_logs.test.ts index c132620b8743d..ce144b9167646 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/windows_logs.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/windows_logs.test.ts @@ -7,10 +7,10 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { dataViewWithTimefieldMock } from '../../../../__mocks__/data_view_with_timefield'; -import { createEsqlDataSource } from '../../../../../common/data_sources'; -import { DataSourceCategory, RootContext, SolutionType } from '../../../profiles'; -import { createContextAwarenessMocks } from '../../../__mocks__'; +import { dataViewWithTimefieldMock } from '../../../../../__mocks__/data_view_with_timefield'; +import { createEsqlDataSource } from '../../../../../../common/data_sources'; +import { DataSourceCategory, RootContext, SolutionType } from '../../../../profiles'; +import { createContextAwarenessMocks } from '../../../../__mocks__'; import { createLogsDataSourceProfileProvider } from '../profile'; import { createWindowsLogsDataSourceProfileProvider } from './windows_logs'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/windows_logs.ts b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/windows_logs.ts similarity index 88% rename from src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/windows_logs.ts rename to src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/windows_logs.ts index c54c56eabbfd8..084233783341e 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/logs_data_source_profile/sub_profiles/windows_logs.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/common/logs_data_source_profile/sub_profiles/windows_logs.ts @@ -7,8 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DataSourceProfileProvider } from '../../../profiles'; -import { extendProfileProvider } from '../../extend_profile_provider'; +import { DataSourceProfileProvider } from '../../../../profiles'; +import { extendProfileProvider } from '../../../extend_profile_provider'; import { createGetDefaultAppState } from '../accessors'; import { HOST_NAME_COLUMN, LOG_LEVEL_COLUMN, MESSAGE_COLUMN } from '../consts'; import { createResolve } from './create_resolve'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example_document_profile/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/example/example_data_source_profile/index.ts similarity index 87% rename from src/plugins/discover/public/context_awareness/profile_providers/example_document_profile/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/example/example_data_source_profile/index.ts index 295596a621393..03d5412fb6692 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/example_document_profile/index.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_data_source_profile/index.ts @@ -7,4 +7,4 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -export { exampleDocumentProfileProvider } from './profile'; +export { createExampleDataSourceProfileProvider } from './profile'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example_data_source_profile/profile.tsx b/src/plugins/discover/public/context_awareness/profile_providers/example/example_data_source_profile/profile.tsx similarity index 96% rename from src/plugins/discover/public/context_awareness/profile_providers/example_data_source_profile/profile.tsx rename to src/plugins/discover/public/context_awareness/profile_providers/example/example_data_source_profile/profile.tsx index f27412930b28d..ae1d29170c852 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/example_data_source_profile/profile.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_data_source_profile/profile.tsx @@ -14,10 +14,10 @@ import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils'; import { euiThemeVars } from '@kbn/ui-theme'; import { capitalize } from 'lodash'; import React from 'react'; -import { DataSourceType, isDataSourceType } from '../../../../common/data_sources'; -import { DataSourceCategory, DataSourceProfileProvider } from '../../profiles'; +import { DataSourceType, isDataSourceType } from '../../../../../common/data_sources'; +import { DataSourceCategory, DataSourceProfileProvider } from '../../../profiles'; -export const exampleDataSourceProfileProvider: DataSourceProfileProvider = { +export const createExampleDataSourceProfileProvider = (): DataSourceProfileProvider => ({ profileId: 'example-data-source-profile', isExperimental: true, profile: { @@ -159,4 +159,4 @@ export const exampleDataSourceProfileProvider: DataSourceProfileProvider = { context: { category: DataSourceCategory.Logs }, }; }, -}; +}); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/example/example_document_profile/index.ts similarity index 87% rename from src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/example/example_document_profile/index.ts index 094b6c4509d46..cd27c9abe55f7 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/index.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_document_profile/index.ts @@ -7,4 +7,4 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -export { exampleRootProfileProvider } from './profile'; +export { createExampleDocumentProfileProvider } from './profile'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example_document_profile/profile.ts b/src/plugins/discover/public/context_awareness/profile_providers/example/example_document_profile/profile.ts similarity index 83% rename from src/plugins/discover/public/context_awareness/profile_providers/example_document_profile/profile.ts rename to src/plugins/discover/public/context_awareness/profile_providers/example/example_document_profile/profile.ts index 848b9e4af0cdd..949eb0400c5d8 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/example_document_profile/profile.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_document_profile/profile.ts @@ -8,9 +8,9 @@ */ import { getFieldValue } from '@kbn/discover-utils'; -import { DocumentProfileProvider, DocumentType } from '../../profiles'; +import { DocumentProfileProvider, DocumentType } from '../../../profiles'; -export const exampleDocumentProfileProvider: DocumentProfileProvider = { +export const createExampleDocumentProfileProvider = (): DocumentProfileProvider => ({ profileId: 'example-document-profile', isExperimental: true, profile: {}, @@ -26,4 +26,4 @@ export const exampleDocumentProfileProvider: DocumentProfileProvider = { }, }; }, -}; +}); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example_data_source_profile/index.ts b/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/index.ts similarity index 88% rename from src/plugins/discover/public/context_awareness/profile_providers/example_data_source_profile/index.ts rename to src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/index.ts index 9c60e7f55d0d4..0c13a49d17d7a 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/example_data_source_profile/index.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/index.ts @@ -7,4 +7,4 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -export { exampleDataSourceProfileProvider } from './profile'; +export { createExampleRootProfileProvider } from './profile'; diff --git a/src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/profile.tsx b/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx similarity index 76% rename from src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/profile.tsx rename to src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx index f6f5e298974b2..ad247eacee666 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/example_root_pofile/profile.tsx +++ b/src/plugins/discover/public/context_awareness/profile_providers/example/example_root_pofile/profile.tsx @@ -8,11 +8,11 @@ */ import { EuiBadge } from '@elastic/eui'; -import type { DataTableRecord } from '@kbn/discover-utils'; +import { getFieldValue } from '@kbn/discover-utils'; import React from 'react'; -import { RootProfileProvider, SolutionType } from '../../profiles'; +import { RootProfileProvider, SolutionType } from '../../../profiles'; -export const exampleRootProfileProvider: RootProfileProvider = { +export const createExampleRootProfileProvider = (): RootProfileProvider => ({ profileId: 'example-root-profile', isExperimental: true, profile: { @@ -36,9 +36,4 @@ export const exampleRootProfileProvider: RootProfileProvider = { return { isMatch: true, context: { solutionType: SolutionType.Default } }; }, -}; - -const getFieldValue = (record: DataTableRecord, field: string) => { - const value = record.flattened[field]; - return Array.isArray(value) ? value[0] : value; -}; +}); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/extend_profile_provider.ts b/src/plugins/discover/public/context_awareness/profile_providers/extend_profile_provider.ts index 3abae6899d03e..9382101464ec7 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/extend_profile_provider.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/extend_profile_provider.ts @@ -9,6 +9,12 @@ import type { BaseProfileProvider } from '../profile_service'; +/** + * Extends a base profile provider with additional properties and profile methods + * @param baseProvider The base profile provider + * @param extension The extension to apply to the base profile provider + * @returns The extended profile provider + */ export const extendProfileProvider = >( baseProvider: TProvider, extension: Partial & Pick diff --git a/src/plugins/discover/public/context_awareness/profile_providers/extract_index_pattern_from.ts b/src/plugins/discover/public/context_awareness/profile_providers/extract_index_pattern_from.ts index c40895dcea8b6..aa754a228569b 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/extract_index_pattern_from.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/extract_index_pattern_from.ts @@ -12,6 +12,11 @@ import { getIndexPatternFromESQLQuery } from '@kbn/esql-utils'; import { isDataViewSource, isEsqlSource } from '../../../common/data_sources'; import type { DataSourceProfileProviderParams } from '../profiles'; +/** + * Extracts the index pattern from the given ES|QL query or data view + * @param options Options object + * @returns The extracted index pattern or null + */ export const extractIndexPatternFrom = ({ dataSource, dataView, diff --git a/src/plugins/discover/public/context_awareness/profile_providers/profile_provider_services.ts b/src/plugins/discover/public/context_awareness/profile_providers/profile_provider_services.ts index d4929337b16a0..7abca8d6d8520 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/profile_provider_services.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/profile_provider_services.ts @@ -9,16 +9,30 @@ import { createLogsContextService, LogsContextService } from '@kbn/discover-utils'; +/** + * Dependencies required by profile provider implementations + */ // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface ProfileProviderDeps { // We will probably soon add uiSettings as a dependency // to consume user configured indices } +/** + * Services provided to profile provider implementations + */ export interface ProfileProviderServices { + /** + * A service containing methods used for logs profiles + */ logsContextService: LogsContextService; } +/** + * Creates the profile provider services + * @param _deps Profile provider dependencies + * @returns Profile provider services + */ export const createProfileProviderServices = ( _deps: ProfileProviderDeps = {} ): ProfileProviderServices => { diff --git a/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.test.ts b/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.test.ts index 0b3ce53c53c86..6b0c22a3d0d08 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.test.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.test.ts @@ -9,14 +9,19 @@ import { createEsqlDataSource } from '../../../common/data_sources'; import { createContextAwarenessMocks } from '../__mocks__'; -import { exampleDataSourceProfileProvider } from './example_data_source_profile'; -import { exampleDocumentProfileProvider } from './example_document_profile'; -import { exampleRootProfileProvider } from './example_root_pofile'; +import { createExampleRootProfileProvider } from './example/example_root_pofile'; +import { createExampleDataSourceProfileProvider } from './example/example_data_source_profile/profile'; +import { createExampleDocumentProfileProvider } from './example/example_document_profile'; + import { registerProfileProviders, registerEnabledProfileProviders, } from './register_profile_providers'; +const exampleRootProfileProvider = createExampleRootProfileProvider(); +const exampleDataSourceProfileProvider = createExampleDataSourceProfileProvider(); +const exampleDocumentProfileProvider = createExampleDocumentProfileProvider(); + describe('registerEnabledProfileProviders', () => { it('should register all profile providers', async () => { const { rootProfileServiceMock, rootProfileProviderMock } = createContextAwarenessMocks({ @@ -93,13 +98,9 @@ describe('registerProfileProviders', () => { raw: {}, }, }); - expect(rootProfileServiceMock.getProfile(rootContext)).toBe(exampleRootProfileProvider.profile); - expect(dataSourceProfileServiceMock.getProfile(dataSourceContext)).toBe( - exampleDataSourceProfileProvider.profile - ); - expect(documentProfileServiceMock.getProfile(documentContext)).toBe( - exampleDocumentProfileProvider.profile - ); + expect(rootContext.profileId).toBe(exampleRootProfileProvider.profileId); + expect(dataSourceContext.profileId).toBe(exampleDataSourceProfileProvider.profileId); + expect(documentContext.profileId).toBe(exampleDocumentProfileProvider.profileId); }); it('should not register disabled experimental profile providers', async () => { @@ -128,14 +129,8 @@ describe('registerProfileProviders', () => { raw: {}, }, }); - expect(rootProfileServiceMock.getProfile(rootContext)).not.toBe( - exampleRootProfileProvider.profile - ); - expect(dataSourceProfileServiceMock.getProfile(dataSourceContext)).not.toBe( - exampleDataSourceProfileProvider.profile - ); - expect(documentProfileServiceMock.getProfile(documentContext)).not.toBe( - exampleDocumentProfileProvider.profile - ); + expect(rootContext.profileId).not.toBe(exampleRootProfileProvider.profileId); + expect(dataSourceContext.profileId).not.toBe(exampleDataSourceProfileProvider.profileId); + expect(documentContext.profileId).not.toBe(exampleDocumentProfileProvider.profileId); }); }); diff --git a/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts b/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts index 3035bb3e507ab..9cd65320ac140 100644 --- a/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts +++ b/src/plugins/discover/public/context_awareness/profile_providers/register_profile_providers.ts @@ -13,29 +13,42 @@ import type { RootProfileService, } from '../profiles'; import type { BaseProfileProvider, BaseProfileService } from '../profile_service'; -import { exampleDataSourceProfileProvider } from './example_data_source_profile'; -import { exampleDocumentProfileProvider } from './example_document_profile'; -import { exampleRootProfileProvider } from './example_root_pofile'; -import { createLogsDataSourceProfileProviders } from './logs_data_source_profile'; -import { createLogDocumentProfileProvider } from './log_document_profile'; +import { createExampleDataSourceProfileProvider } from './example/example_data_source_profile/profile'; +import { createExampleDocumentProfileProvider } from './example/example_document_profile'; +import { createExampleRootProfileProvider } from './example/example_root_pofile'; +import { createLogsDataSourceProfileProviders } from './common/logs_data_source_profile'; +import { createLogDocumentProfileProvider } from './common/log_document_profile'; import { createSecurityRootProfileProvider } from './security/security_root_profile'; import { createProfileProviderServices, ProfileProviderServices, } from './profile_provider_services'; +/** + * Register profile providers for root, data source, and document contexts to the profile profile services + * @param options Register profile provider options + */ export const registerProfileProviders = ({ rootProfileService, dataSourceProfileService, documentProfileService, enabledExperimentalProfileIds, }: { + /** + * Root profile service + */ rootProfileService: RootProfileService; + /** + * Data source profile service + */ dataSourceProfileService: DataSourceProfileService; + /** + * Document profile service + */ documentProfileService: DocumentProfileService; /** - * List of experimental profile Ids which are enabled in kibana config. - * */ + * Array of experimental profile IDs which are enabled in `kibana.yml` + */ enabledExperimentalProfileIds: string[]; }) => { const providerServices = createProfileProviderServices(); @@ -45,23 +58,27 @@ export const registerProfileProviders = ({ registerEnabledProfileProviders({ profileService: rootProfileService, - providers: [...rootProfileProviders], + providers: rootProfileProviders, enabledExperimentalProfileIds, }); registerEnabledProfileProviders({ profileService: dataSourceProfileService, - providers: [...dataSourceProfileProviders], + providers: dataSourceProfileProviders, enabledExperimentalProfileIds, }); registerEnabledProfileProviders({ profileService: documentProfileService, - providers: [...documentProfileProviders], + providers: documentProfileProviders, enabledExperimentalProfileIds, }); }; +/** + * Register enabled profile providers to the provided profile service + * @param options Register enabled profile providers options + */ export const registerEnabledProfileProviders = < TProvider extends BaseProfileProvider<{}>, TService extends BaseProfileService @@ -70,34 +87,52 @@ export const registerEnabledProfileProviders = < providers: availableProviders, enabledExperimentalProfileIds = [], }: { + /** + * Profile service to register providers + */ profileService: TService; + /** + * Array of available profile providers + */ providers: TProvider[]; /** - * List of experimental profile Ids which are enabled in kibana config. - * */ + * Array of experimental profile IDs which are enabled in `kibana.yml` + */ enabledExperimentalProfileIds?: string[]; }) => { for (const provider of availableProviders) { - const isProfileExperimental = provider.isExperimental ?? false; - const isProfileEnabled = - enabledExperimentalProfileIds.includes(provider.profileId) || !isProfileExperimental; - if (isProfileEnabled) { + if (!provider.isExperimental || enabledExperimentalProfileIds.includes(provider.profileId)) { profileService.registerProvider(provider); } } }; -const createRootProfileProviders = (_providerServices: ProfileProviderServices) => [ - exampleRootProfileProvider, - createSecurityRootProfileProvider(_providerServices), +/** + * Creates the available root profile providers + * @param providerServices The profile provider services + * @returns An array of available root profile providers + */ +const createRootProfileProviders = (providerServices: ProfileProviderServices) => [ + createExampleRootProfileProvider(), + createSecurityRootProfileProvider(providerServices), ]; +/** + * Creates the available data source profile providers + * @param providerServices The profile provider services + * @returns An array of available data source profile providers + */ const createDataSourceProfileProviders = (providerServices: ProfileProviderServices) => [ - exampleDataSourceProfileProvider, + createExampleDataSourceProfileProvider(), ...createLogsDataSourceProfileProviders(providerServices), ]; +/** + * Creates the available document profile providers + * @param providerServices The profile provider services + * @returns An array of available document profile providers + */ const createDocumentProfileProviders = (providerServices: ProfileProviderServices) => [ - exampleDocumentProfileProvider, + createExampleDocumentProfileProvider(), createLogDocumentProfileProvider(providerServices), ]; diff --git a/src/plugins/discover/public/context_awareness/profile_service.ts b/src/plugins/discover/public/context_awareness/profile_service.ts index d16f8a13be709..aaeb7664aa5cd 100644 --- a/src/plugins/discover/public/context_awareness/profile_service.ts +++ b/src/plugins/discover/public/context_awareness/profile_service.ts @@ -12,19 +12,48 @@ import type { ComposableProfile, PartialProfile } from './composable_profile'; import type { Profile } from './types'; +/** + * The profile provider resolution result + */ export type ResolveProfileResult = - | { isMatch: true; context: TContext } - | { isMatch: false }; - + | { + /** + * `true` if the associated profile is a match + */ + isMatch: true; + /** + * The resolved context associated with the profile + */ + context: TContext; + } + | { + /** + * `false` if the associated profile is not a match + */ + isMatch: false; + }; + +/** + * Context object with an injected profile ID + */ export type ContextWithProfileId = TContext & { profileId: string }; +/** + * The base profile provider interface + */ export interface BaseProfileProvider { + /** + * The unique profile ID + */ profileId: string; + /** + * The composable profile implementation + */ profile: ComposableProfile; /** - * isExperimental Flag can be used for any profile which is under development and should not be enabled by default. + * Set the `isExperimental` flag to `true` for any profile which is under development and should not be enabled by default. * - * Experimental profiles can still be enabled in kibana config with option `discover.experimental.enabledProfiles` as shown in example below: + * Experimental profiles can be enabled in `kibana.yml` using `discover.experimental.enabledProfiles`, for example: * * ```yaml * discover.experimental.enabledProfiles: @@ -35,13 +64,29 @@ export interface BaseProfileProvider { isExperimental?: boolean; } +/** + * A synchronous profile provider interface + */ export interface ProfileProvider extends BaseProfileProvider { + /** + * The method responsible for context resolution and determining if the associated profile is a match + * @param params Parameters specific to the provider context level + * @returns The resolve profile result + */ resolve: (params: TParams) => ResolveProfileResult; } +/** + * An asynchronous profile provider interface + */ export interface AsyncProfileProvider extends BaseProfileProvider { + /** + * The method responsible for context resolution and determining if the associated profile is a match + * @param params Parameters specific to the provider context level + * @returns The resolve profile result + */ resolve: ( params: TParams ) => ResolveProfileResult | Promise>; @@ -49,26 +94,50 @@ export interface AsyncProfileProvider, TContext> { protected readonly providers: TProvider[] = []; + /** + * @param defaultContext The default context object to use when no profile provider matches + */ protected constructor(public readonly defaultContext: ContextWithProfileId) {} + /** + * Registers a profile provider + * @param provider The profile provider to register + */ public registerProvider(provider: TProvider) { this.providers.push(provider); } + /** + * Returns the composable profile associated with the provided context object + * @param context A context object returned by a provider's `resolve` method + * @returns The composable profile associated with the context + */ public getProfile(context: ContextWithProfileId): ComposableProfile { const provider = this.providers.find((current) => current.profileId === context.profileId); return provider?.profile ?? EMPTY_PROFILE; } } +/** + * A synchronous profile service implementation + */ export class ProfileService< TProfile extends PartialProfile, TParams, TContext > extends BaseProfileService, TContext> { + /** + * Performs context resolution based on the provided context level parameters, + * returning the resolved context from the first matching profile provider + * @param params Parameters specific to the service context level + * @returns The resolved context object with an injected profile ID + */ public resolve(params: TParams) { for (const provider of this.providers) { const result = provider.resolve(params); @@ -85,11 +154,20 @@ export class ProfileService< } } +/** + * An asynchronous profile service implementation + */ export class AsyncProfileService< TProfile extends PartialProfile, TParams, TContext > extends BaseProfileService, TContext> { + /** + * Performs context resolution based on the provided context level parameters, + * returning the resolved context from the first matching profile provider + * @param params Parameters specific to the service context level + * @returns The resolved context object with an injected profile ID + */ public async resolve(params: TParams) { for (const provider of this.providers) { const result = await provider.resolve(params); diff --git a/src/plugins/discover/public/context_awareness/profiles/data_source_profile.ts b/src/plugins/discover/public/context_awareness/profiles/data_source_profile.ts index 96ef82071edea..807072d777a93 100644 --- a/src/plugins/discover/public/context_awareness/profiles/data_source_profile.ts +++ b/src/plugins/discover/public/context_awareness/profiles/data_source_profile.ts @@ -14,21 +14,48 @@ import { AsyncProfileProvider, AsyncProfileService } from '../profile_service'; import type { Profile } from '../types'; import type { RootContext } from './root_profile'; +/** + * Indicates the category of the data source (e.g. logs, alerts, etc.) + */ export enum DataSourceCategory { Logs = 'logs', Default = 'default', } +/** + * The data source profile interface + */ export type DataSourceProfile = Profile; +/** + * Parameters for the data source profile provider `resolve` method + */ export interface DataSourceProfileProviderParams { + /** + * The current root context + */ rootContext: RootContext; + /** + * The current data source + */ dataSource?: DiscoverDataSource; + /** + * The current data view + */ dataView?: DataView; + /** + * The current query + */ query?: Query | AggregateQuery; } +/** + * The resulting context object returned by the data source profile provider `resolve` method + */ export interface DataSourceContext { + /** + * The category of the current data source + */ category: DataSourceCategory; } diff --git a/src/plugins/discover/public/context_awareness/profiles/document_profile.ts b/src/plugins/discover/public/context_awareness/profiles/document_profile.ts index dde4acfecaf1b..cd14e9cdec010 100644 --- a/src/plugins/discover/public/context_awareness/profiles/document_profile.ts +++ b/src/plugins/discover/public/context_awareness/profiles/document_profile.ts @@ -13,20 +13,44 @@ import { ProfileProvider, ProfileService } from '../profile_service'; import type { RootContext } from './root_profile'; import type { DataSourceContext } from './data_source_profile'; +/** + * Indicates the current document type (e.g. log, alert, etc.) + */ export enum DocumentType { Log = 'log', Default = 'default', } +/** + * The document profile interface + */ export type DocumentProfile = Pick; +/** + * Parameters for the document profile provider `resolve` method + */ export interface DocumentProfileProviderParams { + /** + * The current root context + */ rootContext: RootContext; + /** + * The current data source context + */ dataSourceContext: DataSourceContext; + /** + * The current data table record + */ record: DataTableRecord; } +/** + * The resulting context object returned by the document profile provider `resolve` method + */ export interface DocumentContext { + /** + * The current document type + */ type: DocumentType; } diff --git a/src/plugins/discover/public/context_awareness/profiles/root_profile.ts b/src/plugins/discover/public/context_awareness/profiles/root_profile.ts index 3936dafdbcb49..853c93c05cf64 100644 --- a/src/plugins/discover/public/context_awareness/profiles/root_profile.ts +++ b/src/plugins/discover/public/context_awareness/profiles/root_profile.ts @@ -10,6 +10,9 @@ import type { Profile } from '../types'; import { AsyncProfileProvider, AsyncProfileService } from '../profile_service'; +/** + * Indicates the current solution type (i.e. Observability, Security, Search) + */ export enum SolutionType { Observability = 'oblt', Security = 'security', @@ -17,13 +20,28 @@ export enum SolutionType { Default = 'default', } +/** + * The root profile interface + */ export type RootProfile = Profile; +/** + * Parameters for the root profile provider `resolve` method + */ export interface RootProfileProviderParams { + /** + * The current solution navigation ID ('oblt', 'security', 'search', or null) + */ solutionNavId?: string | null; } +/** + * The resulting context object returned by the root profile provider `resolve` method + */ export interface RootContext { + /** + * The current solution type + */ solutionType: SolutionType; } diff --git a/src/plugins/discover/public/context_awareness/profiles_manager.ts b/src/plugins/discover/public/context_awareness/profiles_manager.ts index 27b77345ee0d3..8c24e425147f5 100644 --- a/src/plugins/discover/public/context_awareness/profiles_manager.ts +++ b/src/plugins/discover/public/context_awareness/profiles_manager.ts @@ -39,7 +39,13 @@ interface DataTableRecordWithContext extends DataTableRecord { context: ContextWithProfileId; } +/** + * Options for the `getProfiles` method + */ export interface GetProfilesOptions { + /** + * The data table record to use for the document profile + */ record?: DataTableRecord; } @@ -61,6 +67,10 @@ export class ProfilesManager { this.dataSourceContext$ = new BehaviorSubject(dataSourceProfileService.defaultContext); } + /** + * Resolves the root context profile + * @param params The root profile provider parameters + */ public async resolveRootProfile(params: RootProfileProviderParams) { const serializedParams = serializeRootProfileParams(params); @@ -88,6 +98,10 @@ export class ProfilesManager { this.prevRootProfileParams = serializedParams; } + /** + * Resolves the data source context profile + * @param params The data source profile provider parameters + */ public async resolveDataSourceProfile( params: Omit ) { @@ -120,6 +134,11 @@ export class ProfilesManager { this.prevDataSourceProfileParams = serializedParams; } + /** + * Resolves the document context profile for a given data table record + * @param params The document profile provider parameters + * @returns The data table record with a resolved document context + */ public resolveDocumentProfile( params: Omit ) { @@ -150,6 +169,11 @@ export class ProfilesManager { }); } + /** + * Retrieves an array of the resolved profiles + * @param options Options for getting the profiles + * @returns The resolved profiles + */ public getProfiles({ record }: GetProfilesOptions = {}) { return [ this.rootProfileService.getProfile(this.rootContext$.getValue()), @@ -160,6 +184,11 @@ export class ProfilesManager { ]; } + /** + * Retrieves an observable of the resolved profiles that emits when the profiles change + * @param options Options for getting the profiles + * @returns The resolved profiles as an observable + */ public getProfiles$(options: GetProfilesOptions = {}) { return combineLatest([this.rootContext$, this.dataSourceContext$]).pipe( map(() => this.getProfiles(options)) diff --git a/src/plugins/discover/public/context_awareness/types.ts b/src/plugins/discover/public/context_awareness/types.ts index 03d2ac1f945e7..dacc2edbc218d 100644 --- a/src/plugins/discover/public/context_awareness/types.ts +++ b/src/plugins/discover/public/context_awareness/types.ts @@ -17,48 +17,131 @@ import type { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query'; import type { OmitIndexSignature } from 'type-fest'; import type { Trigger } from '@kbn/ui-actions-plugin/public'; import type { DiscoverDataSource } from '../../common/data_sources'; -import { DiscoverAppState } from '../application/main/state_management/discover_app_state_container'; +import type { DiscoverAppState } from '../application/main/state_management/discover_app_state_container'; +/** + * Supports customizing the Discover document viewer flyout + */ export interface DocViewerExtension { + /** + * Title displayed in the flyout header + */ title: string | undefined; + /** + * Supports modifying existing tabs or adding new tabs to the flyout + * @param prevRegistry The doc views registry + * @returns The updated doc views registry + */ docViewsRegistry: (prevRegistry: DocViewsRegistry) => DocViewsRegistry; } +/** + * Parameters passed to the doc viewer extension + */ export interface DocViewerExtensionParams { + /** + * The record being displayed in the doc viewer + */ record: DataTableRecord; } +/** + * Parameters passed to the row indicator extension + */ export interface RowIndicatorExtensionParams { + /** + * The current data view + */ dataView: DataView; } +/** + * Default data grid column configuration + */ export interface DefaultAppStateColumn { + /** + * The field name of the column + */ name: string; + /** + * The width of the column in pixels -- leave undefined for auto width + */ width?: number; } +/** + * Parameters passed to the default app state extension + */ export interface DefaultAppStateExtensionParams { + /** + * The current data view + */ dataView: DataView; } +/** + * Supports customizing the default Discover application state + */ export interface DefaultAppStateExtension { + /** + * The columns to display in the data grid + */ columns?: DefaultAppStateColumn[]; + /** + * The height of each row in the data grid: + * * -1: auto height mode + * * 0: single line mode + * * 1-20: number of lines to display + */ rowHeight?: number; } +/** + * Parameters passed to the row controls extension + */ export interface RowControlsExtensionParams { + /** + * The current data view + */ dataView: DataView; + /** + * The current query + */ query?: DiscoverAppState['query']; } +/** + * The Discover cell actions trigger + */ export const DISCOVER_CELL_ACTIONS_TRIGGER: Trigger = { id: 'DISCOVER_CELL_ACTIONS_TRIGGER_ID' }; +/** + * Metadata passed to Discover cell actions + */ export interface DiscoverCellActionMetadata extends Record { + /** + * The Discover instance ID (distinct for each dashboard panel) + */ instanceId?: string; + /** + * The current data source (ES|QL or data view) + */ dataSource?: DiscoverDataSource; + /** + * The current data view + */ dataView?: DataView; + /** + * The current query + */ query?: Query | AggregateQuery; + /** + * The current filters + */ filters?: Filter[]; + /** + * The current time range + */ timeRange?: TimeRange; } @@ -68,30 +151,107 @@ export interface DiscoverCellActionExecutionContext extends CellActionExecutionC export type DiscoverCellAction = CellAction; +/** + * Context object passed to additional cell action methods + */ export type AdditionalCellActionContext = CellActionsData & Omit, 'instanceId'>; +/** + * Additional action to show within expanded cell popovers in the data grid + */ export interface AdditionalCellAction { + /** + * Unique ID for the action + */ id: string; + /** + * Gets the display name for the action, used for button text + * @param context Current cell action context + * @returns The action display name + */ getDisplayName: (context: AdditionalCellActionContext) => string; + /** + * Gets the icon type for the action, used for button icon + * @param context Current cell action context + * @returns The action icon type + */ getIconType: (context: AdditionalCellActionContext) => EuiIconType; + /** + * Checks if the action is compatible with the current cell + * @param context The current cell action context + * @returns `true` if the action is compatible, `false` otherwise + */ isCompatible?: ( context: Omit ) => boolean | Promise; + /** + * The action to execute when the button is clicked + * @param context The current cell action context + */ execute: (context: AdditionalCellActionContext) => void | Promise; } +/** + * The core profile interface for Discover context awareness. + * Each of the available methods map to a specific extension point in the Discover application. + */ export interface Profile { + /** + * Lifecycle + */ + + /** + * Gets default Discover app state that should be used when the profile is resolved + * @param params The default app state extension parameters + * @returns The default app state + */ getDefaultAppState: (params: DefaultAppStateExtensionParams) => DefaultAppStateExtension; - // Data grid + + /** + * Data grid + */ + + /** + * Gets a map of column names to custom cell renderers to use in the data grid + * @returns The custom cell renderers to use in the data grid + */ getCellRenderers: () => CustomCellRenderer; + + /** + * Gets a row indicator provider, allowing rows in the data grid to be given coloured highlights + * based on the properties of each result (e.g. highlighting logs based on `log.level`) + * @param params The row indicator extension parameters + * @returns The row indicator provider to use in the data grid + */ getRowIndicatorProvider: ( params: RowIndicatorExtensionParams ) => UnifiedDataTableProps['getRowIndicator'] | undefined; + + /** + * Gets additional leading controls (row actions) to display for each row in the data grid + * @param params The row controls extension parameters + * @returns The additional leading controls to display in the data grid + */ getRowAdditionalLeadingControls: ( params: RowControlsExtensionParams ) => UnifiedDataTableProps['rowAdditionalLeadingControls'] | undefined; + + /** + * Gets additional cell actions to show within expanded cell popovers in the data grid + * @returns The additional cell actions to show in the data grid + */ getAdditionalCellActions: () => AdditionalCellAction[]; - // Doc viewer + + /** + * Document viewer flyout + */ + + /** + * Supports customizing the behaviour of the Discover document + * viewer flyout, such as the flyout title and available tabs + * @param params The doc viewer extension parameters + * @returns The doc viewer extension + */ getDocViewer: (params: DocViewerExtensionParams) => DocViewerExtension; }