Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs UI] Support inline Log Views in the UI #152933

Merged
merged 44 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7f33f3b
Server changes
Kerry350 Feb 21, 2023
1869634
Common changes
Kerry350 Feb 21, 2023
7b58fc9
Alter reference at the closest edge to the server
Kerry350 Feb 21, 2023
d75ff57
Merge remote-tracking branch 'upstream' into 151489-support-inline-lo…
Kerry350 Feb 21, 2023
ec5805d
Merge remote-tracking branch 'upstream' into 151489-support-inline-lo…
Kerry350 Feb 22, 2023
64ebf99
Correct spelling
Kerry350 Feb 22, 2023
fc62aa9
Amend further references
Kerry350 Feb 22, 2023
9f1abab
Amend Jest tests
Kerry350 Feb 22, 2023
beaf6cb
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Feb 23, 2023
108d9f8
WIP: Adding URL handling to machine
Kerry350 Feb 23, 2023
160f2c4
Merge remote-tracking branch 'upstream/main' into 142840-support-inli…
Kerry350 Feb 27, 2023
107ec29
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Mar 1, 2023
2cef2d4
WIP: Amending UI code
Kerry350 Mar 1, 2023
9418f51
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Mar 2, 2023
c8d339f
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Mar 6, 2023
f980baa
WIP: Add support for updating and promoting inline log view to persisted
Kerry350 Mar 6, 2023
ad249cd
WIP: Amend UI code references
Kerry350 Mar 6, 2023
1f6ddbd
WIP: Update hook matches()
Kerry350 Mar 6, 2023
be1f57d
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Mar 7, 2023
d70b111
WIP: Sync to URL
Kerry350 Mar 8, 2023
a4857e8
WIP: Disable functionality where inline Log Views are not allowed
Kerry350 Mar 8, 2023
8fc9144
WIP: Add callout to Settings page
Kerry350 Mar 8, 2023
181f828
WIP: Fix update bug, add playground page, move ML checks in hierarchy
Kerry350 Mar 8, 2023
794d534
WIP: Ensure logView key stays in the URL
Kerry350 Mar 9, 2023
4d8d603
WIP: Add service for persisting inline Log View
Kerry350 Mar 9, 2023
9454771
WIP: Amend link-to handling
Kerry350 Mar 9, 2023
75f3883
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Mar 9, 2023
e713770
WIP: Fix tests
Kerry350 Mar 9, 2023
8874ed4
WIP: Lazy load alert dropdown to avoid adding 100kb to page load bund…
Kerry350 Mar 9, 2023
9150f0f
WIP: Fix tests
Kerry350 Mar 9, 2023
4ab9bd5
WIP: Improve messaging
Kerry350 Mar 9, 2023
55a5bd9
Just use .type key rather than io-ts type
Kerry350 Mar 10, 2023
9beb153
Merge remote-tracking branch 'upstream' into 142840-support-inline-lo…
Kerry350 Mar 10, 2023
2fb2844
Merge branch 'main' into 142840-support-inline-log-views-client
kibanamachine Mar 18, 2023
8ffdf6e
Merge remote-tracking branch 'upstream/main' into 142840-support-inli…
Kerry350 Mar 28, 2023
b288c09
Use one constants location
Kerry350 Mar 28, 2023
e24eb79
Full width callout
Kerry350 Mar 28, 2023
81fd520
Revert to default persisted Log View directly on ML pages
Kerry350 Mar 28, 2023
2edbedd
Merge branch '142840-support-inline-log-views-client' of github.com:K…
Kerry350 Mar 28, 2023
a1fa8fd
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Mar 28, 2023
2c51700
Merge remote-tracking branch 'upstream/main' into 142840-support-inli…
Kerry350 Mar 29, 2023
f63099c
Slightly alter import path (to reduce the page load bundle size)
Kerry350 Mar 29, 2023
f1e8b3b
Merge branch '142840-support-inline-log-views-client' of github.com:K…
Kerry350 Mar 29, 2023
665a459
Update reference from merge
Kerry350 Mar 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion x-pack/plugins/infra/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

export const DEFAULT_SOURCE_ID = 'default';
export const METRICS_INDEX_PATTERN = 'metrics-*,metricbeat-*';
export const LOGS_INDEX_PATTERN = 'logs-*,filebeat-*,kibana_sample_data_logs*';
export const METRICS_APP = 'metrics';
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/infra/common/log_analysis/job_parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export const partitionField = 'event.dataset';
export const getJobIdPrefix = (spaceId: string, sourceId: string) =>
`kibana-logs-ui-${spaceId}-${sourceId}-`;

export const getJobId = (spaceId: string, sourceId: string, jobType: string) =>
`${getJobIdPrefix(spaceId, sourceId)}${jobType}`;
export const getJobId = (spaceId: string, logViewId: string, jobType: string) =>
`${getJobIdPrefix(spaceId, logViewId)}${jobType}`;

export const getDatafeedId = (spaceId: string, sourceId: string, jobType: string) =>
`datafeed-${getJobId(spaceId, sourceId, jobType)}`;
export const getDatafeedId = (spaceId: string, logViewId: string, jobType: string) =>
`datafeed-${getJobId(spaceId, logViewId, jobType)}`;

export const datasetFilterRT = rt.union([
rt.strict({
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/log_views/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface LogViewsStaticConfig {
export const logViewOriginRT = rt.keyof({
stored: null,
internal: null,
inline: null,
'infra-source-stored': null,
'infra-source-internal': null,
'infra-source-fallback': null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const AlertDetailsAppSection = ({ rule, alert }: AlertDetailsAppSectionProps) =>
<CriterionPreview
key={chartCriterion.field}
ruleParams={rule.params}
sourceId={rule.params.logView.logViewId}
logViewReference={{
type: 'log-view-reference',
logViewId: rule.params.logView.logViewId,
}}
chartCriterion={chartCriterion}
showThreshold={true}
executionTimeRange={{ gte: rangeFrom, lte: rangeTo }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { useState, useCallback, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiPopover, EuiContextMenuItem, EuiContextMenuPanel, EuiHeaderLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { useLogViewContext } from '../../../hooks/use_log_view';
import { AlertFlyout } from './alert_flyout';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';

Expand All @@ -26,14 +27,30 @@ const readOnlyUserTooltipTitle = i18n.translate(
}
);

const inlineLogViewTooltipTitle = i18n.translate(
'xpack.infra.logs.alertDropdown.inlineLogViewCreateAlertTitle',
{
defaultMessage: 'Inline Log View',
}
);

const inlineLogViewTooltipContent = i18n.translate(
'xpack.infra.logs.alertDropdown.inlineLogViewCreateAlertContent',
{
defaultMessage: 'Creating alerts is not supported with inline Log Views',
}
);

export const AlertDropdown = () => {
const {
services: {
application: { capabilities },
observability,
},
} = useKibanaContextForPlugin();
const canCreateAlerts = capabilities?.logs?.save ?? false;
const { isPersistedLogView } = useLogViewContext();
const readOnly = !capabilities?.logs?.save;
const canCreateAlerts = (!readOnly && isPersistedLogView) ?? false;
const [popoverOpen, setPopoverOpen] = useState(false);
const [flyoutVisible, setFlyoutVisible] = useState(false);

Expand Down Expand Up @@ -61,8 +78,20 @@ export const AlertDropdown = () => {
icon="bell"
key="createLink"
onClick={openFlyout}
toolTipContent={!canCreateAlerts ? readOnlyUserTooltipContent : undefined}
toolTipTitle={!canCreateAlerts ? readOnlyUserTooltipTitle : undefined}
toolTipContent={
!canCreateAlerts
? readOnly
? readOnlyUserTooltipContent
: inlineLogViewTooltipContent
: undefined
}
toolTipTitle={
!canCreateAlerts
? readOnly
? readOnlyUserTooltipTitle
: inlineLogViewTooltipTitle
: undefined
}
>
<FormattedMessage
id="xpack.infra.alerting.logs.createAlertButton"
Expand All @@ -76,7 +105,7 @@ export const AlertDropdown = () => {
/>
</EuiContextMenuItem>,
];
}, [manageRulesLinkProps, canCreateAlerts, openFlyout]);
}, [canCreateAlerts, openFlyout, readOnly, manageRulesLinkProps]);

return (
<>
Expand Down Expand Up @@ -104,3 +133,7 @@ export const AlertDropdown = () => {
</>
);
};

// Allow for lazy loading
// eslint-disable-next-line import/no-default-export
export default AlertDropdown;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import React, { useCallback } from 'react';
import { EuiFlexItem, EuiFlexGroup, EuiButtonEmpty, EuiAccordion, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import type { ResolvedLogViewField } from '../../../../../common/log_views';
import type {
PersistedLogViewReference,
ResolvedLogViewField,
} from '../../../../../common/log_views';
import { Criterion } from './criterion';
import {
PartialRuleParams,
Expand Down Expand Up @@ -39,7 +42,7 @@ interface SharedProps {
defaultCriterion: PartialCriterionType;
errors: Errors['criteria'];
ruleParams: PartialRuleParams;
sourceId: string;
logViewReference: PersistedLogViewReference;
updateCriteria: (criteria: PartialCriteriaType) => void;
}

Expand All @@ -64,7 +67,7 @@ interface CriteriaWrapperProps {
addCriterion: () => void;
criteria: PartialCountCriteriaType;
errors: CriterionErrors;
sourceId: SharedProps['sourceId'];
logViewReference: SharedProps['logViewReference'];
isRatio?: boolean;
}

Expand All @@ -77,7 +80,7 @@ const CriteriaWrapper: React.FC<CriteriaWrapperProps> = (props) => {
fields,
errors,
ruleParams,
sourceId,
logViewReference,
isRatio = false,
} = props;

Expand Down Expand Up @@ -105,7 +108,7 @@ const CriteriaWrapper: React.FC<CriteriaWrapperProps> = (props) => {
<CriterionPreview
ruleParams={ruleParams}
chartCriterion={criterion}
sourceId={sourceId}
logViewReference={logViewReference}
showThreshold={!isRatio}
/>
</EuiAccordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { PersistedLogViewReference } from '../../../../../common/log_views';
import { ExecutionTimeRange } from '../../../../types';
import {
ChartContainer,
Expand Down Expand Up @@ -55,15 +56,15 @@ const GROUP_LIMIT = 5;
interface Props {
ruleParams: PartialRuleParams;
chartCriterion: Partial<Criterion>;
sourceId: string;
logViewReference: PersistedLogViewReference;
showThreshold: boolean;
executionTimeRange?: ExecutionTimeRange;
}

export const CriterionPreview: React.FC<Props> = ({
ruleParams,
chartCriterion,
sourceId,
logViewReference,
showThreshold,
executionTimeRange,
}) => {
Expand Down Expand Up @@ -105,7 +106,7 @@ export const CriterionPreview: React.FC<Props> = ({
? NUM_BUCKETS
: NUM_BUCKETS / 4
} // Display less data for groups due to space limitations
sourceId={sourceId}
logViewReference={logViewReference}
threshold={ruleParams.count}
chartAlertParams={chartAlertParams}
showThreshold={showThreshold}
Expand All @@ -116,7 +117,7 @@ export const CriterionPreview: React.FC<Props> = ({

interface ChartProps {
buckets: number;
sourceId: string;
logViewReference: PersistedLogViewReference;
threshold?: Threshold;
chartAlertParams: GetLogAlertsChartPreviewDataAlertParamsSubset;
showThreshold: boolean;
Expand All @@ -125,7 +126,7 @@ interface ChartProps {

const CriterionPreviewChart: React.FC<ChartProps> = ({
buckets,
sourceId,
logViewReference,
threshold,
chartAlertParams,
showThreshold,
Expand All @@ -141,7 +142,7 @@ const CriterionPreviewChart: React.FC<ChartProps> = ({
hasError,
chartPreviewData: series,
} = useChartPreviewData({
sourceId,
logViewReference,
ruleParams: chartAlertParams,
buckets,
executionTimeRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from '../../../../../common/alerting/logs/log_threshold/types';
import { decodeOrThrow } from '../../../../../common/runtime_types';
import { ObjectEntries } from '../../../../../common/utility_types';
import { useSourceId } from '../../../../containers/source_id';
import { useKibanaContextForPlugin } from '../../../../hooks/use_kibana';
import { LogViewProvider, useLogViewContext } from '../../../../hooks/use_log_view';
import { GroupByExpression } from '../../../common/group_by_expression/group_by_expression';
Expand All @@ -54,11 +53,6 @@ const DEFAULT_BASE_EXPRESSION = {

const DEFAULT_FIELD = 'log.level';

const createLogViewReference = (logViewId: string): PersistedLogViewReference => ({
logViewId,
type: 'log-view-reference',
});

const createDefaultCriterion = (
availableFields: ResolvedLogViewField[],
value: ExpressionCriteria['value']
Expand Down Expand Up @@ -100,7 +94,6 @@ export const ExpressionEditor: React.FC<
RuleTypeParamsExpressionProps<PartialRuleParams, LogsContextMeta>
> = (props) => {
const isInternal = props.metadata?.isInternal ?? false;
const [logViewId] = useSourceId();
const {
services: { logViews },
} = useKibanaContextForPlugin(); // injected during alert registration
Expand All @@ -112,7 +105,7 @@ export const ExpressionEditor: React.FC<
<Editor {...props} />
</SourceStatusWrapper>
) : (
<LogViewProvider logViewId={logViewId} logViews={logViews.client}>
<LogViewProvider logViews={logViews.client}>
<SourceStatusWrapper {...props}>
<Editor {...props} />
</SourceStatusWrapper>
Expand Down Expand Up @@ -163,7 +156,11 @@ export const Editor: React.FC<RuleTypeParamsExpressionProps<PartialRuleParams, L
) => {
const { setRuleParams, ruleParams, errors } = props;
const [hasSetDefaults, setHasSetDefaults] = useState<boolean>(false);
const { logViewId, resolvedLogView } = useLogViewContext();
const { logViewReference, resolvedLogView } = useLogViewContext();

if (logViewReference.type !== 'log-view-reference') {
throw new Error('The Log Threshold rule type only supports persisted Log Views');
}

const {
criteria: criteriaErrors,
Expand Down Expand Up @@ -230,8 +227,6 @@ export const Editor: React.FC<RuleTypeParamsExpressionProps<PartialRuleParams, L
[setRuleParams]
);

const logViewReference = useMemo(() => createLogViewReference(logViewId), [logViewId]);

const defaultCountAlertParams = useMemo(
() => createDefaultCountRuleParams(supportedFields, logViewReference),
[supportedFields, logViewReference]
Expand Down Expand Up @@ -279,7 +274,7 @@ export const Editor: React.FC<RuleTypeParamsExpressionProps<PartialRuleParams, L
defaultCriterion={defaultCountAlertParams.criteria[0]}
errors={criteriaErrors}
ruleParams={ruleParams}
sourceId={logViewId}
logViewReference={logViewReference}
updateCriteria={updateCriteria}
/>
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { useState, useMemo } from 'react';
import { HttpHandler } from '@kbn/core/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { PersistedLogViewReference } from '../../../../../../common/log_views';
import { ExecutionTimeRange } from '../../../../../types';
import { useTrackedPromise } from '../../../../../utils/use_tracked_promise';
import {
Expand All @@ -20,14 +21,14 @@ import { decodeOrThrow } from '../../../../../../common/runtime_types';
import { GetLogAlertsChartPreviewDataAlertParamsSubset } from '../../../../../../common/http_api/log_alerts';

interface Options {
sourceId: string;
logViewReference: PersistedLogViewReference;
ruleParams: GetLogAlertsChartPreviewDataAlertParamsSubset;
buckets: number;
executionTimeRange?: ExecutionTimeRange;
}

export const useChartPreviewData = ({
sourceId,
logViewReference,
ruleParams,
buckets,
executionTimeRange,
Expand All @@ -43,7 +44,7 @@ export const useChartPreviewData = ({
createPromise: async () => {
setHasError(false);
return await callGetChartPreviewDataAPI(
sourceId,
logViewReference,
http!.fetch,
ruleParams,
buckets,
Expand All @@ -58,7 +59,7 @@ export const useChartPreviewData = ({
setHasError(true);
},
},
[sourceId, http, ruleParams, buckets]
[logViewReference, http, ruleParams, buckets]
);

const isLoading = useMemo(
Expand All @@ -75,7 +76,7 @@ export const useChartPreviewData = ({
};

export const callGetChartPreviewDataAPI = async (
sourceId: string,
logViewReference: PersistedLogViewReference,
fetch: HttpHandler,
alertParams: GetLogAlertsChartPreviewDataAlertParamsSubset,
buckets: number,
Expand All @@ -86,7 +87,7 @@ export const callGetChartPreviewDataAPI = async (
body: JSON.stringify(
getLogAlertsChartPreviewDataRequestPayloadRT.encode({
data: {
logView: { type: 'log-view-reference', logViewId: sourceId },
logView: logViewReference,
alertParams,
buckets,
executionTimeRange,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

const LazyAlertDropdown = React.lazy(() => import('./alert_dropdown'));

export const LazyAlertDropdownWrapper = () => (
<React.Suspense fallback={<div />}>
<LazyAlertDropdown />
</React.Suspense>
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
*/

export * from './log_threshold_rule_type';
export { AlertDropdown } from './components/alert_dropdown';
export { LazyAlertDropdownWrapper } from './components/lazy_alert_dropdown';
Loading