Skip to content

[ML] simplifying model license checks #80031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicensedFeature;
import org.elasticsearch.license.XPackLicenseState;

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -41,12 +40,6 @@ public final class MachineLearningField {
License.OperationMode.PLATINUM
);

public static final LicensedFeature.Momentary ML_MODEL_INFERENCE_PLATINUM_FEATURE = LicensedFeature.momentary(
MachineLearningField.ML_FEATURE_FAMILY,
"model-inference-platinum-check",
License.OperationMode.PLATINUM
);

private MachineLearningField() {}

public static String valuesToId(String... values) {
Expand All @@ -59,10 +52,4 @@ public static String valuesToId(String... values) {
return new BigInteger(hashedBytes) + "_" + combined.length();
}

public static boolean featureCheckForMode(License.OperationMode mode, XPackLicenseState licenseState) {
if (mode.equals(License.OperationMode.PLATINUM)) {
return ML_MODEL_INFERENCE_PLATINUM_FEATURE.check(licenseState);
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public long getEstimatedOperations() {
}

// TODO if we ever support anything other than "basic" and platinum, we need to adjust our feature tracking logic
// Additionally, see `MachineLearningField. featureCheckForMode` for handling modes
// and we need to adjust our license checks to validate more than "is basic" or not
public License.OperationMode getLicenseLevel() {
return licenseLevel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -42,7 +43,6 @@

import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN;
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.featureCheckForMode;

public class TransportInternalInferModelAction extends HandledTransportAction<Request, Response> {

Expand Down Expand Up @@ -83,7 +83,9 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
request.getModelId(),
GetTrainedModelsAction.Includes.empty(),
ActionListener.wrap(trainedModelConfig -> {
final boolean allowed = featureCheckForMode(trainedModelConfig.getLicenseLevel(), licenseState);
// Since we just checked MachineLearningField.ML_API_FEATURE.check(licenseState) and that check failed
// That means we don't have a plat+ license. The only licenses for trained models are basic (free) and plat.
boolean allowed = trainedModelConfig.getLicenseLevel() == License.OperationMode.BASIC;
responseBuilder.setLicensed(allowed);
if (allowed || request.isPreviouslyLicensed()) {
doInfer(request, responseBuilder, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.HeaderWarning;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.tasks.Task;
Expand All @@ -47,7 +48,6 @@
import java.util.Set;
import java.util.function.Predicate;

import static org.elasticsearch.xpack.core.ml.MachineLearningField.featureCheckForMode;
import static org.elasticsearch.xpack.core.ml.job.messages.Messages.TRAINED_MODEL_INPUTS_DIFFER_SIGNIFICANTLY;

public class TransportPutTrainedModelAliasAction extends AcknowledgedTransportMasterNodeAction<PutTrainedModelAliasAction.Request> {
Expand Down Expand Up @@ -93,7 +93,8 @@ protected void masterOperation(
) throws Exception {
final boolean mlSupported = MachineLearningField.ML_API_FEATURE.check(licenseState);
final Predicate<TrainedModelConfig> isLicensed = (model) -> mlSupported
|| featureCheckForMode(model.getLicenseLevel(), licenseState);
// Either we support plat+ or the model is basic licensed
|| model.getLicenseLevel() == License.OperationMode.BASIC;
final String oldModelId = ModelAliasMetadata.fromState(state).getModelId(request.getModelAlias());

if (oldModelId != null && (request.isReassign() == false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryRewriteContext;
import org.elasticsearch.license.License;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.plugins.SearchPlugin;
Expand Down Expand Up @@ -51,7 +52,6 @@
import java.util.function.Supplier;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xpack.core.ml.MachineLearningField.featureCheckForMode;
import static org.elasticsearch.xpack.ml.utils.SecondaryAuthorizationUtils.useSecondaryAuthIfAvailable;

public class InferencePipelineAggregationBuilder extends AbstractPipelineAggregationBuilder<InferencePipelineAggregationBuilder> {
Expand Down Expand Up @@ -267,8 +267,8 @@ public InferencePipelineAggregationBuilder rewrite(QueryRewriteContext context)
.getModelForSearch(modelId, listener.delegateFailure((delegate, model) -> {
loadedModel.set(model);

boolean isLicensed = MachineLearningField.ML_API_FEATURE.check(licenseState)
|| featureCheckForMode(model.getLicenseLevel(), licenseState);
boolean isLicensed = model.getLicenseLevel() == License.OperationMode.BASIC
|| MachineLearningField.ML_API_FEATURE.check(licenseState);
if (isLicensed) {
delegate.onResponse(null);
} else {
Expand Down