forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust SyntheticSourceLicenseService (elastic#116647)
Allow gold and platinum license to use synthetic source for a limited time. If the start time of a license is before the cut off date, then gold and platinum licenses will not fallback to stored source if synthetic source is used. Co-authored-by: Nikolaj Volgushev <[email protected]>
- Loading branch information
Showing
7 changed files
with
562 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...in/logsdb/src/test/java/org/elasticsearch/xpack/logsdb/LegacyLicenceIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.logsdb; | ||
|
||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.mapper.SourceFieldMapper; | ||
import org.elasticsearch.license.AbstractLicensesIntegrationTestCase; | ||
import org.elasticsearch.license.GetFeatureUsageRequest; | ||
import org.elasticsearch.license.GetFeatureUsageResponse; | ||
import org.elasticsearch.license.License; | ||
import org.elasticsearch.license.LicenseService; | ||
import org.elasticsearch.license.LicensedFeature; | ||
import org.elasticsearch.license.TransportGetFeatureUsageAction; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; | ||
import org.hamcrest.Matcher; | ||
import org.junit.Before; | ||
|
||
import java.nio.file.Path; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST; | ||
import static org.elasticsearch.xpack.logsdb.SyntheticSourceLicenseServiceTests.createEnterpriseLicense; | ||
import static org.elasticsearch.xpack.logsdb.SyntheticSourceLicenseServiceTests.createGoldOrPlatinumLicense; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = TEST, numDataNodes = 1, numClientNodes = 0, supportsDedicatedMasters = false) | ||
public class LegacyLicenceIntegrationTests extends AbstractLicensesIntegrationTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return List.of(P.class); | ||
} | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
wipeAllLicenses(); | ||
ensureGreen(); | ||
License license = createGoldOrPlatinumLicense(); | ||
putLicense(license); | ||
ensureGreen(); | ||
} | ||
|
||
public void testSyntheticSourceUsageDisallowed() { | ||
createIndexWithSyntheticSourceAndAssertExpectedType("test", "STORED"); | ||
|
||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY, nullValue()); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE, nullValue()); | ||
} | ||
|
||
public void testSyntheticSourceUsageWithLegacyLicense() { | ||
createIndexWithSyntheticSourceAndAssertExpectedType(".profiling-stacktraces", "synthetic"); | ||
|
||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY, not(nullValue())); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE, nullValue()); | ||
} | ||
|
||
public void testSyntheticSourceUsageWithLegacyLicensePastCutoff() throws Exception { | ||
long startPastCutoff = LocalDateTime.of(2025, 11, 12, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli(); | ||
putLicense(createGoldOrPlatinumLicense(startPastCutoff)); | ||
ensureGreen(); | ||
|
||
createIndexWithSyntheticSourceAndAssertExpectedType(".profiling-stacktraces", "STORED"); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY, nullValue()); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE, nullValue()); | ||
} | ||
|
||
public void testSyntheticSourceUsageWithEnterpriseLicensePastCutoff() throws Exception { | ||
long startPastCutoff = LocalDateTime.of(2025, 11, 12, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli(); | ||
putLicense(createEnterpriseLicense(startPastCutoff)); | ||
ensureGreen(); | ||
|
||
createIndexWithSyntheticSourceAndAssertExpectedType(".profiling-traces", "synthetic"); | ||
// also supports non-exceptional indices | ||
createIndexWithSyntheticSourceAndAssertExpectedType("test", "synthetic"); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY, nullValue()); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE, not(nullValue())); | ||
} | ||
|
||
public void testSyntheticSourceUsageTracksBothLegacyAndRegularFeature() throws Exception { | ||
createIndexWithSyntheticSourceAndAssertExpectedType(".profiling-traces", "synthetic"); | ||
|
||
putLicense(createEnterpriseLicense()); | ||
ensureGreen(); | ||
|
||
createIndexWithSyntheticSourceAndAssertExpectedType(".profiling-traces-v2", "synthetic"); | ||
|
||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY, not(nullValue())); | ||
assertFeatureUsage(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE, not(nullValue())); | ||
} | ||
|
||
private void createIndexWithSyntheticSourceAndAssertExpectedType(String indexName, String expectedType) { | ||
var settings = Settings.builder().put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic").build(); | ||
createIndex(indexName, settings); | ||
var response = admin().indices().getSettings(new GetSettingsRequest().indices(indexName)).actionGet(); | ||
assertThat( | ||
response.getIndexToSettings().get(indexName).get(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey()), | ||
equalTo(expectedType) | ||
); | ||
} | ||
|
||
private List<GetFeatureUsageResponse.FeatureUsageInfo> getFeatureUsageInfo() { | ||
return client().execute(TransportGetFeatureUsageAction.TYPE, new GetFeatureUsageRequest()).actionGet().getFeatures(); | ||
} | ||
|
||
private void assertFeatureUsage(LicensedFeature.Momentary syntheticSourceFeature, Matcher<Object> matcher) { | ||
GetFeatureUsageResponse.FeatureUsageInfo featureUsage = getFeatureUsageInfo().stream() | ||
.filter(f -> f.getFamily().equals(SyntheticSourceLicenseService.MAPPINGS_FEATURE_FAMILY)) | ||
.filter(f -> f.getName().equals(syntheticSourceFeature.getName())) | ||
.findAny() | ||
.orElse(null); | ||
assertThat(featureUsage, matcher); | ||
} | ||
|
||
public static class P extends LocalStateCompositeXPackPlugin { | ||
|
||
public P(final Settings settings, final Path configPath) { | ||
super(settings, configPath); | ||
plugins.add(new LogsDBPlugin(settings) { | ||
@Override | ||
protected XPackLicenseState getLicenseState() { | ||
return P.this.getLicenseState(); | ||
} | ||
|
||
@Override | ||
protected LicenseService getLicenseService() { | ||
return P.this.getLicenseService(); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.