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

[8.14] [ResponseOps] Bring back EuiThemeProvider to fix o11y and stack monitoring rules in stack management (#188724) #188904

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ interface Props {
value: React.ReactNode;
children?: React.ReactNode;
color?: ExpressionColor;
dataTestSubj?: string;
}

export function PopoverExpression(props: Props) {
const { title, value, children, color } = props;
const { title, value, children, color, dataTestSubj } = props;
const [popoverOpen, setPopoverOpen] = useState(false);

return (
Expand All @@ -27,6 +28,7 @@ export function PopoverExpression(props: Props) {
closePopover={() => setPopoverOpen(false)}
button={
<EuiExpression
data-test-subj={dataTestSubj}
description={title}
value={value}
isActive={popoverOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function ServiceField({
}) {
return (
<PopoverExpression
dataTestSubj="apmServiceField"
value={currentValue || allOptionText}
title={i18n.translate('xpack.apm.alerting.fields.service', {
defaultMessage: 'Service',
Expand Down Expand Up @@ -68,6 +69,7 @@ export function EnvironmentField({
}) {
return (
<PopoverExpression
dataTestSubj="apmEnvironmentField"
value={getEnvironmentLabel(currentValue)}
title={i18n.translate('xpack.apm.alerting.fields.environment', {
defaultMessage: 'Environment',
Expand Down Expand Up @@ -106,7 +108,11 @@ export function TransactionNameField({
});

return (
<PopoverExpression value={currentValue || allOptionText} title={label}>
<PopoverExpression
dataTestSubj="apmTransactionNameField"
value={currentValue || allOptionText}
title={label}
>
<SuggestionsSelect
customOptions={[{ label: allOptionText, value: undefined }]}
customOptionText={i18n.translate('xpack.apm.alerting.transaction.name.custom.text', {
Expand Down Expand Up @@ -139,7 +145,11 @@ export function TransactionTypeField({
defaultMessage: 'Type',
});
return (
<PopoverExpression value={currentValue || allOptionText} title={label}>
<PopoverExpression
dataTestSubj="apmTransactionTypeField"
value={currentValue || allOptionText}
title={label}
>
<SuggestionsSelect
customOptions={[{ label: allOptionText, value: undefined }]}
customOptionText={i18n.translate('xpack.apm.transactionTypesSelectCustomOptionText', {
Expand Down Expand Up @@ -172,7 +182,11 @@ export function ErrorGroupingKeyField({
defaultMessage: 'Error grouping key',
});
return (
<PopoverExpression value={currentValue || allOptionText} title={label}>
<PopoverExpression
dataTestSubj="apmErrorGroupingKeyField"
value={currentValue || allOptionText}
title={label}
>
<SuggestionsSelect
customOptions={[{ label: allOptionText, value: undefined }]}
customOptionText={i18n.translate('xpack.apm.errorKeySelectCustomOptionText', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import {
EuiToolTip,
EuiCallOut,
EuiAccordion,
useEuiTheme,
COLOR_MODES_STANDARD,
} from '@elastic/eui';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import { capitalize } from 'lodash';
import { KibanaFeature } from '@kbn/features-plugin/public';
import {
Expand Down Expand Up @@ -199,6 +202,7 @@ export const RuleForm = ({
dataViews,
} = useKibana().services;
const canShowActions = hasShowActionsCapability(capabilities);
const { colorMode } = useEuiTheme();

const [ruleTypeModel, setRuleTypeModel] = useState<RuleTypeModel | null>(null);
const flyoutBodyOverflowRef = useRef<HTMLDivElement | HTMLSpanElement | null>(null);
Expand Down Expand Up @@ -765,24 +769,26 @@ export const RuleForm = ({
</SectionLoading>
}
>
<RuleParamsExpressionComponent
id={rule.id}
ruleParams={rule.params}
ruleInterval={`${ruleInterval ?? 1}${ruleIntervalUnit}`}
ruleThrottle={''}
alertNotifyWhen={rule.notifyWhen ?? 'onActionGroupChange'}
errors={errors}
setRuleParams={setRuleParams}
setRuleProperty={setRuleProperty}
defaultActionGroupId={defaultActionGroupId}
actionGroups={selectedRuleType.actionGroups}
metadata={metadata}
charts={charts}
data={data}
dataViews={dataViews}
unifiedSearch={unifiedSearch}
onChangeMetaData={onChangeMetaData}
/>
<EuiThemeProvider darkMode={colorMode === COLOR_MODES_STANDARD.dark}>
<RuleParamsExpressionComponent
id={rule.id}
ruleParams={rule.params}
ruleInterval={`${ruleInterval ?? 1}${ruleIntervalUnit}`}
ruleThrottle={''}
alertNotifyWhen={rule.notifyWhen ?? 'onActionGroupChange'}
errors={errors}
setRuleParams={setRuleParams}
setRuleProperty={setRuleProperty}
defaultActionGroupId={defaultActionGroupId}
actionGroups={selectedRuleType.actionGroups}
metadata={metadata}
charts={charts}
data={data}
dataViews={dataViews}
unifiedSearch={unifiedSearch}
onChangeMetaData={onChangeMetaData}
/>
</EuiThemeProvider>
</Suspense>
</EuiErrorBoundary>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import expect from '@kbn/expect';
import { asyncForEach } from '@kbn/std';
import { omit } from 'lodash';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { getApmSynthtraceEsClient } from '../../../common/utils/synthtrace/apm_es_client';
import { FtrProviderContext } from '../../ftr_provider_context';
import { generateUniqueKey } from '../../lib/get_test_data';

Expand All @@ -20,6 +23,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const retry = getService('retry');
const rules = getService('rules');
const toasts = getService('toasts');
const esClient = getService('es');
const apmSynthtraceKibanaClient = getService('apmSynthtraceKibanaClient');

async function getAlertsByName(name: string) {
const {
Expand Down Expand Up @@ -71,6 +76,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await nameInput.click();
}

async function defineAPMErrorCountRule(ruleName: string) {
await pageObjects.triggersActionsUI.clickCreateAlertButton();
await testSubjects.click(`apm.error_rate-SelectOption`);
await testSubjects.setValue('ruleNameInput', ruleName);
}

async function defineAlwaysFiringAlert(alertName: string) {
await pageObjects.triggersActionsUI.clickCreateAlertButton();
await testSubjects.click('test.always-firing-SelectOption');
Expand All @@ -82,6 +93,45 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
}

describe('create alert', function () {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;
before(async () => {
const version = (await apmSynthtraceKibanaClient.installApmPackage()).version;
apmSynthtraceEsClient = await getApmSynthtraceEsClient({
client: esClient,
packageVersion: version,
});
const opbeansJava = apm
.service({ name: 'opbeans-java', environment: 'production', agentName: 'java' })
.instance('instance');

const opbeansNode = apm
.service({ name: 'opbeans-node', environment: 'production', agentName: 'node' })
.instance('instance');

const events = timerange('now-15m', 'now')
.ratePerMinute(1)
.generator((timestamp) => {
return [
opbeansJava
.transaction({ transactionName: 'tx-java' })
.timestamp(timestamp)
.duration(100)
.failure()
.errors(opbeansJava.error({ message: 'a java error' }).timestamp(timestamp + 50)),

opbeansNode
.transaction({ transactionName: 'tx-node' })
.timestamp(timestamp)
.duration(100)
.success(),
];
});

return Promise.all([apmSynthtraceEsClient.index(events)]);
});

after(() => apmSynthtraceEsClient.clean());

beforeEach(async () => {
await pageObjects.common.navigateToApp('triggersActions');
await testSubjects.click('rulesTab');
Expand Down Expand Up @@ -321,6 +371,19 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await discardNewRuleCreation();
});

// Related issue that this test is trying to prevent:
// https://github.com/elastic/kibana/issues/186969
it('should successfully show the APM error count rule flyout', async () => {
const ruleName = generateUniqueKey();
await defineAPMErrorCountRule(ruleName);

await testSubjects.existOrFail('apmServiceField');
await testSubjects.existOrFail('apmEnvironmentField');
await testSubjects.existOrFail('apmErrorGroupingKeyField');

await discardNewRuleCreation();
});

it('should successfully test valid es_query alert', async () => {
const alertName = generateUniqueKey();
await defineEsQueryAlert(alertName);
Expand Down