forked from opensearch-project/OpenSearch
-
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.
- Loading branch information
Anshu Agarwal
committed
Dec 4, 2023
1 parent
69cc2a1
commit 0184b8c
Showing
9 changed files
with
203 additions
and
7 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
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
80 changes: 80 additions & 0 deletions
80
server/src/main/java/org/opensearch/transport/TransportConnectionFailureStats.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,80 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.opensearch.transport; | ||
|
||
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; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class TransportConnectionFailureStats implements ToXContentFragment, Writeable { | ||
// Node as key with failure count as value | ||
private ConcurrentHashMap<String, Integer> connectionFailureMap; | ||
|
||
private static final TransportConnectionFailureStats INSTANCE = new TransportConnectionFailureStats(); | ||
|
||
public TransportConnectionFailureStats() { | ||
connectionFailureMap = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public TransportConnectionFailureStats(StreamInput in) throws IOException { | ||
connectionFailureMap = (ConcurrentHashMap)in.readMap(StreamInput::readString, StreamInput::readInt); | ||
} | ||
|
||
public static TransportConnectionFailureStats getInstance() { | ||
return INSTANCE; | ||
} | ||
public void updateConnectionFailureCount(String node) | ||
{ | ||
connectionFailureMap.compute(node, (k, v) -> v==null? 1 : v+1); | ||
} | ||
|
||
public int getConnectionFailureCount(String node) | ||
{ | ||
if (connectionFailureMap.containsKey(node)) | ||
{ | ||
Integer value = connectionFailureMap.get(node); | ||
return value; | ||
} | ||
return 0; | ||
} | ||
|
||
public Map<String, Integer> getConnectionFailure() | ||
{ | ||
return new HashMap(connectionFailureMap); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
Map<String, Integer> map = connectionFailureMap; | ||
out.writeMap(map,StreamOutput::writeString, StreamOutput::writeInt); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject("transport_connection_failure"); | ||
for (var entry: connectionFailureMap.entrySet()) { | ||
builder.field(entry.getKey(), entry.getValue()); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(connectionFailureMap); | ||
} | ||
} |
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