Skip to content

Commit 15b0340

Browse files
authored
[GPU] Licensing checks via LicensedFeature (#139142)
This PR changes the gpu plugin license check to use a LicensedFeature, so users can get feedback messages when the license becomes invalid/expires, like for other x-pack features. To ensure better feedback, it also updates the check logic used to return GPU-enabled vector formats/codecs with errors and warnings in case other conditions are met, but we lack a correct license.
1 parent 3e88ded commit 15b0340

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class XPackLicenseState {
8686
);
8787
messages.put(XPackField.REDACT_PROCESSOR, new String[] { "Executing a redact processor in an ingest pipeline will fail." });
8888
messages.put(XPackField.INFERENCE, new String[] { "The Inference API is disabled" });
89+
messages.put(XPackField.GPU_INDEXING, new String[] { "Indexing using a GPU is disabled." });
8990
EXPIRATION_MESSAGES = Collections.unmodifiableMap(messages);
9091
}
9192

@@ -109,6 +110,7 @@ public class XPackLicenseState {
109110
messages.put(XPackField.REDACT_PROCESSOR, XPackLicenseState::redactProcessorAcknowledgementMessages);
110111
messages.put(XPackField.ESQL, XPackLicenseState::esqlAcknowledgementMessages);
111112
messages.put(XPackField.INFERENCE, XPackLicenseState::inferenceApiAcknowledgementMessages);
113+
messages.put(XPackField.GPU_INDEXING, XPackLicenseState::gpuIndexingAcknowledgementMessages);
112114
ACKNOWLEDGMENT_MESSAGES = Collections.unmodifiableMap(messages);
113115
}
114116

@@ -376,6 +378,22 @@ private static String[] redactProcessorAcknowledgementMessages(OperationMode cur
376378
return Strings.EMPTY_ARRAY;
377379
}
378380

381+
private static String[] gpuIndexingAcknowledgementMessages(OperationMode currentMode, OperationMode newMode) {
382+
switch (newMode) {
383+
case BASIC:
384+
case STANDARD:
385+
case GOLD:
386+
case PLATINUM:
387+
switch (currentMode) {
388+
case TRIAL:
389+
case ENTERPRISE:
390+
return new String[] { "Indexing using a GPU will be disabled" };
391+
}
392+
break;
393+
}
394+
return Strings.EMPTY_ARRAY;
395+
}
396+
379397
private static boolean isBasic(OperationMode mode) {
380398
return mode == OperationMode.BASIC;
381399
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public final class XPackField {
9494

9595
/** Name constant for the redact processor feature. */
9696
public static final String REDACT_PROCESSOR = "redact_processor";
97+
/** Name constant for the GPU indexing feature. */
98+
public static final String GPU_INDEXING = "gpu_indexing";
9799
public static final String ENTERPRISE_GEOIP_DOWNLOADER = "enterprise_geoip_downloader";
98100
/** Name for Universal Profiling. */
99101
public static final String UNIVERSAL_PROFILING = "universal_profiling";

x-pack/plugin/gpu/src/main/java/org/elasticsearch/xpack/gpu/GPUPlugin.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,34 @@
1414
import org.elasticsearch.common.settings.Setting;
1515
import org.elasticsearch.common.settings.Settings;
1616
import org.elasticsearch.common.util.FeatureFlag;
17+
import org.elasticsearch.core.Strings;
1718
import org.elasticsearch.gpu.GPUSupport;
1819
import org.elasticsearch.gpu.codec.ES92GpuHnswSQVectorsFormat;
1920
import org.elasticsearch.gpu.codec.ES92GpuHnswVectorsFormat;
2021
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
2122
import org.elasticsearch.index.mapper.vectors.VectorsFormatProvider;
2223
import org.elasticsearch.license.License;
24+
import org.elasticsearch.license.LicensedFeature;
25+
import org.elasticsearch.logging.LogManager;
26+
import org.elasticsearch.logging.Logger;
2327
import org.elasticsearch.plugins.Plugin;
2428
import org.elasticsearch.plugins.internal.InternalVectorFormatProviderPlugin;
29+
import org.elasticsearch.xpack.core.XPackField;
2530
import org.elasticsearch.xpack.core.XPackPlugin;
2631

2732
import java.util.List;
2833

2934
public class GPUPlugin extends Plugin implements InternalVectorFormatProviderPlugin {
3035

36+
private static final Logger log = LogManager.getLogger(GPUPlugin.class);
37+
3138
public static final FeatureFlag GPU_FORMAT = new FeatureFlag("gpu_vectors_indexing");
3239

33-
private static final License.OperationMode MINIMUM_ALLOWED_LICENSE = License.OperationMode.ENTERPRISE;
40+
public static final LicensedFeature.Momentary GPU_INDEXING_FEATURE = LicensedFeature.momentary(
41+
null,
42+
XPackField.GPU_INDEXING,
43+
License.OperationMode.ENTERPRISE
44+
);
3445

3546
private final GpuMode gpuMode;
3647

@@ -75,7 +86,7 @@ public List<Setting<?>> getSettings() {
7586
// Allow tests to override the license state
7687
protected boolean isGpuIndexingFeatureAllowed() {
7788
var licenseState = XPackPlugin.getSharedLicenseState();
78-
return licenseState != null && licenseState.isAllowedByLicense(MINIMUM_ALLOWED_LICENSE);
89+
return licenseState != null && GPU_INDEXING_FEATURE.check(licenseState);
7990
}
8091

8192
@Override
@@ -115,10 +126,25 @@ public ReferenceDocs referenceDocs() {
115126
@Override
116127
public VectorsFormatProvider getVectorsFormatProvider() {
117128
return (indexSettings, indexOptions, similarity, elementType) -> {
118-
if (GPU_FORMAT.isEnabled() && isGpuIndexingFeatureAllowed()) {
119-
if ((gpuMode == GpuMode.TRUE || (gpuMode == GpuMode.AUTO && GPUSupport.isSupported()))
120-
&& vectorIndexAndElementTypeSupported(indexOptions.getType(), elementType)) {
121-
return getVectorsFormat(indexOptions, similarity);
129+
if (GPU_FORMAT.isEnabled()) {
130+
if (vectorIndexAndElementTypeSupported(indexOptions.getType(), elementType) == false) {
131+
return null;
132+
}
133+
134+
if (gpuMode == GpuMode.TRUE || (gpuMode == GpuMode.AUTO && GPUSupport.isSupported())) {
135+
assert GPUSupport.isSupported();
136+
if (isGpuIndexingFeatureAllowed()) {
137+
return getVectorsFormat(indexOptions, similarity);
138+
} else {
139+
log.warn(
140+
Strings.format(
141+
"The current configuration supports GPU indexing, but it is not allowed by the current license. "
142+
+ "If this is intentional, it is possible to suppress this message by setting [%s] to FALSE",
143+
VECTORS_INDEXING_USE_GPU_NODE_SETTING.getKey()
144+
)
145+
);
146+
return null;
147+
}
122148
}
123149
}
124150
return null;

0 commit comments

Comments
 (0)