-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gaurav Bafna <[email protected]>
- Loading branch information
Showing
19 changed files
with
621 additions
and
70 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
39 changes: 39 additions & 0 deletions
39
...ain/kotlin/com/amazon/elasticsearch/replication/action/stats/FollowerNodeStatsResponse.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 elasticsearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright elasticsearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.elasticsearch.replication.action.stats | ||
|
||
import com.amazon.elasticsearch.replication.task.shard.FollowerShardMetric | ||
import com.amazon.elasticsearch.replication.task.shard.FollowerShardMetric.FollowerStats | ||
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 FollowerNodeStatsResponse : BaseNodeResponse { | ||
var stats :Map<ShardId, FollowerStats> | ||
|
||
constructor(inp: StreamInput) : super(inp) { | ||
stats = inp.readMap(::ShardId, ::FollowerStats) | ||
} | ||
|
||
constructor(node : DiscoveryNode, remoteClusterStats: Map<ShardId, FollowerShardMetric>) : super(node) { | ||
stats = remoteClusterStats.mapValues { (_ , v) -> v.createStats() } | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
super.writeTo(out) | ||
out.writeMap(stats, { o, k -> k.writeTo(o)}, { o, v -> v.writeTo(o)}) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/FollowerStatsAction.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,27 @@ | ||
/* | ||
* 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 org.elasticsearch.replication.action.stats | ||
|
||
import com.amazon.elasticsearch.replication.action.stats.FollowerStatsResponse | ||
import org.elasticsearch.action.ActionType | ||
import org.elasticsearch.common.io.stream.Writeable | ||
|
||
class FollowerStatsAction : ActionType<FollowerStatsResponse>(NAME, reader) { | ||
companion object { | ||
const val NAME = "indices:admin/plugins/replication/follower/stats" | ||
val INSTANCE = FollowerStatsAction() | ||
val reader = Writeable.Reader { inp -> FollowerStatsResponse(inp) } | ||
} | ||
|
||
override fun getResponseReader(): Writeable.Reader<FollowerStatsResponse> = reader | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/FollowerStatsRequest.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 elasticsearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright elasticsearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.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 FollowerStatsRequest : BaseNodesRequest<FollowerStatsRequest?> { | ||
|
||
/** | ||
* | ||
* @param in A stream input object. | ||
* @throws IOException if the stream cannot be deserialized. | ||
*/ | ||
constructor(`in`: StreamInput) : super(`in`) | ||
|
||
/** | ||
* 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) | ||
} | ||
|
||
} |
123 changes: 123 additions & 0 deletions
123
src/main/kotlin/com/amazon/elasticsearch/replication/action/stats/FollowerStatsResponse.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,123 @@ | ||
/* | ||
* 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.metadata.ReplicationOverallState | ||
import com.amazon.elasticsearch.replication.metadata.state.REPLICATION_LAST_KNOWN_OVERALL_STATE | ||
import com.amazon.elasticsearch.replication.metadata.state.ReplicationStateMetadata | ||
import com.amazon.elasticsearch.replication.task.shard.FollowerShardMetric | ||
import com.amazon.elasticsearch.replication.task.shard.FollowerShardMetric.FollowerStats | ||
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 org.elasticsearch.index.shard.ShardId | ||
import org.elasticsearch.replication.action.stats.FollowerNodeStatsResponse | ||
import java.io.IOException | ||
|
||
class FollowerStatsResponse : BaseNodesResponse<FollowerNodeStatsResponse?>, ToXContentObject { | ||
var shardStats :MutableMap<ShardId, FollowerShardMetric.FollowerStats> = mutableMapOf() | ||
var indexStats :MutableMap<String, FollowerShardMetric.FollowerStats> = mutableMapOf() | ||
var stats : FollowerShardMetric.FollowerStatsFragment = FollowerShardMetric.FollowerStatsFragment() | ||
|
||
var pausedIndices :Int = 0 | ||
var failedIndices :Int = 0 | ||
var bootstrappingIndices :Int = 0 | ||
var syncingIndices :Int = 0 | ||
var shardTaskCount :Int = 0 | ||
var indexTaskCount :Int = 0 | ||
|
||
companion object { | ||
private val log = LogManager.getLogger(FollowerStatsResponse::class.java) | ||
} | ||
|
||
constructor(inp: StreamInput) : super(inp) { | ||
shardStats = inp.readMap(::ShardId, ::FollowerStats) | ||
} | ||
|
||
constructor(clusterName: ClusterName?, followerNodeResponse: List<FollowerNodeStatsResponse>?, failures: List<FailedNodeException?>? | ||
, metadata : ReplicationStateMetadata) : super(clusterName, followerNodeResponse, failures) { | ||
|
||
var syncing :MutableSet<String> = mutableSetOf() | ||
if (followerNodeResponse != null) { | ||
for (response in followerNodeResponse) { | ||
shardStats.putAll(response.stats) | ||
|
||
for (i in response.stats) { | ||
syncing.add(i.key.indexName) | ||
|
||
if (i.key.indexName !in indexStats) { | ||
indexStats[i.key.indexName] = FollowerShardMetric.FollowerStats() | ||
} | ||
indexStats[i.key.indexName]!!.add(i.value) | ||
|
||
stats.add(i.value) | ||
} | ||
} | ||
} | ||
|
||
var totalRunning = 0 //includes boostrap and syncing | ||
for (entry in metadata.replicationDetails) { | ||
when (entry.value[REPLICATION_LAST_KNOWN_OVERALL_STATE]) { | ||
ReplicationOverallState.RUNNING.name -> totalRunning++ | ||
ReplicationOverallState.FAILED.name -> failedIndices++ | ||
ReplicationOverallState.PAUSED.name -> pausedIndices++ | ||
} | ||
} | ||
|
||
syncingIndices = syncing.size | ||
bootstrappingIndices = totalRunning - syncingIndices | ||
|
||
shardTaskCount = shardStats.size | ||
indexTaskCount = totalRunning | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun readNodesFrom(inp: StreamInput): List<FollowerNodeStatsResponse> { | ||
return inp.readList { FollowerNodeStatsResponse(inp) } | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeNodesTo(out: StreamOutput, leaderNodeRespons: List<FollowerNodeStatsResponse?>?) { | ||
out.writeList(leaderNodeRespons) | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: Params?): XContentBuilder { | ||
builder.startObject() | ||
builder.field("num_syncing_indices", syncingIndices) | ||
builder.field("num_bootstrapping_indices", bootstrappingIndices) | ||
builder.field("num_paused_indices", pausedIndices) | ||
builder.field("num_shard_tasks", shardTaskCount) | ||
builder.field("num_index_tasks", indexTaskCount) | ||
stats.toXContent(builder, params) | ||
builder.field("index_stats").map(indexStats) | ||
builder.endObject() | ||
return builder | ||
} | ||
|
||
override fun toString(): String { | ||
val builder: XContentBuilder = XContentFactory.jsonBuilder().prettyPrint() | ||
toXContent(builder, EMPTY_PARAMS) | ||
return Strings.toString(builder) | ||
} | ||
} | ||
|
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.