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

[Monitoring] Fix issues with show_license_expiration #84361

Merged
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 @@ -230,6 +230,46 @@ export function ElasticsearchPanel(props) {
return null;
};

const showLicense = () => {
if (!props.showLicenseExpiration) {
return null;
}
return (
<Fragment>
<EuiDescriptionListTitle className="eui-textBreakWord">
<FormattedMessage
id="xpack.monitoring.cluster.overview.esPanel.licenseLabel"
defaultMessage="License"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription data-test-subj="esLicenseType">
<EuiFlexGroup direction="column" gutterSize="xs">
<EuiFlexItem grow={false}>
<EuiLink href={getSafeForExternalLink('#/license')}>
{capitalize(props.license.type)}
</EuiLink>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s">
{props.license.expiry_date_in_millis === undefined ? (
''
) : (
<FormattedMessage
id="xpack.monitoring.cluster.overview.esPanel.expireDateText"
defaultMessage="expires on {expiryDate}"
values={{
expiryDate: formatDateLocal(props.license.expiry_date_in_millis),
}}
/>
)}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiDescriptionListDescription>
</Fragment>
);
};

const statusColorMap = {
green: 'success',
yellow: 'warning',
Expand Down Expand Up @@ -325,36 +365,7 @@ export function ElasticsearchPanel(props) {
{formatNumber(get(nodes, 'jvm.max_uptime_in_millis'), 'time_since')}
</EuiDescriptionListDescription>
{showMlJobs()}
<EuiDescriptionListTitle className="eui-textBreakWord">
<FormattedMessage
id="xpack.monitoring.cluster.overview.esPanel.licenseLabel"
defaultMessage="License"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription data-test-subj="esLicenseType">
<EuiFlexGroup direction="column" gutterSize="xs">
<EuiFlexItem grow={false}>
<EuiLink href={getSafeForExternalLink('#/license')}>
{capitalize(props.license.type)}
</EuiLink>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s">
{props.license.expiry_date_in_millis === undefined ? (
''
) : (
<FormattedMessage
id="xpack.monitoring.cluster.overview.esPanel.expireDateText"
defaultMessage="expires on {expiryDate}"
values={{
expiryDate: formatDateLocal(props.license.expiry_date_in_millis),
}}
/>
)}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiDescriptionListDescription>
{showLicense()}
</EuiDescriptionList>
</EuiPanel>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('LicenseExpirationAlert', () => {
const monitoringCluster = null;
const config = {
ui: {
show_license_expiration: true,
ccs: { enabled: true },
container: { elasticsearch: { enabled: false } },
metricbeat: { index: 'metricbeat-*' },
Expand Down Expand Up @@ -282,5 +283,32 @@ describe('LicenseExpirationAlert', () => {
state: 'resolved',
});
});

it('should not fire actions if we are not showing license expiration', async () => {
const alert = new LicenseExpirationAlert();
const customConfig = {
...config,
ui: {
...config.ui,
show_license_expiration: false,
},
};
alert.initializeAlertType(
getUiSettingsService as any,
monitoringCluster as any,
getLogger as any,
customConfig as any,
kibanaUrl,
false
);
const type = alert.getAlertType();
await type.executor({
...executorOptions,
// @ts-ignore
params: alert.defaultParams,
} as any);
expect(replaceState).not.toHaveBeenCalledWith({});
expect(scheduleActions).not.toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
LegacyAlert,
CommonAlertParams,
} from '../../common/types/alerts';
import { AlertInstance } from '../../../alerts/server';
import { AlertExecutorOptions, AlertInstance } from '../../../alerts/server';
import {
INDEX_ALERTS,
ALERT_LICENSE_EXPIRATION,
Expand Down Expand Up @@ -64,6 +64,13 @@ export class LicenseExpirationAlert extends BaseAlert {
AlertingDefaults.ALERT_TYPE.context.actionPlain,
];

protected async execute(options: AlertExecutorOptions): Promise<any> {
if (!this.config.ui.show_license_expiration) {
return;
}
return await super.execute(options);
}

protected async fetchData(
params: CommonAlertParams,
callCluster: any,
Expand Down