forked from Azure/azure-sdk-for-java
-
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.
Fix for connection state listener (Azure#27242)
* collect connection state listner metrics * move connection state listener to RntbdRequestManager level, which improvements the handling when the connection is idle Co-authored-by: annie-mac <[email protected]> Co-authored-by: annie-mac <[email protected]>
- Loading branch information
1 parent
162b541
commit c1210cf
Showing
18 changed files
with
206 additions
and
81 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
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
60 changes: 60 additions & 0 deletions
60
...e/cosmos/implementation/directconnectivity/rntbd/RntbdConnectionStateListenerMetrics.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,60 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.cosmos.implementation.directconnectivity.rntbd; | ||
|
||
import com.azure.cosmos.implementation.apachecommons.lang.tuple.Pair; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.time.Instant; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
@JsonSerialize(using = RntbdConnectionStateListenerMetrics.RntbdConnectionStateListenerMetricsJsonSerializer.class) | ||
public final class RntbdConnectionStateListenerMetrics implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
private static final Logger logger = LoggerFactory.getLogger(RntbdConnectionStateListenerMetrics.class); | ||
|
||
private final AtomicReference<Instant> lastCallTimestamp; | ||
private final AtomicReference<Pair<Instant, Integer>> lastActionableContext; | ||
|
||
public RntbdConnectionStateListenerMetrics() { | ||
|
||
this.lastCallTimestamp = new AtomicReference<>(); | ||
this.lastActionableContext = new AtomicReference<>(); | ||
} | ||
|
||
public void recordAddressUpdated(int addressEntryUpdatedCount) { | ||
this.lastActionableContext.set(Pair.of(this.lastCallTimestamp.get(), addressEntryUpdatedCount)); | ||
} | ||
|
||
public void record() { | ||
this.lastCallTimestamp.set(Instant.now()); | ||
} | ||
|
||
final static class RntbdConnectionStateListenerMetricsJsonSerializer extends com.fasterxml.jackson.databind.JsonSerializer<RntbdConnectionStateListenerMetrics> { | ||
|
||
public RntbdConnectionStateListenerMetricsJsonSerializer() { | ||
} | ||
|
||
@Override | ||
public void serialize(RntbdConnectionStateListenerMetrics metrics, JsonGenerator writer, SerializerProvider serializers) throws IOException { | ||
writer.writeStartObject(); | ||
|
||
writer.writeStringField( | ||
"lastCallTimestamp", | ||
metrics.lastCallTimestamp.get() == null ? "N/A" : metrics.lastCallTimestamp.toString()); | ||
|
||
if (metrics.lastActionableContext.get() != null) { | ||
writer.writeStringField("lastActionableContext", metrics.lastActionableContext.get().toString()); | ||
} | ||
|
||
writer.writeEndObject(); | ||
} | ||
} | ||
} |
Oops, something went wrong.