-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding model level metric in node level (#1330)
* adding model level metric in node level Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * spotlessApply and fixed a test Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * added if clause to bypass the integration test Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * addressing comments Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * addressed comments Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * add more tests Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> * adding boolean check if model stats exists Signed-off-by: Dhrubo Saha <dhrubo@amazon.com> --------- Signed-off-by: Dhrubo Saha <dhrubo@amazon.com>
- Loading branch information
Showing
17 changed files
with
449 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
plugin/src/main/java/org/opensearch/ml/stats/MLModelStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.stats; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
public class MLModelStats implements ToXContentFragment, Writeable { | ||
|
||
/** | ||
* Model stats. | ||
* Key: Model Id. | ||
* Value: MLActionStats which contains action stat/value map. | ||
* | ||
* Example: {predict: { request_count: 1}} | ||
*/ | ||
private Map<ActionName, MLActionStats> modelStats; | ||
|
||
public MLModelStats(StreamInput in) throws IOException { | ||
if (in.readBoolean()) { | ||
this.modelStats = in.readMap(stream -> stream.readEnum(ActionName.class), MLActionStats::new); | ||
} | ||
} | ||
|
||
public MLModelStats(Map<ActionName, MLActionStats> modelStats) { | ||
this.modelStats = modelStats; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
if (modelStats != null && modelStats.size() > 0) { | ||
out.writeBoolean(true); | ||
out.writeMap(modelStats, (stream, v) -> stream.writeEnum(v), (stream, stats) -> stats.writeTo(stream)); | ||
} else { | ||
out.writeBoolean(false); | ||
} | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
if (modelStats != null && modelStats.size() > 0) { | ||
for (Map.Entry<ActionName, MLActionStats> entry : modelStats.entrySet()) { | ||
builder.startObject(entry.getKey().name().toLowerCase(Locale.ROOT)); | ||
entry.getValue().toXContent(builder, params); | ||
builder.endObject(); | ||
} | ||
} | ||
return builder; | ||
} | ||
|
||
public MLActionStats getActionStats(ActionName action) { | ||
return modelStats == null ? null : modelStats.get(action); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.