Skip to content

Commit

Permalink
Fix metrics "connection_client" and "connecting_client" underreportin…
Browse files Browse the repository at this point in the history
…g due to multiple client actors of a connection starting on the same instance.

Tagging the metrics by the client actor number is not possible
without significant change because the client actor props factory
does not know about client actor numbers.

Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Dec 9, 2022
1 parent fdd4a61 commit 99639bc
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public abstract class BaseClientActor extends AbstractFSMWithStash<BaseClientSta
private final ActorRef connectionActor;
private final ActorSelection commandForwarderActorSelection;
private final Gauge clientGauge;
private boolean clientGaugeFlag = false; // set if clientGauge is incremented
private final Gauge clientConnectingGauge;
private boolean clientConnectingGaugeFlag = false; // set if clientConnectingGauge is incremented
private final ReconnectTimeoutStrategy reconnectTimeoutStrategy;
private final SupervisorStrategy supervisorStrategy;
private final ConnectionPubSub connectionPubSub;
Expand Down Expand Up @@ -369,8 +371,12 @@ private boolean shouldAnyTargetSendConnectionAnnouncements() {
@Override
public void postStop() {
cancelOnStopTasks.forEach(Cancellable::cancel);
clientGauge.reset();
clientConnectingGauge.reset();
if (clientGaugeFlag) {
clientGauge.decrement();
}
if (clientConnectingGaugeFlag) {
clientConnectingGauge.decrement();
}
stopChildActor(tunnelActor);
logger.debug("Stopped client with id - <{}>", getDefaultClientId());
try {
Expand Down Expand Up @@ -613,19 +619,23 @@ protected final List<Source> getSourcesOrEmptyList() {
private void onTransition(final BaseClientState from, final BaseClientState to) {
logger.debug("Transition: {} -> {}", from, to);
if (to == CONNECTED) {
clientGauge.set(1L);
clientGauge.increment();
clientGaugeFlag = true;
reconnectTimeoutStrategy.reset();
publishConnectionOpenedAnnouncement();
}
if (to == DISCONNECTED) {
clientGauge.reset();
clientGauge.decrement();
clientGaugeFlag = false;
}
if (to == CONNECTING) {
clientConnectingGauge.set(1L);
clientConnectingGauge.increment();
clientConnectingGaugeFlag = true;
}
// do not use else if since we might use goTo(CONNECTING) if in CONNECTING state. This will cause another onTransition.
if (from == CONNECTING) {
clientConnectingGauge.reset();
clientConnectingGauge.decrement();
clientConnectingGaugeFlag = false;
}
// cancel our own state timeout if target state is stable
if (to == CONNECTED || to == DISCONNECTED || to == INITIALIZED) {
Expand Down

0 comments on commit 99639bc

Please sign in to comment.