forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Universal Profiling as Enterprise feature
With this commit we ensure that Universal Profiling can only be used with an Enterprise license.
- Loading branch information
1 parent
d214d74
commit d930fc5
Showing
14 changed files
with
313 additions
and
17 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
25 changes: 25 additions & 0 deletions
25
...nalClusterTest/java/org/elasticsearch/xpack/profiling/LocalStateProfilingXPackPlugin.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,25 @@ | ||
/* | ||
* 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.profiling; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class LocalStateProfilingXPackPlugin extends LocalStateCompositeXPackPlugin { | ||
public LocalStateProfilingXPackPlugin(final Settings settings, final Path configPath) { | ||
super(settings, configPath); | ||
plugins.add(new ProfilingPlugin(settings) { | ||
@Override | ||
protected ProfilingLicenseChecker createLicenseChecker() { | ||
return new ProfilingLicenseChecker(LocalStateProfilingXPackPlugin.this::getLicenseState); | ||
} | ||
}); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...ofiling/src/main/java/org/elasticsearch/xpack/profiling/ProfilingInfoTransportAction.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,49 @@ | ||
/* | ||
* 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.profiling; | ||
|
||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; | ||
import org.elasticsearch.xpack.core.action.XPackInfoFeatureTransportAction; | ||
|
||
public class ProfilingInfoTransportAction extends XPackInfoFeatureTransportAction { | ||
private final boolean enabled; | ||
private final ProfilingLicenseChecker licenseChecker; | ||
|
||
@Inject | ||
public ProfilingInfoTransportAction( | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
Settings settings, | ||
ProfilingLicenseChecker licenseChecker | ||
) { | ||
super(XPackInfoFeatureAction.UNIVERSAL_PROFILING.name(), transportService, actionFilters); | ||
this.enabled = XPackSettings.PROFILING_ENABLED.get(settings); | ||
this.licenseChecker = licenseChecker; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return XPackField.UNIVERSAL_PROFILING; | ||
} | ||
|
||
@Override | ||
public boolean available() { | ||
return licenseChecker.isSupportedLicense(); | ||
} | ||
|
||
@Override | ||
public boolean enabled() { | ||
return enabled; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...in/profiling/src/main/java/org/elasticsearch/xpack/profiling/ProfilingLicenseChecker.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,39 @@ | ||
/* | ||
* 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.profiling; | ||
|
||
import org.elasticsearch.license.License; | ||
import org.elasticsearch.license.LicenseUtils; | ||
import org.elasticsearch.license.LicensedFeature; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public final class ProfilingLicenseChecker { | ||
private static final LicensedFeature.Momentary UNIVERSAL_PROFILING_FEATURE = LicensedFeature.momentary( | ||
null, | ||
"universal_profiling", | ||
License.OperationMode.ENTERPRISE | ||
); | ||
|
||
private final Supplier<XPackLicenseState> licenseStateResolver; | ||
|
||
public ProfilingLicenseChecker(Supplier<XPackLicenseState> licenseStateResolver) { | ||
this.licenseStateResolver = licenseStateResolver; | ||
} | ||
|
||
public boolean isSupportedLicense() { | ||
return UNIVERSAL_PROFILING_FEATURE.checkWithoutTracking(licenseStateResolver.get()); | ||
} | ||
|
||
public void requireSupportedLicense() { | ||
if (UNIVERSAL_PROFILING_FEATURE.check(licenseStateResolver.get()) == false) { | ||
throw LicenseUtils.newComplianceException(UNIVERSAL_PROFILING_FEATURE.getName()); | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/ProfilingUsage.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,32 @@ | ||
/* | ||
* 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.profiling; | ||
|
||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.TransportVersions; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
|
||
import java.io.IOException; | ||
|
||
public class ProfilingUsage extends XPackFeatureSet.Usage { | ||
public ProfilingUsage(StreamInput input) throws IOException { | ||
super(input); | ||
} | ||
|
||
public ProfilingUsage(boolean available, boolean enabled) { | ||
super(XPackField.UNIVERSAL_PROFILING, available, enabled); | ||
} | ||
|
||
@Override | ||
public TransportVersion getMinimalSupportedVersion() { | ||
// TODO: This should probably say 8.11.0 but I'm not certain. Check with somebody what's appropriate. | ||
return TransportVersions.V_8_8_1; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...filing/src/main/java/org/elasticsearch/xpack/profiling/ProfilingUsageTransportAction.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,63 @@ | ||
/* | ||
* 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.profiling; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.protocol.xpack.XPackUsageRequest; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
import org.elasticsearch.xpack.core.action.XPackUsageFeatureAction; | ||
import org.elasticsearch.xpack.core.action.XPackUsageFeatureResponse; | ||
import org.elasticsearch.xpack.core.action.XPackUsageFeatureTransportAction; | ||
|
||
public class ProfilingUsageTransportAction extends XPackUsageFeatureTransportAction { | ||
private final ProfilingLicenseChecker licenseChecker; | ||
|
||
private final boolean enabled; | ||
|
||
@Inject | ||
public ProfilingUsageTransportAction( | ||
TransportService transportService, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ActionFilters actionFilters, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
ProfilingLicenseChecker licenseChecker, | ||
Settings settings | ||
) { | ||
super( | ||
XPackUsageFeatureAction.UNIVERSAL_PROFILING.name(), | ||
transportService, | ||
clusterService, | ||
threadPool, | ||
actionFilters, | ||
indexNameExpressionResolver | ||
); | ||
this.licenseChecker = licenseChecker; | ||
this.enabled = XPackSettings.PROFILING_ENABLED.get(settings); | ||
} | ||
|
||
@Override | ||
protected void masterOperation( | ||
Task task, | ||
XPackUsageRequest request, | ||
ClusterState state, | ||
ActionListener<XPackUsageFeatureResponse> listener | ||
) { | ||
ProfilingUsage profilingUsage = new ProfilingUsage(licenseChecker.isSupportedLicense(), enabled); | ||
listener.onResponse(new XPackUsageFeatureResponse(profilingUsage)); | ||
} | ||
} |
Oops, something went wrong.