|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
package org.elasticsearch.xpack.core.ml.inference.allocation;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
@@ -33,6 +34,8 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
private final Integer pendingCount;
|
|
|
private final RoutingStateAndReason routingState;
|
|
|
private final Instant startTime;
|
|
|
+ private final Integer inferenceThreads;
|
|
|
+ private final Integer modelThreads;
|
|
|
|
|
|
public static AllocationStats.NodeStats forStartedState(
|
|
|
DiscoveryNode node,
|
|
@@ -40,7 +43,9 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
Double avgInferenceTime,
|
|
|
int pendingCount,
|
|
|
Instant lastAccess,
|
|
|
- Instant startTime
|
|
|
+ Instant startTime,
|
|
|
+ Integer inferenceThreads,
|
|
|
+ Integer modelThreads
|
|
|
) {
|
|
|
return new AllocationStats.NodeStats(
|
|
|
node,
|
|
@@ -49,22 +54,26 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
lastAccess,
|
|
|
pendingCount,
|
|
|
new RoutingStateAndReason(RoutingState.STARTED, null),
|
|
|
- Objects.requireNonNull(startTime)
|
|
|
+ Objects.requireNonNull(startTime),
|
|
|
+ inferenceThreads,
|
|
|
+ modelThreads
|
|
|
);
|
|
|
}
|
|
|
|
|
|
public static AllocationStats.NodeStats forNotStartedState(DiscoveryNode node, RoutingState state, String reason) {
|
|
|
- return new AllocationStats.NodeStats(node, null, null, null, null, new RoutingStateAndReason(state, reason), null);
|
|
|
+ return new AllocationStats.NodeStats(node, null, null, null, null, new RoutingStateAndReason(state, reason), null, null, null);
|
|
|
}
|
|
|
|
|
|
- private NodeStats(
|
|
|
+ public NodeStats(
|
|
|
DiscoveryNode node,
|
|
|
Long inferenceCount,
|
|
|
Double avgInferenceTime,
|
|
|
Instant lastAccess,
|
|
|
Integer pendingCount,
|
|
|
RoutingStateAndReason routingState,
|
|
|
- @Nullable Instant startTime
|
|
|
+ @Nullable Instant startTime,
|
|
|
+ @Nullable Integer inferenceThreads,
|
|
|
+ @Nullable Integer modelThreads
|
|
|
) {
|
|
|
this.node = node;
|
|
|
this.inferenceCount = inferenceCount;
|
|
@@ -73,6 +82,8 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
this.pendingCount = pendingCount;
|
|
|
this.routingState = routingState;
|
|
|
this.startTime = startTime;
|
|
|
+ this.inferenceThreads = inferenceThreads;
|
|
|
+ this.modelThreads = modelThreads;
|
|
|
|
|
|
// if lastAccess time is null there have been no inferences
|
|
|
assert this.lastAccess != null || (inferenceCount == null || inferenceCount == 0);
|
|
@@ -86,6 +97,14 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
this.pendingCount = in.readOptionalVInt();
|
|
|
this.routingState = in.readOptionalWriteable(RoutingStateAndReason::new);
|
|
|
this.startTime = in.readOptionalInstant();
|
|
|
+
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_8_1_0)) {
|
|
|
+ this.inferenceThreads = in.readOptionalVInt();
|
|
|
+ this.modelThreads = in.readOptionalVInt();
|
|
|
+ } else {
|
|
|
+ this.inferenceThreads = null;
|
|
|
+ this.modelThreads = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public DiscoveryNode getNode() {
|
|
@@ -104,6 +123,18 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
return Optional.ofNullable(avgInferenceTime);
|
|
|
}
|
|
|
|
|
|
+ public Instant getLastAccess() {
|
|
|
+ return lastAccess;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getPendingCount() {
|
|
|
+ return pendingCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Instant getStartTime() {
|
|
|
+ return startTime;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.startObject();
|
|
@@ -128,6 +159,12 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
if (startTime != null) {
|
|
|
builder.timeField("start_time", "start_time_string", startTime.toEpochMilli());
|
|
|
}
|
|
|
+ if (inferenceThreads != null) {
|
|
|
+ builder.field("inference_threads", inferenceThreads);
|
|
|
+ }
|
|
|
+ if (modelThreads != null) {
|
|
|
+ builder.field("model_threads", modelThreads);
|
|
|
+ }
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|
|
@@ -141,6 +178,10 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
out.writeOptionalVInt(pendingCount);
|
|
|
out.writeOptionalWriteable(routingState);
|
|
|
out.writeOptionalInstant(startTime);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_8_1_0)) {
|
|
|
+ out.writeOptionalVInt(inferenceThreads);
|
|
|
+ out.writeOptionalVInt(modelThreads);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -154,12 +195,24 @@ public class AllocationStats implements ToXContentObject, Writeable {
|
|
|
&& Objects.equals(lastAccess, that.lastAccess)
|
|
|
&& Objects.equals(pendingCount, that.pendingCount)
|
|
|
&& Objects.equals(routingState, that.routingState)
|
|
|
- && Objects.equals(startTime, that.startTime);
|
|
|
+ && Objects.equals(startTime, that.startTime)
|
|
|
+ && Objects.equals(inferenceThreads, that.inferenceThreads)
|
|
|
+ && Objects.equals(modelThreads, that.modelThreads);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(node, inferenceCount, avgInferenceTime, lastAccess, pendingCount, routingState, startTime);
|
|
|
+ return Objects.hash(
|
|
|
+ node,
|
|
|
+ inferenceCount,
|
|
|
+ avgInferenceTime,
|
|
|
+ lastAccess,
|
|
|
+ pendingCount,
|
|
|
+ routingState,
|
|
|
+ startTime,
|
|
|
+ inferenceThreads,
|
|
|
+ modelThreads
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|