From c0b7f7674d661bdc848502cb1d298d2f18b56b2c Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 11 Feb 2021 16:21:53 -0800 Subject: [PATCH] Remove grace period from license expiration check (#67316) License expiration checking currently has a 7 day grace period. When a license expires, the licensing code acts as if it is not yet expired. This was originally intended to protect users who may accidentally end up letting their license expire from the pain of their licensed features ceasing to work. However, the grace period effectively shifts the license expiration by a week, resulting in confusion since the actual license expiration date is not accurate. It also is less of a concern now as not only do we emit several warnings for upcoming license expiration, but the new license can be downloaded and installed quickly by the user through the support portal. This commit removes the license grace period altogether. --- .../elasticsearch/license/LicenseService.java | 26 +++---------------- .../license/LicenseScheduleTests.java | 10 +------ .../license/LicenseServiceClusterTests.java | 16 +----------- 3 files changed, 5 insertions(+), 47 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java index a1d15800a6181..effcbaf782386 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java @@ -77,11 +77,6 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste static final Set VALID_TRIAL_TYPES = Set.of( License.LicenseType.GOLD, License.LicenseType.PLATINUM, License.LicenseType.ENTERPRISE, License.LicenseType.TRIAL); - /** - * Duration of grace period after a license has expired - */ - static final TimeValue GRACE_PERIOD_DURATION = days(7); - /** * Period before the license expires when warning starts being added to the response header */ @@ -192,16 +187,9 @@ public void on(License license) { logExpirationWarning(license.expiryDate(), false); } }); - expirationCallbacks.add(new ExpirationCallback.Pre(days(0), days(7), TimeValue.timeValueMinutes(10)) { - @Override - public void on(License license) { - logExpirationWarning(license.expiryDate(), false); - } - }); expirationCallbacks.add(new ExpirationCallback.Post(days(0), null, TimeValue.timeValueMinutes(10)) { @Override public void on(License license) { - // logged when grace period begins logExpirationWarning(license.expiryDate(), true); } }); @@ -486,22 +474,16 @@ protected void updateLicenseState(final License license, Version mostRecentTrial } if (license != null) { long time = clock.millis(); - boolean active; + final boolean active; if (license.expiryDate() == BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS) { active = true; } else { - // We subtract the grace period from the current time to avoid overflowing on an expiration - // date that is near Long.MAX_VALUE - active = time >= license.issueDate() && time - GRACE_PERIOD_DURATION.getMillis() < license.expiryDate(); + active = time >= license.issueDate() && time < license.expiryDate(); } licenseState.update(license.operationMode(), active, license.expiryDate(), mostRecentTrialVersion); if (active) { - if (time < license.expiryDate()) { - logger.debug("license [{}] - valid", license.uid()); - } else { - logger.warn("license [{}] - grace", license.uid()); - } + logger.debug("license [{}] - valid", license.uid()); } else { logger.warn("license [{}] - expired", license.uid()); } @@ -552,8 +534,6 @@ static SchedulerEngine.Schedule nextLicenseCheck(License license) { return license.issueDate(); } else if (time < license.expiryDate()) { return license.expiryDate(); - } else if (time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) { - return license.expiryDate() + GRACE_PERIOD_DURATION.getMillis(); } return -1; // license is expired, no need to check again }; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseScheduleTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseScheduleTests.java index 2fba2358a281c..d607f27069313 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseScheduleTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseScheduleTests.java @@ -30,16 +30,8 @@ public void testEnabledLicenseSchedule() throws Exception { assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime), equalTo(license.expiryDate())); } - public void testGraceLicenseSchedule() throws Exception { - long triggeredTime = license.expiryDate() + between(1, - ((int) LicenseService.GRACE_PERIOD_DURATION.getMillis())); - assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime), - equalTo(license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis())); - } - public void testExpiredLicenseSchedule() throws Exception { - long triggeredTime = license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis() + - randomIntBetween(1, 1000); + long triggeredTime = license.expiryDate() + randomIntBetween(1, 1000); assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime), equalTo(-1L)); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java index 77bb09958513c..e23aab25e7bc3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java @@ -121,26 +121,12 @@ public void testClusterRestartWhileEnabled() throws Exception { assertLicenseActive(true); } - public void testClusterRestartWhileGrace() throws Exception { - wipeAllLicenses(); - internalCluster().startNode(); - assertLicenseActive(true); - putLicense(TestUtils.generateSignedLicense(TimeValue.timeValueMillis(0))); - ensureGreen(); - assertLicenseActive(true); - logger.info("--> restart node"); - internalCluster().fullRestart(); - ensureYellow(); - logger.info("--> await node for grace_period"); - assertLicenseActive(true); - } - public void testClusterRestartWhileExpired() throws Exception { wipeAllLicenses(); internalCluster().startNode(); ensureGreen(); assertLicenseActive(true); - putLicense(TestUtils.generateExpiredNonBasicLicense(System.currentTimeMillis() - LicenseService.GRACE_PERIOD_DURATION.getMillis())); + putLicense(TestUtils.generateExpiredNonBasicLicense(System.currentTimeMillis())); assertLicenseActive(false); logger.info("--> restart node"); internalCluster().fullRestart();