Skip to content

Commit a3f2f40

Browse files
authored
Add native code info to ML info api (#43172)
The machine learning feature of xpack has native binaries with a different commit id than the rest of code. It is currently exposed in the xpack info api. This commit adds that commit information to the ML info api, so that it may be removed from the info api.
1 parent d9dbf79 commit a3f2f40

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docs/reference/ml/apis/get-ml-info.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ This is a possible response:
5757
}
5858
},
5959
"upgrade_mode": false,
60+
"native_code" : {
61+
"version": "7.0.0",
62+
"build_hash": "99a07c016d5a73"
63+
},
6064
"limits" : { }
6165
}
6266
----
6367
// TESTRESPONSE[s/"upgrade_mode": false/"upgrade_mode": $body.upgrade_mode/]
68+
// TESTRESPONSE[s/"version": "7.0.0",/"version": "$body.native_code.version",/]
69+
// TESTRESPONSE[s/"build_hash": "99a07c016d5a73"/"build_hash": "$body.native_code.build_hash"/]

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.inject.Inject;
1313
import org.elasticsearch.common.unit.ByteSizeUnit;
1414
import org.elasticsearch.common.unit.ByteSizeValue;
15+
import org.elasticsearch.env.Environment;
1516
import org.elasticsearch.tasks.Task;
1617
import org.elasticsearch.transport.TransportService;
1718
import org.elasticsearch.xpack.core.ml.MachineLearningField;
@@ -20,26 +21,51 @@
2021
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
2122
import org.elasticsearch.xpack.core.ml.job.config.AnalysisLimits;
2223
import org.elasticsearch.xpack.core.ml.job.config.Job;
24+
import org.elasticsearch.xpack.ml.process.NativeController;
25+
import org.elasticsearch.xpack.ml.process.NativeControllerHolder;
2326

27+
import java.io.IOException;
28+
import java.util.Collections;
2429
import java.util.HashMap;
2530
import java.util.Map;
31+
import java.util.concurrent.TimeoutException;
2632
import java.util.function.Supplier;
2733

2834
public class TransportMlInfoAction extends HandledTransportAction<MlInfoAction.Request, MlInfoAction.Response> {
2935

3036
private final ClusterService clusterService;
37+
private final Map<String, Object> nativeCodeInfo;
3138

3239
@Inject
33-
public TransportMlInfoAction(TransportService transportService, ActionFilters actionFilters, ClusterService clusterService) {
40+
public TransportMlInfoAction(TransportService transportService, ActionFilters actionFilters,
41+
ClusterService clusterService, Environment env) {
3442
super(MlInfoAction.NAME, transportService, actionFilters, (Supplier<MlInfoAction.Request>) MlInfoAction.Request::new);
3543
this.clusterService = clusterService;
44+
45+
try {
46+
NativeController nativeController = NativeControllerHolder.getNativeController(clusterService.getNodeName(), env);
47+
// TODO: this leniency is only for tests. it can be removed when NativeController is created as a component and
48+
// becomes a ctor arg to this action
49+
if (nativeController != null) {
50+
nativeCodeInfo = nativeController.getNativeCodeInfo();
51+
} else {
52+
nativeCodeInfo = Collections.emptyMap();
53+
}
54+
} catch (IOException e) {
55+
// this should not be possible since this action is only registered when ML is enabled,
56+
// and the MachineLearning plugin would have failed to create components
57+
throw new IllegalStateException("native controller failed to load", e);
58+
} catch (TimeoutException e) {
59+
throw new RuntimeException("Could not get native code info from native controller", e);
60+
}
3661
}
3762

3863
@Override
3964
protected void doExecute(Task task, MlInfoAction.Request request, ActionListener<MlInfoAction.Response> listener) {
4065
Map<String, Object> info = new HashMap<>();
4166
info.put("defaults", defaults());
4267
info.put("limits", limits());
68+
info.put("native_code", nativeCodeInfo);
4369
info.put(MlMetadata.UPGRADE_MODE.getPreferredName(), upgradeMode());
4470
listener.onResponse(new MlInfoAction.Response(info));
4571
}

0 commit comments

Comments
 (0)