Skip to content

Commit

Permalink
Add Retry count retrieval in hook (#1335)
Browse files Browse the repository at this point in the history
* Add Retry count retrieval in hook

* Fix compile issue on travis

* Pull in latest changes in retry structures

* Rebasing off develop with successful travis run for retry
  • Loading branch information
disa6302 authored Dec 7, 2021
1 parent 877d116 commit cc8fc05
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions samples/Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ STATUS logSignalingClientStats(PSignalingClientMetrics pSignalingClientMetrics)
// This gives the EMA of the getIceConfig() call.
DLOGD("Data Plane API call latency: %" PRIu64 " ms",
(pSignalingClientMetrics->signalingClientStats.dpApiCallLatency / HUNDREDS_OF_NANOS_IN_A_MILLISECOND));
DLOGD("API call retry count: %d", pSignalingClientMetrics->signalingClientStats.apiCallRetryCount);
CleanUp:
LEAVES();
return retStatus;
Expand Down
6 changes: 3 additions & 3 deletions samples/kvsWebRTCClientMaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ INT32 main(INT32 argc, CHAR* argv[])
PSampleConfiguration pSampleConfiguration = NULL;
SignalingClientMetrics signalingClientMetrics;
PCHAR pChannelName;
signalingClientMetrics.version = 0;
signalingClientMetrics.version = SIGNALING_CLIENT_METRICS_CURRENT_VERSION;

SET_INSTRUMENTED_ALLOCATORS();

Expand Down Expand Up @@ -114,7 +114,7 @@ INT32 main(INT32 argc, CHAR* argv[])
CleanUp:

if (retStatus != STATUS_SUCCESS) {
printf("[KVS Master] Terminated with status code 0x%08x", retStatus);
printf("[KVS Master] Terminated with status code 0x%08x\n", retStatus);
}

printf("[KVS Master] Cleaning up....\n");
Expand Down Expand Up @@ -147,7 +147,7 @@ INT32 main(INT32 argc, CHAR* argv[])
if (retStatus == STATUS_SUCCESS) {
logSignalingClientStats(&signalingClientMetrics);
} else {
printf("[KVS Master] signalingClientGetMetrics() operation returned status code: 0x%08x", retStatus);
printf("[KVS Master] signalingClientGetMetrics() operation returned status code: 0x%08x\n", retStatus);
}
retStatus = freeSignalingClient(&pSampleConfiguration->signalingClientHandle);
if (retStatus != STATUS_SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,7 @@ typedef struct {
//!< being used this value can be NULL or point to an EMPTY_STRING.
KvsRetryStrategyCallbacks signalingRetryStrategyCallbacks; //!< Retry strategy callbacks used while creating signaling client
UINT32 signalingClientCreationMaxRetryAttempts; //!< Max attempts to create signaling client before returning error to the caller
UINT32 stateMachineRetryCountReadOnly; //!< Retry count of state machine. Note that this **MUST NOT** be modified by the user. It is a read only field
} SignalingClientInfo, *PSignalingClientInfo;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef enum {
typedef struct {
UINT64 durationInSeconds; //!< Time (seconds) spent in each state
RTC_QUALITY_LIMITATION_REASON qualityLimitationReason; //!< Quality limitation reason
} QualityLimitationDurationsRecord, PQualityLimitationDurationsRecord;
} QualityLimitationDurationsRecord, *PQualityLimitationDurationsRecord;

/**
* @brief Record of total number of packets sent per DSCP. Used by RTCOutboundRtpStreamStats
Expand Down Expand Up @@ -577,6 +577,7 @@ typedef struct {
//!< * When refreshing ICE server configuration fails after pre-configured retries
//!< In all of these cases the error callback (if specified) will be called.
UINT32 numberOfReconnects; //!< Number of reconnects in the session
UINT32 apiCallRetryCount; //!< Number of retries due to API call failures in the state machine
} SignalingClientStats, PSignalingClientStats;

/**
Expand Down
5 changes: 3 additions & 2 deletions src/source/Signaling/Client.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ STATUS createSignalingClientSync(PSignalingClientInfo pClientInfo, PChannelInfo
break;
}

pClientInfo->stateMachineRetryCountReadOnly = signalingClientInfoInternal.signalingClientInfo.stateMachineRetryCountReadOnly;

// Wait before attempting to create signaling client
CHK_STATUS(pClientInfo->signalingRetryStrategyCallbacks.executeRetryStrategyFn(
&createSignalingClientRetryStrategy, &signalingClientCreationWaitTime));

DLOGE("Attempting to back off for [%lf] milliseconds before creating signaling client again. "
DLOGV("Attempting to back off for [%lf] milliseconds before creating signaling client again. "
"Signaling client creation retry count [%d]",
retStatus, signalingClientCreationWaitTime/1000.0, signalingClientCreationMaxRetryCount);
THREAD_SLEEP(signalingClientCreationWaitTime);
Expand Down Expand Up @@ -345,7 +347,6 @@ STATUS signalingClientGetMetrics(SIGNALING_CLIENT_HANDLE signalingClientHandle,
CHK_STATUS(signalingGetMetrics(pSignalingClient, pSignalingClientMetrics));

CleanUp:

SIGNALING_UPDATE_ERROR_COUNT(pSignalingClient, retStatus);
LEAVES();
return retStatus;
Expand Down
5 changes: 4 additions & 1 deletion src/source/Signaling/Signaling.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ STATUS createSignalingSync(PSignalingClientInfoInternal pClientInfo, PChannelInf
SIGNALING_STATE_READY));

CleanUp:

if(pClientInfo != NULL && pSignalingClient != NULL) {
pClientInfo->signalingClientInfo.stateMachineRetryCountReadOnly = pSignalingClient->diagnostics.stateMachineRetryCount;
}
CHK_LOG_ERR(retStatus);

if (STATUS_FAILED(retStatus)) {
Expand Down Expand Up @@ -1210,6 +1212,7 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe

pSignalingClientMetrics->signalingClientStats.connectionDuration =
ATOMIC_LOAD_BOOL(&pSignalingClient->connected) ? curTime - pSignalingClient->diagnostics.connectTime : 0;
pSignalingClientMetrics->signalingClientStats.apiCallRetryCount = pSignalingClient->diagnostics.stateMachineRetryCount;

MUTEX_UNLOCK(pSignalingClient->diagnosticsLock);

Expand Down
1 change: 1 addition & 0 deletions src/source/Signaling/Signaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ typedef struct {
UINT64 connectTime;
UINT64 cpApiLatency;
UINT64 dpApiLatency;
UINT32 stateMachineRetryCount;
} SignalingDiagnostics, PSignalingDiagnostics;

/**
Expand Down
11 changes: 10 additions & 1 deletion src/source/Signaling/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ STATUS defaultSignalingStateTransitionHook(
PUINT64 stateTransitionWaitTime) {
ENTERS();
STATUS retStatus = STATUS_SUCCESS;
STATUS countStatus = STATUS_SUCCESS;
PSignalingClient pSignalingClient = NULL;
PKvsRetryStrategy pSignalingStateMachineRetryStrategy = NULL;
PKvsRetryStrategyCallbacks pSignalingStateMachineRetryStrategyCallbacks = NULL;
Expand All @@ -149,9 +150,17 @@ STATUS defaultSignalingStateTransitionHook(
DLOGV("Signaling Client base result is [%u]. Executing KVS retry handler of retry strategy type [%u]",
pSignalingClient->result, pSignalingStateMachineRetryStrategy->retryStrategyType);
pSignalingStateMachineRetryStrategyCallbacks->executeRetryStrategyFn(pSignalingStateMachineRetryStrategy, &retryWaitTime);

*stateTransitionWaitTime = retryWaitTime;

if(pSignalingStateMachineRetryStrategyCallbacks->getCurrentRetryAttemptNumberFn != NULL) {
if((countStatus = pSignalingStateMachineRetryStrategyCallbacks->getCurrentRetryAttemptNumberFn(pSignalingStateMachineRetryStrategy, &pSignalingClient->diagnostics.stateMachineRetryCount)) != STATUS_SUCCESS) {
DLOGW("Failed to get retry count. Error code: %08x", countStatus);
}
else {
DLOGD("Retry count: %llu", pSignalingClient->diagnostics.stateMachineRetryCount);
}
}

CleanUp:

LEAVES();
Expand Down
2 changes: 1 addition & 1 deletion tst/SignalingApiFunctionalityTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ TEST_F(SignalingApiFunctionalityTest, basicCreateConnectFree)
EXPECT_EQ(STATUS_SUCCESS, freeSignalingClient(&signalingHandle));
}

TEST_F(SignalingApiFunctionalityTest, basicCreateCreateWithRetries)
TEST_F(SignalingApiFunctionalityTest, basicCreateWithRetries)
{
if (!mAccessKeyIdSet) {
return;
Expand Down

0 comments on commit cc8fc05

Please sign in to comment.