Skip to content

Commit 8a8d868

Browse files
authored
[ML] stop using isAllowedByLicense for model license checks (#79908)
For trained models, there are both basic and platinum licenses allowed. We should track the feature usage check based on the license operation mode instead of using the underlying isAllowedByLicense. closes: #79811
1 parent 499f84a commit 8a8d868

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MachineLearningField.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.core.TimeValue;
1414
import org.elasticsearch.license.License;
1515
import org.elasticsearch.license.LicensedFeature;
16+
import org.elasticsearch.license.XPackLicenseState;
1617

1718
import java.math.BigInteger;
1819
import java.nio.charset.StandardCharsets;
@@ -40,6 +41,12 @@ public final class MachineLearningField {
4041
License.OperationMode.PLATINUM
4142
);
4243

44+
public static final LicensedFeature.Momentary ML_MODEL_INFERENCE_PLATINUM_FEATURE = LicensedFeature.momentary(
45+
MachineLearningField.ML_FEATURE_FAMILY,
46+
"model-inference-platinum-check",
47+
License.OperationMode.PLATINUM
48+
);
49+
4350
private MachineLearningField() {}
4451

4552
public static String valuesToId(String... values) {
@@ -51,4 +58,11 @@ public static String valuesToId(String... values) {
5158
System.arraycopy(Numbers.longToBytes(hash.h2), 0, hashedBytes, 8, 8);
5259
return new BigInteger(hashedBytes) + "_" + combined.length();
5360
}
61+
62+
public static boolean featureCheckForMode(License.OperationMode mode, XPackLicenseState licenseState) {
63+
if (mode.equals(License.OperationMode.PLATINUM)) {
64+
return ML_MODEL_INFERENCE_PLATINUM_FEATURE.check(licenseState);
65+
}
66+
return true;
67+
}
5468
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/inference/TrainedModelConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public long getEstimatedOperations() {
351351
}
352352

353353
// TODO if we ever support anything other than "basic" and platinum, we need to adjust our feature tracking logic
354+
// Additionally, see `MachineLearningField. featureCheckForMode` for handling modes
354355
public License.OperationMode getLicenseLevel() {
355356
return licenseLevel;
356357
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportInternalInferModelAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
4444
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
45+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.featureCheckForMode;
4546

4647
public class TransportInternalInferModelAction extends HandledTransportAction<Request, Response> {
4748

@@ -82,8 +83,9 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
8283
request.getModelId(),
8384
GetTrainedModelsAction.Includes.empty(),
8485
ActionListener.wrap(trainedModelConfig -> {
85-
responseBuilder.setLicensed(licenseState.isAllowedByLicense(trainedModelConfig.getLicenseLevel()));
86-
if (licenseState.isAllowedByLicense(trainedModelConfig.getLicenseLevel()) || request.isPreviouslyLicensed()) {
86+
final boolean allowed = featureCheckForMode(trainedModelConfig.getLicenseLevel(), licenseState);
87+
responseBuilder.setLicensed(allowed);
88+
if (allowed || request.isPreviouslyLicensed()) {
8789
doInfer(request, responseBuilder, listener);
8890
} else {
8991
listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING));

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutTrainedModelAliasAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.Set;
4848
import java.util.function.Predicate;
4949

50+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.featureCheckForMode;
5051
import static org.elasticsearch.xpack.core.ml.job.messages.Messages.TRAINED_MODEL_INPUTS_DIFFER_SIGNIFICANTLY;
5152

5253
public class TransportPutTrainedModelAliasAction extends AcknowledgedTransportMasterNodeAction<PutTrainedModelAliasAction.Request> {
@@ -91,7 +92,8 @@ protected void masterOperation(
9192
ActionListener<AcknowledgedResponse> listener
9293
) throws Exception {
9394
final boolean mlSupported = MachineLearningField.ML_API_FEATURE.check(licenseState);
94-
final Predicate<TrainedModelConfig> isLicensed = (model) -> mlSupported || licenseState.isAllowedByLicense(model.getLicenseLevel());
95+
final Predicate<TrainedModelConfig> isLicensed = (model) -> mlSupported
96+
|| featureCheckForMode(model.getLicenseLevel(), licenseState);
9597
final String oldModelId = ModelAliasMetadata.fromState(state).getModelId(request.getModelAlias());
9698

9799
if (oldModelId != null && (request.isReassign() == false)) {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/inference/InferencePipelineAggregationBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.function.Supplier;
5252

5353
import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
54+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.featureCheckForMode;
5455
import static org.elasticsearch.xpack.ml.utils.SecondaryAuthorizationUtils.useSecondaryAuthIfAvailable;
5556

5657
public class InferencePipelineAggregationBuilder extends AbstractPipelineAggregationBuilder<InferencePipelineAggregationBuilder> {
@@ -267,7 +268,7 @@ public InferencePipelineAggregationBuilder rewrite(QueryRewriteContext context)
267268
loadedModel.set(model);
268269

269270
boolean isLicensed = MachineLearningField.ML_API_FEATURE.check(licenseState)
270-
|| licenseState.isAllowedByLicense(model.getLicenseLevel());
271+
|| featureCheckForMode(model.getLicenseLevel(), licenseState);
271272
if (isLicensed) {
272273
delegate.onResponse(null);
273274
} else {

0 commit comments

Comments
 (0)