Skip to content

Commit

Permalink
Remove grace period from license expiration check (#67316)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjernst committed Feb 12, 2021
1 parent 2fde28e commit 3c4d76a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
static final Set<License.LicenseType> VALID_TRIAL_TYPES = Collections.unmodifiableSet(Sets.newHashSet(
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
*/
Expand Down Expand Up @@ -193,16 +188,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);
}
});
Expand Down Expand Up @@ -487,22 +475,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());
}
Expand Down Expand Up @@ -553,8 +535,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
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,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();
Expand Down

0 comments on commit 3c4d76a

Please sign in to comment.