mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ML] Fix Log rate analysis, change point detection, and pattern analysis embeddables not respecting filters from Dashboard's controls (#210039)
## Summary This PR addresses https://github.com/elastic/kibana/issues/204246 and fixes Log rate analysis and change point detection embeddable not updating based on Dashboard's controls https://github.com/user-attachments/assets/e6750cca-b579-49e8-af89-4effb3a7536e ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
14eefced0f
commit
8ce4eefad5
7 changed files with 44 additions and 11 deletions
|
@ -21,6 +21,7 @@ import {
|
|||
initializeTimeRange,
|
||||
initializeTitleManager,
|
||||
useBatchedPublishingSubjects,
|
||||
apiPublishesFilters,
|
||||
} from '@kbn/presentation-publishing';
|
||||
|
||||
import fastIsEqual from 'fast-deep-equal';
|
||||
|
@ -79,6 +80,8 @@ export const getChangePointChartEmbeddableFactory = (
|
|||
await pluginStart.data.dataViews.get(state.dataViewId),
|
||||
]);
|
||||
|
||||
const filtersApi = apiPublishesFilters(parentApi) ? parentApi : undefined;
|
||||
|
||||
const api = buildApi(
|
||||
{
|
||||
...timeRangeManager.api,
|
||||
|
@ -194,6 +197,7 @@ export const getChangePointChartEmbeddableFactory = (
|
|||
|
||||
return (
|
||||
<ChangePointDetectionComponent
|
||||
filtersApi={filtersApi}
|
||||
viewType={viewType}
|
||||
timeRange={timeRange}
|
||||
fn={fn}
|
||||
|
|
|
@ -17,6 +17,7 @@ import type { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import {
|
||||
apiHasExecutionContext,
|
||||
apiPublishesFilters,
|
||||
fetch$,
|
||||
initializeTimeRange,
|
||||
initializeTitleManager,
|
||||
|
@ -81,6 +82,7 @@ export const getLogRateAnalysisEmbeddableFactory = (
|
|||
),
|
||||
]);
|
||||
|
||||
const filtersApi = apiPublishesFilters(parentApi) ? parentApi : undefined;
|
||||
const api = buildApi(
|
||||
{
|
||||
...timeRangeManager.api,
|
||||
|
@ -190,6 +192,7 @@ export const getLogRateAnalysisEmbeddableFactory = (
|
|||
|
||||
return (
|
||||
<LogRateAnalysisEmbeddableWrapper
|
||||
filtersApi={filtersApi}
|
||||
dataViewId={dataViewId}
|
||||
timeRange={timeRange}
|
||||
onLoading={onLoading}
|
||||
|
|
|
@ -17,6 +17,7 @@ import type { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public';
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import {
|
||||
apiHasExecutionContext,
|
||||
apiPublishesFilters,
|
||||
fetch$,
|
||||
initializeTimeRange,
|
||||
initializeTitleManager,
|
||||
|
@ -80,6 +81,7 @@ export const getPatternAnalysisEmbeddableFactory = (
|
|||
),
|
||||
]);
|
||||
|
||||
const filtersApi = apiPublishesFilters(parentApi) ? parentApi : undefined;
|
||||
const api = buildApi(
|
||||
{
|
||||
...timeRangeManager.api,
|
||||
|
@ -198,6 +200,7 @@ export const getPatternAnalysisEmbeddableFactory = (
|
|||
|
||||
return (
|
||||
<PatternAnalysisComponent
|
||||
filtersApi={filtersApi}
|
||||
dataViewId={dataViewId}
|
||||
fieldName={fieldName}
|
||||
minimumTimeRangeOption={minimumTimeRangeOption}
|
||||
|
|
|
@ -19,6 +19,7 @@ import { useTimeRangeUpdates } from '@kbn/ml-date-picker';
|
|||
import { type AggregateQuery } from '@kbn/es-query';
|
||||
import type { TimeRangeBounds } from '@kbn/data-plugin/common';
|
||||
import { getBoundsRoundedToInterval, useTimeBuckets } from '@kbn/ml-time-buckets';
|
||||
import type { PublishesFilters } from '@kbn/presentation-publishing';
|
||||
import { useAiopsAppContext } from './use_aiops_app_context';
|
||||
import { useReload } from './use_reload';
|
||||
|
||||
|
@ -60,8 +61,9 @@ export const FilterQueryContext = createContext<{
|
|||
export const FilterQueryContextProvider: FC<
|
||||
PropsWithChildren<{
|
||||
timeRange?: TimeRange;
|
||||
filtersApi?: PublishesFilters;
|
||||
}>
|
||||
> = ({ children, timeRange }) => {
|
||||
> = ({ children, timeRange, filtersApi }) => {
|
||||
const {
|
||||
data: {
|
||||
query: { filterManager, queryString, timefilter },
|
||||
|
@ -78,13 +80,25 @@ export const FilterQueryContextProvider: FC<
|
|||
const timeRangeUpdates = useTimeRangeUpdates(false);
|
||||
|
||||
useEffect(() => {
|
||||
const sub = filterManager.getUpdates$().subscribe(() => {
|
||||
setResultFilter(filterManager.getFilters());
|
||||
});
|
||||
return () => {
|
||||
sub.unsubscribe();
|
||||
};
|
||||
}, [filterManager]);
|
||||
// Embeddable API exposes not just filters from query bar, but also
|
||||
// filters from other dashboard controls
|
||||
// so if that information is available, we should prioritize it
|
||||
if (filtersApi?.filters$) {
|
||||
const sub = filtersApi?.filters$.subscribe(() => {
|
||||
setResultFilter(filtersApi?.filters$.getValue() ?? []);
|
||||
});
|
||||
return () => {
|
||||
sub.unsubscribe();
|
||||
};
|
||||
} else {
|
||||
const sub = filterManager.getUpdates$().subscribe(() => {
|
||||
setResultFilter(filterManager.getFilters());
|
||||
});
|
||||
return () => {
|
||||
sub.unsubscribe();
|
||||
};
|
||||
}
|
||||
}, [filterManager, filtersApi]);
|
||||
|
||||
useEffect(() => {
|
||||
const sub = queryString.getUpdates$().subscribe(() => {
|
||||
|
|
|
@ -15,6 +15,7 @@ import { pick } from 'lodash';
|
|||
import React, { useEffect, useMemo, useState, type FC } from 'react';
|
||||
import type { Observable } from 'rxjs';
|
||||
import { BehaviorSubject, combineLatest, distinctUntilChanged, map } from 'rxjs';
|
||||
import type { PublishesFilters } from '@kbn/presentation-publishing';
|
||||
import {
|
||||
ChangePointDetectionControlsContextProvider,
|
||||
type ChangePointAnnotation,
|
||||
|
@ -62,6 +63,7 @@ export interface ChangePointDetectionProps {
|
|||
onLoading: (isLoading: boolean) => void;
|
||||
onRenderComplete: () => void;
|
||||
onError: (error: Error) => void;
|
||||
filtersApi?: PublishesFilters;
|
||||
}
|
||||
|
||||
const ChangePointDetectionWrapper: FC<ChangePointDetectionPropsWithDeps> = ({
|
||||
|
@ -82,6 +84,7 @@ const ChangePointDetectionWrapper: FC<ChangePointDetectionPropsWithDeps> = ({
|
|||
onRenderComplete,
|
||||
embeddingOrigin,
|
||||
lastReloadRequestTime,
|
||||
filtersApi,
|
||||
}) => {
|
||||
const deps = useMemo(() => {
|
||||
const { charts, lens, data, usageCollection, fieldFormats, share, storage, unifiedSearch } =
|
||||
|
@ -147,7 +150,7 @@ const ChangePointDetectionWrapper: FC<ChangePointDetectionPropsWithDeps> = ({
|
|||
dataViews={pluginStart.data.dataViews}
|
||||
dataViewId={dataViewId}
|
||||
>
|
||||
<FilterQueryContextProvider timeRange={timeRange}>
|
||||
<FilterQueryContextProvider timeRange={timeRange} filtersApi={filtersApi}>
|
||||
<ChangePointDetectionControlsContextProvider>
|
||||
<ChartGridEmbeddableWrapper
|
||||
viewType={viewType}
|
||||
|
|
|
@ -20,6 +20,7 @@ import { DatePickerContextProvider } from '@kbn/ml-date-picker';
|
|||
import type { SignificantItem } from '@kbn/ml-agg-utils';
|
||||
|
||||
import type { WindowParameters } from '@kbn/aiops-log-rate-analysis';
|
||||
import type { PublishesFilters } from '@kbn/presentation-publishing';
|
||||
import { AiopsAppContext, type AiopsAppContextValue } from '../hooks/use_aiops_app_context';
|
||||
import { DataSourceContextProvider } from '../hooks/use_data_source';
|
||||
import { ReloadContextProvider } from '../hooks/use_reload';
|
||||
|
@ -59,6 +60,7 @@ export interface LogRateAnalysisEmbeddableWrapperProps {
|
|||
onRenderComplete: () => void;
|
||||
onError: (error: Error) => void;
|
||||
windowParameters?: WindowParameters;
|
||||
filtersApi?: PublishesFilters;
|
||||
}
|
||||
|
||||
const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps> = ({
|
||||
|
@ -71,6 +73,7 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
|
|||
embeddingOrigin,
|
||||
lastReloadRequestTime,
|
||||
windowParameters,
|
||||
filtersApi,
|
||||
}) => {
|
||||
const deps = useMemo(() => {
|
||||
const { lens, data, usageCollection, fieldFormats, charts, share, storage, unifiedSearch } =
|
||||
|
@ -155,7 +158,7 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
|
|||
dataViews={pluginStart.data.dataViews}
|
||||
dataViewId={dataViewId}
|
||||
>
|
||||
<FilterQueryContextProvider timeRange={timeRange}>
|
||||
<FilterQueryContextProvider timeRange={timeRange} filtersApi={filtersApi}>
|
||||
<LogRateAnalysisReduxProvider initialAnalysisStart={windowParameters}>
|
||||
<LogRateAnalysisForEmbeddable timeRange={timeRange} />
|
||||
</LogRateAnalysisReduxProvider>
|
||||
|
|
|
@ -14,6 +14,7 @@ import { pick } from 'lodash';
|
|||
import React, { useEffect, useMemo, useState, type FC } from 'react';
|
||||
import type { Observable } from 'rxjs';
|
||||
import { BehaviorSubject, combineLatest, distinctUntilChanged, map } from 'rxjs';
|
||||
import type { PublishesFilters } from '@kbn/presentation-publishing';
|
||||
import type { MinimumTimeRangeOption } from '../components/log_categorization/log_categorization_for_embeddable/minimum_time_range';
|
||||
import type {
|
||||
RandomSamplerOption,
|
||||
|
@ -60,6 +61,7 @@ export interface PatternAnalysisProps {
|
|||
onLoading: (isLoading: boolean) => void;
|
||||
onRenderComplete: () => void;
|
||||
onError: (error: Error) => void;
|
||||
filtersApi?: PublishesFilters;
|
||||
}
|
||||
|
||||
const PatternAnalysisWrapper: FC<PatternAnalysisPropsWithDeps> = ({
|
||||
|
@ -79,6 +81,7 @@ const PatternAnalysisWrapper: FC<PatternAnalysisPropsWithDeps> = ({
|
|||
embeddingOrigin,
|
||||
lastReloadRequestTime,
|
||||
onChange,
|
||||
filtersApi,
|
||||
}) => {
|
||||
const deps = useMemo(() => {
|
||||
const { lens, data, usageCollection, fieldFormats, charts, share, storage, unifiedSearch } =
|
||||
|
@ -145,7 +148,7 @@ const PatternAnalysisWrapper: FC<PatternAnalysisPropsWithDeps> = ({
|
|||
dataViews={pluginStart.data.dataViews}
|
||||
dataViewId={dataViewId}
|
||||
>
|
||||
<FilterQueryContextProvider timeRange={timeRange}>
|
||||
<FilterQueryContextProvider timeRange={timeRange} filtersApi={filtersApi}>
|
||||
<PatternAnalysisEmbeddableWrapper
|
||||
dataViewId={dataViewId}
|
||||
timeRange={timeRange}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue