Skip to content

Commit c0b7f76

Browse files
authored
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.
1 parent c074e46 commit c0b7f76

File tree

3 files changed

+5
-47
lines changed

3 files changed

+5
-47
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
7777
static final Set<License.LicenseType> VALID_TRIAL_TYPES = Set.of(
7878
License.LicenseType.GOLD, License.LicenseType.PLATINUM, License.LicenseType.ENTERPRISE, License.LicenseType.TRIAL);
7979

80-
/**
81-
* Duration of grace period after a license has expired
82-
*/
83-
static final TimeValue GRACE_PERIOD_DURATION = days(7);
84-
8580
/**
8681
* Period before the license expires when warning starts being added to the response header
8782
*/
@@ -192,16 +187,9 @@ public void on(License license) {
192187
logExpirationWarning(license.expiryDate(), false);
193188
}
194189
});
195-
expirationCallbacks.add(new ExpirationCallback.Pre(days(0), days(7), TimeValue.timeValueMinutes(10)) {
196-
@Override
197-
public void on(License license) {
198-
logExpirationWarning(license.expiryDate(), false);
199-
}
200-
});
201190
expirationCallbacks.add(new ExpirationCallback.Post(days(0), null, TimeValue.timeValueMinutes(10)) {
202191
@Override
203192
public void on(License license) {
204-
// logged when grace period begins
205193
logExpirationWarning(license.expiryDate(), true);
206194
}
207195
});
@@ -486,22 +474,16 @@ protected void updateLicenseState(final License license, Version mostRecentTrial
486474
}
487475
if (license != null) {
488476
long time = clock.millis();
489-
boolean active;
477+
final boolean active;
490478
if (license.expiryDate() == BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS) {
491479
active = true;
492480
} else {
493-
// We subtract the grace period from the current time to avoid overflowing on an expiration
494-
// date that is near Long.MAX_VALUE
495-
active = time >= license.issueDate() && time - GRACE_PERIOD_DURATION.getMillis() < license.expiryDate();
481+
active = time >= license.issueDate() && time < license.expiryDate();
496482
}
497483
licenseState.update(license.operationMode(), active, license.expiryDate(), mostRecentTrialVersion);
498484

499485
if (active) {
500-
if (time < license.expiryDate()) {
501-
logger.debug("license [{}] - valid", license.uid());
502-
} else {
503-
logger.warn("license [{}] - grace", license.uid());
504-
}
486+
logger.debug("license [{}] - valid", license.uid());
505487
} else {
506488
logger.warn("license [{}] - expired", license.uid());
507489
}
@@ -552,8 +534,6 @@ static SchedulerEngine.Schedule nextLicenseCheck(License license) {
552534
return license.issueDate();
553535
} else if (time < license.expiryDate()) {
554536
return license.expiryDate();
555-
} else if (time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) {
556-
return license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
557537
}
558538
return -1; // license is expired, no need to check again
559539
};

x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseScheduleTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,8 @@ public void testEnabledLicenseSchedule() throws Exception {
3030
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime), equalTo(license.expiryDate()));
3131
}
3232

33-
public void testGraceLicenseSchedule() throws Exception {
34-
long triggeredTime = license.expiryDate() + between(1,
35-
((int) LicenseService.GRACE_PERIOD_DURATION.getMillis()));
36-
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
37-
equalTo(license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis()));
38-
}
39-
4033
public void testExpiredLicenseSchedule() throws Exception {
41-
long triggeredTime = license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis() +
42-
randomIntBetween(1, 1000);
34+
long triggeredTime = license.expiryDate() + randomIntBetween(1, 1000);
4335
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
4436
equalTo(-1L));
4537
}

x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseServiceClusterTests.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,12 @@ public void testClusterRestartWhileEnabled() throws Exception {
121121
assertLicenseActive(true);
122122
}
123123

124-
public void testClusterRestartWhileGrace() throws Exception {
125-
wipeAllLicenses();
126-
internalCluster().startNode();
127-
assertLicenseActive(true);
128-
putLicense(TestUtils.generateSignedLicense(TimeValue.timeValueMillis(0)));
129-
ensureGreen();
130-
assertLicenseActive(true);
131-
logger.info("--> restart node");
132-
internalCluster().fullRestart();
133-
ensureYellow();
134-
logger.info("--> await node for grace_period");
135-
assertLicenseActive(true);
136-
}
137-
138124
public void testClusterRestartWhileExpired() throws Exception {
139125
wipeAllLicenses();
140126
internalCluster().startNode();
141127
ensureGreen();
142128
assertLicenseActive(true);
143-
putLicense(TestUtils.generateExpiredNonBasicLicense(System.currentTimeMillis() - LicenseService.GRACE_PERIOD_DURATION.getMillis()));
129+
putLicense(TestUtils.generateExpiredNonBasicLicense(System.currentTimeMillis()));
144130
assertLicenseActive(false);
145131
logger.info("--> restart node");
146132
internalCluster().fullRestart();

0 commit comments

Comments
 (0)