Skip to content

Commit

Permalink
Merge branch 'main' into elastic#8929-1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp authored Apr 16, 2024
2 parents a9edafd + da890be commit 9944abd
Show file tree
Hide file tree
Showing 19 changed files with 594 additions and 106 deletions.
1 change: 1 addition & 0 deletions packages/kbn-rule-data-utils/src/rule_types/o11y_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const OBSERVABILITY_THRESHOLD_RULE_TYPE_ID = 'observability.rules.custom_
export const SLO_BURN_RATE_RULE_TYPE_ID = 'slo.rules.burnRate';

export const METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.inventory.threshold';
export const METRIC_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.threshold';
export const LOG_THRESHOLD_ALERT_TYPE_ID = 'logs.alert.document.count';

export enum ApmRuleType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@

import { EuiCheckableCard, EuiFormFieldset, EuiSpacer, EuiTitle } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { useUiTracker } from '@kbn/observability-shared-plugin/public';
import {
logIndexNameReferenceRT,
LogDataViewReference,
logDataViewReferenceRT,
LogIndexReference,
} from '@kbn/logs-shared-plugin/common';
import { EuiCallOut } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { loadRuleAggregations } from '@kbn/triggers-actions-ui-plugin/public';
import { LOG_THRESHOLD_ALERT_TYPE_ID } from '@kbn/rule-data-utils';

import { rulesLocatorID, RulesParams } from '@kbn/observability-plugin/public';
import { EuiLink } from '@elastic/eui';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { FormElement, isFormElementForType } from './form_elements';
import { IndexNamesConfigurationPanel } from './index_names_configuration_panel';
import { IndexPatternConfigurationPanel } from './index_pattern_configuration_panel';
Expand All @@ -25,6 +33,19 @@ export const IndicesConfigurationPanel = React.memo<{
isReadOnly: boolean;
indicesFormElement: FormElement<LogIndexReference | undefined, FormValidationError>;
}>(({ isLoading, isReadOnly, indicesFormElement }) => {
const {
services: {
http,
share: {
url: { locators },
},
},
} = useKibanaContextForPlugin();
const [numberOfLogsRules, setNumberOfLogsRules] = useState(0);

const rulesLocator = locators.get<RulesParams>(rulesLocatorID);
const viewAffectedRulesLink = rulesLocator?.useUrl({ type: [LOG_THRESHOLD_ALERT_TYPE_ID] });

const trackChangeIndexSourceType = useUiTracker({ app: 'infra_logs' });

const changeToIndexPatternType = useCallback(() => {
Expand Down Expand Up @@ -54,6 +75,23 @@ export const IndicesConfigurationPanel = React.memo<{
});
}, [indicesFormElement, trackChangeIndexSourceType]);

useEffect(() => {
const getNumberOfInfraRules = async () => {
if (http) {
const { ruleExecutionStatus } = await loadRuleAggregations({
http,
typesFilter: [LOG_THRESHOLD_ALERT_TYPE_ID],
});
const numberOfRules = Object.values(ruleExecutionStatus).reduce(
(acc, value) => acc + value,
0
);
setNumberOfLogsRules(numberOfRules);
}
};
getNumberOfInfraRules();
}, [http]);

return (
<EuiFormFieldset
legend={{
Expand Down Expand Up @@ -123,6 +161,36 @@ export const IndicesConfigurationPanel = React.memo<{
/>
)}
</EuiCheckableCard>
{numberOfLogsRules > 0 && indicesFormElement.isDirty && (
<>
<EuiSpacer size="s" />
<EuiCallOut
data-test-subj="infraIndicesPanelSettingsWarningCallout"
size="m"
title={i18n.translate('xpack.infra.sourceConfiguration.logsIndicesUsedByRulesTitle', {
defaultMessage: 'Rules utilize this data source.',
})}
color="warning"
iconType="warning"
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.logsIndicesUsedByRulesMessage"
defaultMessage="One or more rules rely on this data source setting. Changing this setting may impact the execution of these rules."
/>
<EuiSpacer size="s" />
<EuiLink
data-test-subj="logIndicesViewAffectedRulesLink"
href={viewAffectedRulesLink}
target="_blank"
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.logIndices.viewAffectedRulesLink"
defaultMessage="View affected rules"
/>
</EuiLink>
</EuiCallOut>
</>
)}
</EuiFormFieldset>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { useKibana } from '@kbn/kibana-react-plugin/public';
import { SourceConfigurationSettings } from './settings/source_configuration_settings';

export const MetricsSettingsPage = () => {
const uiCapabilities = useKibana().services.application?.capabilities;
const { application, http } = useKibana().services;
return (
<EuiErrorBoundary>
<SourceConfigurationSettings
shouldAllowEdit={uiCapabilities?.infrastructure?.configureSource as boolean}
shouldAllowEdit={application?.capabilities?.infrastructure?.configureSource as boolean}
http={http}
/>
</EuiErrorBoundary>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { EuiLink } from '@elastic/eui';
import {
EuiCallOut,
EuiCode,
Expand All @@ -18,15 +19,23 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import { rulesLocatorID, RulesParams } from '@kbn/observability-plugin/public';
import {
METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID,
METRIC_THRESHOLD_ALERT_TYPE_ID,
} from '@kbn/rule-data-utils';
import { METRICS_INDEX_PATTERN } from '../../../../common/constants';
import { InputFieldProps } from './input_fields';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';

interface IndicesConfigurationPanelProps {
isLoading: boolean;
readOnly: boolean;
metricAliasFieldProps: InputFieldProps;
metricIndicesExist?: boolean;
remoteClustersExist?: boolean;
isMetricAliasChanged?: boolean;
numberOfInfraRules: number;
}

const METRIC_INDICES_WARNING_TITLE = i18n.translate(
Expand All @@ -36,6 +45,13 @@ const METRIC_INDICES_WARNING_TITLE = i18n.translate(
}
);

const METRIC_INDICES_USED_BY_RULES = i18n.translate(
'xpack.infra.sourceConfiguration.metricIndicesUsedByRulesTitle',
{
defaultMessage: 'Rules utilize this data source.',
}
);

const REMOTE_CLUSTER_ERROR_TITLE = i18n.translate(
'xpack.infra.sourceConfiguration.remoteClusterConnectionDoNotExistTitle',
{
Expand All @@ -49,97 +65,142 @@ export const IndicesConfigurationPanel = ({
metricAliasFieldProps,
metricIndicesExist,
remoteClustersExist,
}: IndicesConfigurationPanelProps) => (
<EuiForm>
<EuiTitle size="s">
<h3>
<FormattedMessage
id="xpack.infra.sourceConfiguration.indicesSectionTitle"
defaultMessage="Indices"
/>
</h3>
</EuiTitle>
<EuiSpacer size="m" />
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesTitle"
defaultMessage="Metrics indices"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesDescription"
defaultMessage="Index pattern for matching indices that contain metrics data"
/>
}
>
<EuiFormRow
error={metricAliasFieldProps.error}
fullWidth
helpText={
isMetricAliasChanged,
numberOfInfraRules,
}: IndicesConfigurationPanelProps) => {
const {
services: {
share: {
url: { locators },
},
},
} = useKibanaContextForPlugin();

const rulesLocator = locators.get<RulesParams>(rulesLocatorID);
const viewAffectedRulesLink = rulesLocator?.useUrl({
type: [METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, METRIC_THRESHOLD_ALERT_TYPE_ID],
});

return (
<EuiForm>
<EuiTitle size="s">
<h3>
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesRecommendedValue"
defaultMessage="The recommended value is {defaultValue}"
values={{
defaultValue: <EuiCode>{METRICS_INDEX_PATTERN}</EuiCode>,
}}
id="xpack.infra.sourceConfiguration.indicesSectionTitle"
defaultMessage="Indices"
/>
</h3>
</EuiTitle>
<EuiSpacer size="m" />
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesTitle"
defaultMessage="Metrics indices"
/>
</h4>
}
isInvalid={metricAliasFieldProps.isInvalid}
label={
description={
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesLabel"
defaultMessage="Metrics indices"
id="xpack.infra.sourceConfiguration.metricIndicesDescription"
defaultMessage="Index pattern for matching indices that contain metrics data"
/>
}
>
<EuiFieldText
data-test-subj="metricIndicesInput"
<EuiFormRow
error={metricAliasFieldProps.error}
fullWidth
disabled={isLoading}
readOnly={readOnly}
isLoading={isLoading}
{...metricAliasFieldProps}
/>
</EuiFormRow>
{remoteClustersExist && !metricIndicesExist && (
<>
<EuiSpacer size="s" />
<EuiCallOut
size="s"
title={METRIC_INDICES_WARNING_TITLE}
color="warning"
iconType="warning"
data-test-subj="infraIndicesPanelSettingsWarningCallout"
>
helpText={
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesDoNotExist"
defaultMessage="We couldn’t find any metrics data because the pattern entered doesn’t match any index."
id="xpack.infra.sourceConfiguration.metricIndicesRecommendedValue"
defaultMessage="The recommended value is {defaultValue}"
values={{
defaultValue: <EuiCode>{METRICS_INDEX_PATTERN}</EuiCode>,
}}
/>
</EuiCallOut>
</>
)}
{!remoteClustersExist && !metricIndicesExist && (
<>
<EuiSpacer size="s" />
<EuiCallOut
data-test-subj="infraIndicesPanelSettingsDangerCallout"
size="s"
title={REMOTE_CLUSTER_ERROR_TITLE}
color="danger"
iconType="error"
>
}
isInvalid={metricAliasFieldProps.isInvalid}
label={
<FormattedMessage
id="xpack.infra.sourceConfiguration.remoteClusterConnectionDoNotExist"
defaultMessage="Check that the remote cluster is available or that the remote connection settings are
correct."
id="xpack.infra.sourceConfiguration.metricIndicesLabel"
defaultMessage="Metrics indices"
/>
</EuiCallOut>
</>
)}
</EuiDescribedFormGroup>
</EuiForm>
);
}
>
<EuiFieldText
data-test-subj="metricIndicesInput"
fullWidth
disabled={isLoading}
readOnly={readOnly}
isLoading={isLoading}
{...metricAliasFieldProps}
/>
</EuiFormRow>
{isMetricAliasChanged && numberOfInfraRules > 0 && (
<>
<EuiSpacer size="s" />
<EuiCallOut
data-test-subj="infraIndicesPanelSettingsWarningCalloutUsedByRules"
size="s"
title={METRIC_INDICES_USED_BY_RULES}
color="warning"
iconType="warning"
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesUsedByRulesMessage"
defaultMessage="One or more rules rely on this data source setting. Changing this setting may impact the execution of these rules."
/>
<EuiSpacer size="s" />
<EuiLink
data-test-subj="metricIndicesViewAffectedRulesLink"
href={viewAffectedRulesLink}
target="_blank"
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndices.viewAffectedRulesLink"
defaultMessage="View affected rules"
/>
</EuiLink>
</EuiCallOut>
</>
)}
{remoteClustersExist && !metricIndicesExist && (
<>
<EuiSpacer size="s" />
<EuiCallOut
size="s"
title={METRIC_INDICES_WARNING_TITLE}
color="warning"
iconType="warning"
data-test-subj="infraIndicesPanelSettingsWarningCallout"
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.metricIndicesDoNotExist"
defaultMessage="We couldn’t find any metrics data because the pattern entered doesn’t match any index."
/>
</EuiCallOut>
</>
)}
{!remoteClustersExist && !metricIndicesExist && (
<>
<EuiSpacer size="s" />
<EuiCallOut
data-test-subj="infraIndicesPanelSettingsDangerCallout"
size="s"
title={REMOTE_CLUSTER_ERROR_TITLE}
color="danger"
iconType="error"
>
<FormattedMessage
id="xpack.infra.sourceConfiguration.remoteClusterConnectionDoNotExist"
defaultMessage="Check that the remote cluster is available or that the remote connection settings are
correct."
/>
</EuiCallOut>
</>
)}
</EuiDescribedFormGroup>
</EuiForm>
);
};
Loading

0 comments on commit 9944abd

Please sign in to comment.