Skip to content

Commit

Permalink
Fix issues with show_license_expiration (#84361)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline authored Nov 25, 2020
1 parent 5fda300 commit dfa9c75
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 31 deletions.
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

0 comments on commit dfa9c75

Please sign in to comment.