forked from opensearch-project/cross-cluster-replication
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Leader Stats API (opensearch-project#122) (opensearch-project#133)
Signed-off-by: Gaurav Bafna <[email protected]>
- Loading branch information
Showing
14 changed files
with
597 additions
and
9 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
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/LeaderNodeStatsResponse.kt
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,39 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package com.amazon.elasticsearch.replication.action.stats | ||
|
||
import com.amazon.elasticsearch.replication.seqno.RemoteShardMetric | ||
import com.amazon.elasticsearch.replication.seqno.RemoteShardMetric.RemoteShardStats | ||
import org.elasticsearch.action.support.nodes.BaseNodeResponse | ||
import org.elasticsearch.cluster.node.DiscoveryNode | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import org.elasticsearch.common.io.stream.StreamOutput | ||
import org.elasticsearch.index.shard.ShardId | ||
import java.io.IOException | ||
|
||
class LeaderNodeStatsResponse : BaseNodeResponse { | ||
var remoteStats :Map<ShardId, RemoteShardMetric.RemoteShardStats> | ||
|
||
constructor(inp: StreamInput) : super(inp) { | ||
remoteStats = inp.readMap(::ShardId, ::RemoteShardStats) | ||
} | ||
|
||
constructor(node : DiscoveryNode, remoteClusterStats: Map<ShardId, RemoteShardMetric>) : super(node) { | ||
remoteStats = remoteClusterStats.mapValues { (_ , v) -> v.createStats() } | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
super.writeTo(out) | ||
out.writeMap(remoteStats, { o, k -> k.writeTo(o)}, { o, v -> v.writeTo(o)}) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/LeaderStatsAction.kt
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,25 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package com.amazon.elasticsearch.replication.action.stats | ||
|
||
import org.elasticsearch.action.ActionType | ||
import org.elasticsearch.common.io.stream.Writeable | ||
|
||
class LeaderStatsAction : ActionType<LeaderStatsResponse>(NAME, reader) { | ||
companion object { | ||
const val NAME = "indices:admin/plugins/replication/index/stats" | ||
val INSTANCE = LeaderStatsAction() | ||
val reader = Writeable.Reader { inp -> LeaderStatsResponse(inp) } | ||
} | ||
|
||
override fun getResponseReader(): Writeable.Reader<LeaderStatsResponse> = reader | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/LeaderStatsRequest.kt
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,42 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package com.amazon.elasticsearch.replication.action.stats | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodesRequest | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import org.elasticsearch.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
/** | ||
* A request to get node (cluster) level replication stats. | ||
*/ | ||
class LeaderStatsRequest : BaseNodesRequest<LeaderStatsRequest?> { | ||
|
||
/** | ||
* | ||
* @param in A stream input object. | ||
* @throws IOException if the stream cannot be deserialized. | ||
*/ | ||
constructor(inp: StreamInput) : super(inp) | ||
|
||
/** | ||
* Get information from nodes based on the nodes ids specified. If none are passed, information | ||
* for all nodes will be returned. | ||
*/ | ||
constructor(vararg nodesIds: String) : super(*nodesIds) | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
super.writeTo(out) | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/LeaderStatsResponse.kt
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,103 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package com.amazon.elasticsearch.replication.action.stats | ||
|
||
|
||
import com.amazon.elasticsearch.replication.seqno.RemoteShardMetric | ||
import com.amazon.elasticsearch.replication.seqno.RemoteShardMetric.RemoteShardStats | ||
import org.apache.logging.log4j.LogManager | ||
import org.elasticsearch.action.FailedNodeException | ||
import org.elasticsearch.action.support.nodes.BaseNodesResponse | ||
import org.elasticsearch.cluster.ClusterName | ||
import org.elasticsearch.common.Strings | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import org.elasticsearch.common.io.stream.StreamOutput | ||
import org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS | ||
import org.elasticsearch.common.xcontent.ToXContent.Params | ||
import org.elasticsearch.common.xcontent.ToXContentObject | ||
import org.elasticsearch.common.xcontent.XContentBuilder | ||
import org.elasticsearch.common.xcontent.XContentFactory | ||
import java.io.IOException | ||
|
||
class LeaderStatsResponse : BaseNodesResponse<LeaderNodeStatsResponse?>, ToXContentObject { | ||
var remoteStats :MutableMap<String, RemoteShardMetric.RemoteShardStats> = mutableMapOf() | ||
var ops :Long = 0 | ||
var tlogSize :Long = 0 | ||
var opsLucene :Long = 0 | ||
var opsTlog :Long = 0 | ||
var latencyLucene :Long = 0 | ||
var latencyTlog :Long = 0 | ||
var bytesRead :Long = 0 | ||
|
||
companion object { | ||
private val log = LogManager.getLogger(LeaderStatsResponse::class.java) | ||
} | ||
|
||
constructor(inp: StreamInput) : super(inp) { | ||
remoteStats = inp.readMap(StreamInput::readString, ::RemoteShardStats) | ||
} | ||
|
||
fun add(stat :RemoteShardStats) { | ||
ops += stat.ops | ||
tlogSize += stat.tlogSize | ||
opsLucene += stat.opsLucene | ||
opsTlog += stat.opsTlog | ||
latencyLucene += stat.latencyLucene | ||
latencyTlog += stat.latencyTlog | ||
bytesRead += stat.bytesRead | ||
} | ||
|
||
constructor(clusterName: ClusterName?, leaderNodeRespons: List<LeaderNodeStatsResponse>?, failures: List<FailedNodeException?>?) : super(clusterName, leaderNodeRespons, failures) { | ||
if (leaderNodeRespons != null) { | ||
for (response in leaderNodeRespons) { | ||
for (entry in response.remoteStats) { | ||
remoteStats[entry.key.indexName] = remoteStats.getOrDefault(entry.key.indexName, RemoteShardStats()) | ||
remoteStats[entry.key.indexName]!!.add(entry.value) | ||
add(entry.value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun readNodesFrom(inp: StreamInput): List<LeaderNodeStatsResponse> { | ||
return inp.readList { LeaderNodeStatsResponse(inp) } | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeNodesTo(out: StreamOutput, leaderNodeRespons: List<LeaderNodeStatsResponse?>?) { | ||
out.writeList(leaderNodeRespons) | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: Params?): XContentBuilder { | ||
builder.startObject() | ||
builder.field("num_replicated_indices", remoteStats.size) | ||
builder.field("operations_read", ops) | ||
builder.field("translog_size_bytes", tlogSize) | ||
builder.field("operations_read_lucene", opsLucene) | ||
builder.field("operations_read_translog", opsTlog) | ||
builder.field("total_read_time_lucene_millis", latencyLucene) | ||
builder.field("total_read_time_translog_millis", latencyTlog) | ||
builder.field("bytes_read", bytesRead) | ||
builder.field("index_details").map(remoteStats) | ||
builder.endObject() | ||
return builder | ||
} | ||
|
||
override fun toString(): String { | ||
val builder: XContentBuilder = XContentFactory.jsonBuilder().prettyPrint() | ||
toXContent(builder, EMPTY_PARAMS) | ||
return Strings.toString(builder) | ||
} | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/NodeStatsRequest.kt
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,30 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package com.amazon.elasticsearch.replication.action.stats | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodeRequest | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import org.elasticsearch.common.io.stream.StreamOutput | ||
import java.io.IOException | ||
|
||
class NodeStatsRequest : BaseNodeRequest { | ||
|
||
constructor(inp :StreamInput) : super(inp) | ||
|
||
constructor() | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
super.writeTo(out) | ||
} | ||
} | ||
|
Oops, something went wrong.