Skip to content

Commit

Permalink
[8.14] [ResponseOps] Bring back EuiThemeProvider to fix o11y and stac…
Browse files Browse the repository at this point in the history
…k monitoring rules in stack management (#188724) (#188904)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[ResponseOps] Bring back EuiThemeProvider to fix o11y and stack
monitoring rules in stack management
(#188724)](#188724)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-23T08:42:42Z","message":"[ResponseOps]
Bring back EuiThemeProvider to fix o11y and stack monitoring rules in
stack management (#188724)\n\nRelated to
#186969
and\r\nelastic/response-ops-team#218\r\n\r\n## Summary\r\n\r\nThis PR
brings back EuiThemeProvider to fix o11y and stack monitoring\r\nrules
in stack management.\r\n\r\n## To check/do\r\n\r\n- [x] Add an APM test
that fails without this fix\r\n- [x] Check if this solves the related
SDH for
[CPU\r\nUsage](https://github.com/elastic/sdh-kibana/issues/4829)\r\n-
Yes, it will solve that
issue\r\n([comment](https://github.com/elastic/sdh-kibana/issues/4829#issuecomment-2242509680))\r\n-
[x] Smoke test **ALL** rule types in stack management\r\n - Can we load
the rule form?\r\n - Can we adjust all the input fields without
error?\r\n - Does it work both with and without data in the preview
chart?","sha":"ed32c980722efa113e70f0f409ee95e36a9f7a15","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","ci:project-deploy-observability","Team:obs-ux-infra_services","apm:review","v8.15.0","v8.16.0","v8.14.4"],"title":"[ResponseOps]
Bring back EuiThemeProvider to fix o11y and stack monitoring rules in
stack
management","number":188724,"url":"https://github.com/elastic/kibana/pull/188724","mergeCommit":{"message":"[ResponseOps]
Bring back EuiThemeProvider to fix o11y and stack monitoring rules in
stack management (#188724)\n\nRelated to
#186969
and\r\nelastic/response-ops-team#218\r\n\r\n## Summary\r\n\r\nThis PR
brings back EuiThemeProvider to fix o11y and stack monitoring\r\nrules
in stack management.\r\n\r\n## To check/do\r\n\r\n- [x] Add an APM test
that fails without this fix\r\n- [x] Check if this solves the related
SDH for
[CPU\r\nUsage](https://github.com/elastic/sdh-kibana/issues/4829)\r\n-
Yes, it will solve that
issue\r\n([comment](https://github.com/elastic/sdh-kibana/issues/4829#issuecomment-2242509680))\r\n-
[x] Smoke test **ALL** rule types in stack management\r\n - Can we load
the rule form?\r\n - Can we adjust all the input fields without
error?\r\n - Does it work both with and without data in the preview
chart?","sha":"ed32c980722efa113e70f0f409ee95e36a9f7a15"}},"sourceBranch":"main","suggestedTargetBranches":["8.15","8.14"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/188724","number":188724,"mergeCommit":{"message":"[ResponseOps]
Bring back EuiThemeProvider to fix o11y and stack monitoring rules in
stack management (#188724)\n\nRelated to
#186969
and\r\nelastic/response-ops-team#218\r\n\r\n## Summary\r\n\r\nThis PR
brings back EuiThemeProvider to fix o11y and stack monitoring\r\nrules
in stack management.\r\n\r\n## To check/do\r\n\r\n- [x] Add an APM test
that fails without this fix\r\n- [x] Check if this solves the related
SDH for
[CPU\r\nUsage](https://github.com/elastic/sdh-kibana/issues/4829)\r\n-
Yes, it will solve that
issue\r\n([comment](https://github.com/elastic/sdh-kibana/issues/4829#issuecomment-2242509680))\r\n-
[x] Smoke test **ALL** rule types in stack management\r\n - Can we load
the rule form?\r\n - Can we adjust all the input fields without
error?\r\n - Does it work both with and without data in the preview
chart?","sha":"ed32c980722efa113e70f0f409ee95e36a9f7a15"}},{"branch":"8.14","label":"v8.14.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Maryam Saeidi <[email protected]>
  • Loading branch information
kibanamachine and maryam-saeidi authored Jul 23, 2024
1 parent 2445c0e commit 7d17731
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 22 deletions.
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

0 comments on commit 7d17731

Please sign in to comment.