-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Weighted Routing] Support for fail open stats (#6041)
* Support for fail open stats Signed-off-by: Anshu Agarwal <anshukag@amazon.com>
- Loading branch information
Showing
12 changed files
with
261 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
84 changes: 84 additions & 0 deletions
84
server/src/main/java/org/opensearch/cluster/routing/WeightedRoutingStats.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,84 @@ | ||
/* | ||
* 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.cluster.routing; | ||
|
||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.io.stream.Writeable; | ||
import org.opensearch.common.xcontent.ToXContent; | ||
import org.opensearch.common.xcontent.ToXContentFragment; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Captures weighted shard routing stats per node. See {@link WeightedRoutingService} for more details. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class WeightedRoutingStats implements ToXContentFragment, Writeable { | ||
// number of times fail open has to be executed for search requests | ||
private AtomicInteger failOpenCount; | ||
|
||
private static final WeightedRoutingStats INSTANCE = new WeightedRoutingStats(); | ||
|
||
public static WeightedRoutingStats getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
private WeightedRoutingStats() { | ||
failOpenCount = new AtomicInteger(0); | ||
} | ||
|
||
public WeightedRoutingStats(StreamInput in) throws IOException { | ||
failOpenCount = new AtomicInteger(in.readInt()); | ||
} | ||
|
||
public void updateFailOpenCount() { | ||
failOpenCount.getAndIncrement(); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
builder.startObject("weighted_routing"); | ||
builder.startObject("stats"); | ||
builder.field("fail_open_count", getFailOpenCount()); | ||
builder.endObject(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public int getFailOpenCount() { | ||
return failOpenCount.get(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeInt(failOpenCount.get()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
WeightedRoutingStats that = (WeightedRoutingStats) o; | ||
return failOpenCount.equals(that.failOpenCount); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(failOpenCount); | ||
} | ||
|
||
public void resetFailOpenCount() { | ||
failOpenCount.set(0); | ||
} | ||
} |
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.