-
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 <[email protected]> * spotlessApply and fixed a test Signed-off-by: Dhrubo Saha <[email protected]> * added if clause to bypass the integration test Signed-off-by: Dhrubo Saha <[email protected]> * addressing comments Signed-off-by: Dhrubo Saha <[email protected]> * addressed comments Signed-off-by: Dhrubo Saha <[email protected]> * add more tests Signed-off-by: Dhrubo Saha <[email protected]> * adding boolean check if model stats exists Signed-off-by: Dhrubo Saha <[email protected]> --------- Signed-off-by: Dhrubo Saha <[email protected]> (cherry picked from commit bb84282)
- Loading branch information
1 parent
4b7aba4
commit ceeb2b1
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.