Skip to content

Commit

Permalink
[telemetry] add upstream DNS metrics (openthread#9729)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherysheng authored Jan 4, 2024
1 parent 666a9bd commit ee74513
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
29 changes: 21 additions & 8 deletions include/openthread/dnssd_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,33 @@ typedef enum
OT_DNSSD_QUERY_TYPE_RESOLVE_HOST = 3, ///< Service type resolve hostname.
} otDnssdQueryType;

/**
* Represents the count of queries, responses, failures handled by upstream DNS server.
*
* Requires `OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE`.
*/
typedef struct otUpstreamDnsCounters
{
uint32_t mQueries; ///< The number of queries forwarded.
uint32_t mResponses; ///< The number of responses forwarded.
uint32_t mFailures; ///< The number of upstream DNS failures.
} otUpstreamDnsCounters;

/**
* Contains the counters of DNS-SD server.
*
*/
typedef struct otDnssdCounters
{
uint32_t mSuccessResponse; ///< The number of successful responses
uint32_t mServerFailureResponse; ///< The number of server failure responses
uint32_t mFormatErrorResponse; ///< The number of format error responses
uint32_t mNameErrorResponse; ///< The number of name error responses
uint32_t mNotImplementedResponse; ///< The number of 'not implemented' responses
uint32_t mOtherResponse; ///< The number of other responses

uint32_t mResolvedBySrp; ///< The number of queries completely resolved by the local SRP server
uint32_t mSuccessResponse; ///< The number of successful responses.
uint32_t mServerFailureResponse; ///< The number of server failure responses.
uint32_t mFormatErrorResponse; ///< The number of format error responses.
uint32_t mNameErrorResponse; ///< The number of name error responses.
uint32_t mNotImplementedResponse; ///< The number of 'not implemented' responses.
uint32_t mOtherResponse; ///< The number of other responses.
uint32_t mResolvedBySrp; ///< The number of queries resolved by the local SRP server.
otUpstreamDnsCounters mUpstreamDnsCounters; ///< The number of queries, responses,
///< failures handled by upstream DNS server.
} otDnssdCounters;

/**
Expand Down
2 changes: 1 addition & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (385)
#define OPENTHREAD_API_VERSION (386)

/**
* @addtogroup api-instance
Expand Down
9 changes: 8 additions & 1 deletion src/core/net/dnssd_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ void Server::OnUpstreamQueryDone(UpstreamQueryTransaction &aQueryTransaction, Me
{
error = mSocket.SendTo(*aResponseMessage, aQueryTransaction.GetMessageInfo());
}
else
{
error = kErrorResponseTimeout;
}

ResetUpstreamQueryTransaction(aQueryTransaction, error);

Expand All @@ -886,7 +890,7 @@ Server::UpstreamQueryTransaction *Server::AllocateUpstreamQueryTransaction(const
}
}

VerifyOrExit(newTxn != nullptr);
VerifyOrExit(newTxn != nullptr, mCounters.mUpstreamDnsCounters.mFailures++);

newTxn->Init(aMessageInfo);
LogInfo("Upstream query transaction %d initialized.", static_cast<int>(newTxn - mUpstreamQueryTransactions));
Expand All @@ -905,6 +909,7 @@ Error Server::ResolveByUpstream(const Request &aRequest)
VerifyOrExit(txn != nullptr, error = kErrorNoBufs);

otPlatDnsStartUpstreamQuery(&GetInstance(), txn, aRequest.mMessage);
mCounters.mUpstreamDnsCounters.mQueries++;

exit:
return error;
Expand Down Expand Up @@ -1277,10 +1282,12 @@ void Server::ResetUpstreamQueryTransaction(UpstreamQueryTransaction &aTxn, Error
OT_UNUSED_VARIABLE(index);
if (aError == kErrorNone)
{
mCounters.mUpstreamDnsCounters.mResponses++;
LogInfo("Upstream query transaction %d completed.", index);
}
else
{
mCounters.mUpstreamDnsCounters.mFailures++;
LogWarn("Upstream query transaction %d closed: %s.", index, ErrorToString(aError));
}
aTxn.Reset();
Expand Down

0 comments on commit ee74513

Please sign in to comment.