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

[Uptime] TLS alerting #63913

Merged
merged 57 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
674857e
Refactor settings form event handling and modify certs fields.
justinkambic Apr 21, 2020
7d2bf4c
Fix/improve broken types/unit/integration/api tests.
justinkambic Apr 21, 2020
caf3ef2
Merge branch 'master' into uptime_tls-settings
justinkambic Apr 23, 2020
d0246a7
Modify default expiration threshold.
justinkambic Apr 23, 2020
f7678b6
Rename test vars.
justinkambic Apr 23, 2020
0ddd97b
Implement PR feedback.
justinkambic Apr 23, 2020
ef21286
Refresh snapshots, fix broken tests/types.
justinkambic Apr 23, 2020
8412951
Remove unnecessary state spreading.
justinkambic Apr 23, 2020
59e60e8
Add type for settings field errors.
justinkambic Apr 23, 2020
d47d429
Refresh test snapshots.
justinkambic Apr 23, 2020
a1fdf46
Improve punctuation.
justinkambic Apr 23, 2020
929e38a
Add TLS alert type.
justinkambic Apr 16, 2020
07055cb
Add cert API request and runtime type checking.
justinkambic Apr 8, 2020
9e017cb
Add api test for cert api.
justinkambic Apr 16, 2020
b7ab73b
Add unload command to certs test.
justinkambic Apr 16, 2020
6f007bc
Extract API params interface to io-ts type.
justinkambic Apr 17, 2020
a18ee01
Add TLS alert type on server.
justinkambic Apr 17, 2020
ff773bf
WIP - add state for changing selected alert type.
justinkambic Apr 17, 2020
5870a59
Finish adding alert type for client, add server alert summary.
justinkambic Apr 22, 2020
4c94906
Add some state variables.
justinkambic Apr 23, 2020
6e0b469
Update certs summary function to create required values.
justinkambic Apr 23, 2020
de52717
Merge branch 'master' into uptime_tls-alert
justinkambic Apr 27, 2020
36a9ee1
Refresh test snapshots.
justinkambic Apr 27, 2020
6f4365f
Clean up message generator function.
justinkambic Apr 27, 2020
1a339d1
Add a comment.
justinkambic Apr 27, 2020
e5febce
Update formatting for alert messages, add flags denoting presence of …
justinkambic Apr 27, 2020
86a1ff9
Add relative date information to tls alert messages.
justinkambic Apr 27, 2020
b13c74f
Clean up more logic in certs request function.
justinkambic Apr 27, 2020
3092dad
Fix broken unit tests.
justinkambic Apr 27, 2020
4c0d3f6
Merge branch 'master' into uptime_tls-alert
justinkambic Apr 28, 2020
1255978
Move tests for common function to new file.
justinkambic Apr 29, 2020
2326449
Fix logic error in test and add common state fields to tls alerts.
justinkambic Apr 29, 2020
ba9bc8c
Extract common state field translations from status check alert.
justinkambic Apr 29, 2020
844f443
Merge branch 'master' into uptime_tls-alert
justinkambic Apr 29, 2020
9162a65
Add a comment.
justinkambic Apr 29, 2020
c436914
Add nested context navigation for uptime alert selection.
justinkambic Apr 29, 2020
4ed9d11
Merge branch 'master' into uptime_tls-alert
justinkambic Apr 29, 2020
77ac31a
Clean up types.
justinkambic Apr 29, 2020
f044861
Fix translation key typo.
justinkambic Apr 30, 2020
d820bb1
Merge branch 'master' into uptime_tls-alert
justinkambic Apr 30, 2020
9551b14
Extract translations from tls alert factory.
justinkambic Apr 30, 2020
4a39540
Extract summary messages to translation file.
justinkambic Apr 30, 2020
cbf85eb
Change default tls alert time window from 1w to 1d.
justinkambic Apr 30, 2020
2420c81
Merge branch 'master' into uptime_tls-alert
justinkambic May 4, 2020
e34742e
Merge branch 'master' into uptime_tls-alert
justinkambic May 4, 2020
7bc051e
Remove unnecessary import.
justinkambic May 4, 2020
d693a2a
Simplify page linking.
justinkambic May 4, 2020
5d57988
Extract a non-trivial component to a dedicated file.
justinkambic May 4, 2020
2c07456
Simplify create alert copy.
justinkambic May 4, 2020
6fb9d3b
Fix broken functional test.
justinkambic May 4, 2020
5902515
Fix busted types.
justinkambic May 4, 2020
190610c
Fix tls query error.
justinkambic May 4, 2020
86add5b
Allow for alerts toggle button to receive a set of types to display.
justinkambic May 4, 2020
d1b414a
Add alerts toggle button to certs page.
justinkambic May 4, 2020
f3f18c1
Fix copy.
justinkambic May 4, 2020
98418d2
Fixup punctuation in default message to avoid double-period symbols.
justinkambic May 4, 2020
8566b00
Refresh snapshots.
justinkambic May 4, 2020
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
9 changes: 9 additions & 0 deletions x-pack/plugins/uptime/common/constants/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ export const ACTION_GROUP_DEFINITIONS: ActionGroupDefinitions = {
id: 'xpack.uptime.alerts.actionGroups.monitorStatus',
name: 'Uptime Down Monitor',
},
TLS: {
id: 'xpack.uptime.alerts.actionGroups.tls',
name: 'Uptime TLS Alert',
},
};

export const CLIENT_ALERT_TYPES = {
MONITOR_STATUS: 'xpack.uptime.alerts.monitorStatus',
TLS: 'xpack.uptime.alerts.tls',
};
2 changes: 1 addition & 1 deletion x-pack/plugins/uptime/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { ACTION_GROUP_DEFINITIONS } from './alerts';
export * from './alerts';
export { CHART_FORMAT_LIMITS } from './chart_format_limits';
export { CLIENT_DEFAULTS } from './client_defaults';
export { CONTEXT_DEFAULTS } from './context_defaults';
Expand Down
23 changes: 23 additions & 0 deletions x-pack/plugins/uptime/common/runtime_types/alerts/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as t from 'io-ts';

export const UptimeCommonStateType = t.intersection([
t.partial({
currentTriggerStarted: t.string,
firstTriggeredAt: t.string,
lastTriggeredAt: t.string,
lastResolvedAt: t.string,
}),
t.type({
firstCheckedAt: t.string,
lastCheckedAt: t.string,
isTriggered: t.boolean,
}),
]);

export type UptimeCommonState = t.TypeOf<typeof UptimeCommonStateType>;
8 changes: 2 additions & 6 deletions x-pack/plugins/uptime/common/runtime_types/alerts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

export {
StatusCheckAlertStateType,
StatusCheckAlertState,
StatusCheckExecutorParamsType,
StatusCheckExecutorParams,
} from './status_check';
export * from './common';
export * from './status_check';
16 changes: 0 additions & 16 deletions x-pack/plugins/uptime/common/runtime_types/alerts/status_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@

import * as t from 'io-ts';

export const StatusCheckAlertStateType = t.intersection([
t.partial({
currentTriggerStarted: t.string,
firstTriggeredAt: t.string,
lastTriggeredAt: t.string,
lastResolvedAt: t.string,
}),
t.type({
firstCheckedAt: t.string,
lastCheckedAt: t.string,
isTriggered: t.boolean,
}),
]);

export type StatusCheckAlertState = t.TypeOf<typeof StatusCheckAlertStateType>;

export const StatusCheckExecutorParamsType = t.intersection([
t.partial({
filters: t.string,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/uptime/common/runtime_types/certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const GetCertsParamsType = t.intersection([
}),
t.partial({
search: t.string,
notValidBefore: t.string,
notValidAfter: t.string,
from: t.string,
to: t.string,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiExpression, EuiFlexItem, EuiFlexGroup, EuiSpacer } from '@elastic/eui';
import React from 'react';
import { TlsTranslations } from './translations';
import { SettingsMessageExpressionPopover } from './settings_message_expression_popover';

interface Props {
ageThreshold?: number;
expirationThreshold?: number;
setAlertFlyoutVisible: (value: boolean) => void;
}

export const AlertTlsComponent: React.FC<Props> = props => (
<>
<EuiSpacer size="l" />
<EuiFlexGroup direction="column" gutterSize="none">
<EuiFlexItem>
<EuiExpression
aria-label={TlsTranslations.criteriaAriaLabel}
color="secondary"
description={TlsTranslations.criteriaDescription}
value={TlsTranslations.criteriaValue}
/>
</EuiFlexItem>
<EuiFlexItem>
<SettingsMessageExpressionPopover
aria-label={TlsTranslations.expirationAriaLabel}
id="expiration"
description={TlsTranslations.expirationDescription}
value={TlsTranslations.expirationValue(props.expirationThreshold)}
{...props}
/>
</EuiFlexItem>
<EuiFlexItem>
<SettingsMessageExpressionPopover
aria-label={TlsTranslations.ageAriaLabel}
id="age"
description={TlsTranslations.ageDescription}
value={TlsTranslations.ageValue(props.ageThreshold)}
{...props}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { useDispatch, useSelector } from 'react-redux';
import React, { useCallback } from 'react';
import { AlertTlsComponent } from '../alert_tls';
import { setAlertFlyoutVisible } from '../../../../state/actions';
import { selectDynamicSettings } from '../../../../state/selectors';

export const AlertTls = () => {
const dispatch = useDispatch();
const setFlyoutVisible = useCallback((value: boolean) => dispatch(setAlertFlyoutVisible(value)), [
dispatch,
]);
const { settings } = useSelector(selectDynamicSettings);
return (
<AlertTlsComponent
ageThreshold={settings?.certThresholds?.age}
expirationThreshold={settings?.certThresholds?.expiration}
setAlertFlyoutVisible={setFlyoutVisible}
/>
);
Comment on lines +14 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have been lately thinking, should we start using hooks for this pattern instead of container approach? I mean write a simple hook, which will dispatch action and return data, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea, and I think we should do it in the future; however, we are going to have some interesting state management concerns for these alert creation UIs post-FF because they don't currently work with the Edit feature on the management page (because our store isn't available there). This only came to my attention after we finished NP migration.

For the time being I think we should keep these presentational components relying solely on props, until we devise a solution with the alerting team.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it doesnt apply to this PR.

};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
*/

export { AlertMonitorStatus } from './alert_monitor_status';
export { ToggleAlertFlyoutButton } from './toggle_alert_flyout_button';
export {
ToggleAlertFlyoutButton,
ToggleAlertFlyoutButtonProps,
} from './toggle_alert_flyout_button';
export { UptimeAlertsFlyoutWrapper } from './uptime_alerts_flyout_wrapper';
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@

import React from 'react';
import { useDispatch } from 'react-redux';
import { setAlertFlyoutVisible } from '../../../../state/actions';
import { setAlertFlyoutType, setAlertFlyoutVisible } from '../../../../state/actions';
import { ToggleAlertFlyoutButtonComponent } from '../index';

export const ToggleAlertFlyoutButton = () => {
export interface ToggleAlertFlyoutButtonProps {
alertOptions?: string[];
}

export const ToggleAlertFlyoutButton: React.FC<ToggleAlertFlyoutButtonProps> = props => {
const dispatch = useDispatch();
return (
<ToggleAlertFlyoutButtonComponent
setAlertFlyoutVisible={(value: boolean) => dispatch(setAlertFlyoutVisible(value))}
{...props}
setAlertFlyoutVisible={(value: boolean | string) => {
if (typeof value === 'string') {
dispatch(setAlertFlyoutType(value));
dispatch(setAlertFlyoutVisible(true));
} else {
dispatch(setAlertFlyoutVisible(value));
}
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,22 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { setAlertFlyoutVisible } from '../../../../state/actions';
import { selectAlertFlyoutVisibility } from '../../../../state/selectors';
import { UptimeAlertsFlyoutWrapperComponent } from '../index';
import { UptimeAlertsFlyoutWrapperComponent } from '../uptime_alerts_flyout_wrapper';
import { selectAlertFlyoutVisibility, selectAlertFlyoutType } from '../../../../state/selectors';

interface Props {
alertTypeId?: string;
canChangeTrigger?: boolean;
}

export const UptimeAlertsFlyoutWrapper = ({ alertTypeId, canChangeTrigger }: Props) => {
export const UptimeAlertsFlyoutWrapper: React.FC = () => {
const dispatch = useDispatch();
const setAddFlyoutVisibility = (value: React.SetStateAction<boolean>) =>
// @ts-ignore the value here is a boolean, and it works with the action creator function
dispatch(setAlertFlyoutVisible(value));

const alertFlyoutVisible = useSelector(selectAlertFlyoutVisibility);
const alertTypeId = useSelector(selectAlertFlyoutType);

return (
<UptimeAlertsFlyoutWrapperComponent
alertFlyoutVisible={alertFlyoutVisible}
alertTypeId={alertTypeId}
canChangeTrigger={canChangeTrigger}
setAlertFlyoutVisibility={setAddFlyoutVisibility}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiExpression, EuiPopover } from '@elastic/eui';
import { Link } from 'react-router-dom';
import React, { useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { SETTINGS_ROUTE } from '../../../../common/constants';

interface SettingsMessageExpressionPopoverProps {
'aria-label': string;
description: string;
id: string;
setAlertFlyoutVisible: (value: boolean) => void;
value: string;
}

export const SettingsMessageExpressionPopover: React.FC<SettingsMessageExpressionPopoverProps> = ({
'aria-label': ariaLabel,
description,
setAlertFlyoutVisible,
value,
id,
}) => {
const [isOpen, setIsOpen] = useState(false);
return (
<EuiPopover
id={id}
anchorPosition="downLeft"
button={
<EuiExpression
aria-label={ariaLabel}
color="secondary"
description={description}
isActive={isOpen}
onClick={() => setIsOpen(!isOpen)}
value={value}
/>
}
isOpen={isOpen}
closePopover={() => setIsOpen(false)}
>
<FormattedMessage
id="xpack.uptime.alerts.tls.settingsPageNav.text"
defaultMessage="You can edit these thresholds on the {settingsPageLink}."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be less verbose?
instead of saying 'You can edit these thresholds on the settings page.'
You can edit this threshold in Settings. though i am not a native english speaker
so you probably know better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copy comes from the spec, so I think we can just leave it for now.

values={{
settingsPageLink: (
// this link is wrapped around a span so we can also change the UI state
// and hide the alert flyout before triggering the navigation to the settings page
<Link to={SETTINGS_ROUTE} data-test-subj="xpack.uptime.alerts.tlsFlyout.linkToSettings">
<span
onClick={() => {
setAlertFlyoutVisible(false);
}}
onKeyUp={e => {
if (e.key === 'Enter') {
setAlertFlyoutVisible(false);
}
}}
>
settings page
</span>
</Link>
),
}}
/>
</EuiPopover>
);
};
Loading