Skip to content

Commit 344a91e

Browse files
committed
add new metric correct connect time in curl.
1 parent d3ed146 commit 344a91e

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

src/aws-cpp-sdk-core/include/aws/core/monitoring/HttpClientMetrics.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ namespace Aws
3535
ConnectionReused,
3636

3737
/**
38-
* Requires the SDK to recognize that a new connection was established to make the request,
39-
* contains the time interval (in milliseconds) between the construction of the http request and when a connection was fully established.
40-
* If the SDK is able to estimate this time despite not having a perfectly accurate callback for the specific event, then it should.
41-
* For example, if the http client includes user-level data write functions that are guaranteed to be called shortly after connection establishment,
42-
* then the first call could be used as a reasonable time marker for ConnectLatency
38+
* Deprecated, maintained for backwards compatibility, use TimeToConnect instead,
4339
*/
4440
ConnectLatency,
4541

@@ -84,7 +80,21 @@ namespace Aws
8480
/**
8581
* Unknow Metrics Type
8682
*/
87-
Unknown
83+
Unknown,
84+
85+
/**
86+
* Time between http client initialization and first byte transferred.
87+
*/
88+
TimeToFirstByte,
89+
90+
/**
91+
* Requires the SDK to recognize that a new connection was established to make the request,
92+
* contains the time interval (in milliseconds) between the construction of the http request and when a connection was fully established.
93+
* If the SDK is able to estimate this time despite not having a perfectly accurate callback for the specific event, then it should.
94+
* For example, if the http client includes user-level data write functions that are guaranteed to be called shortly after connection establishment,
95+
* then the first call could be used as a reasonable time marker for ConnectLatency
96+
*/
97+
TimeToConnect,
8898
};
8999

90100
typedef Aws::Map<Aws::String, int64_t> HttpClientMetricsCollection;

src/aws-cpp-sdk-core/source/http/curl/CurlHttpClient.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,13 @@ std::shared_ptr<HttpResponse> CurlHttpClient::MakeRequest(const std::shared_ptr<
933933
if (ret == CURLE_OK)
934934
{
935935
request->AddRequestMetric(GetHttpClientMetricNameByType(HttpClientMetricsType::ConnectLatency), static_cast<int64_t>(timep * 1000));
936+
request->AddRequestMetric(GetHttpClientMetricNameByType(HttpClientMetricsType::TimeToFirstByte), static_cast<int64_t>(timep * 1000));
937+
}
938+
939+
ret = curl_easy_getinfo(connectionHandle, CURLINFO_PRETRANSFER_TIME, &timep);
940+
if (ret == CURLE_OK)
941+
{
942+
request->AddRequestMetric(GetHttpClientMetricNameByType(HttpClientMetricsType::TimeToConnect), static_cast<int64_t>(timep * 1000));
936943
}
937944

938945
#if LIBCURL_VERSION_NUM >= 0x073D00 // 7.61.0

src/aws-cpp-sdk-core/source/monitoring/DefaultMonitoring.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ namespace Aws
187187
ExportHttpMetricsToJson(json, metricsFromCore.httpClientMetrics, HttpClientMetricsType::RequestLatency);
188188
ExportHttpMetricsToJson(json, metricsFromCore.httpClientMetrics, HttpClientMetricsType::SslLatency);
189189
ExportHttpMetricsToJson(json, metricsFromCore.httpClientMetrics, HttpClientMetricsType::TcpLatency);
190+
ExportHttpMetricsToJson(json, metricsFromCore.httpClientMetrics, HttpClientMetricsType::TimeToFirstByte);
191+
ExportHttpMetricsToJson(json, metricsFromCore.httpClientMetrics, HttpClientMetricsType::TimeToConnect);
190192
}
191193

192194
DefaultMonitoring::DefaultMonitoring(const Aws::String& clientId, const Aws::String& host, unsigned short port):

src/aws-cpp-sdk-core/source/monitoring/HttpClientMetrics.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ namespace Aws
2121
static const char HTTP_CLIENT_METRICS_DOWNLOAD_SPEED[] = "DownloadSpeed";
2222
static const char HTTP_CLIENT_METRICS_THROUGHPUT[] = "Throughput";
2323
static const char HTTP_CLIENT_METRICS_UPLOAD_SPEED[] = "UploadSpeed";
24+
static const char HTTP_CLIENT_METRICS_TIME_TO_FIRST_BYTE[] = "TimeToFirstByte";
25+
static const char HTTP_CLIENT_METRICS_TIME_TO_CONNECT[] = "TimeToConnect";
2426
static const char HTTP_CLIENT_METRICS_UNKNOWN[] = "Unknown";
2527

26-
static const Aws::Array<std::pair<HttpClientMetricsType, const char*>, 12> httpClientMetricsNames =
28+
static const Aws::Array<std::pair<HttpClientMetricsType, const char*>, 14> httpClientMetricsNames =
2729
{
2830
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::DestinationIp, HTTP_CLIENT_METRICS_DESTINATION_IP),
2931
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::AcquireConnectionLatency, HTTP_CLIENT_METRICS_ACQUIRE_CONNECTION_LATENCY),
@@ -37,6 +39,8 @@ namespace Aws
3739
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::Throughput, HTTP_CLIENT_METRICS_THROUGHPUT),
3840
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::UploadSpeed, HTTP_CLIENT_METRICS_UPLOAD_SPEED),
3941
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::Unknown, HTTP_CLIENT_METRICS_UNKNOWN),
42+
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::TimeToFirstByte, HTTP_CLIENT_METRICS_TIME_TO_FIRST_BYTE),
43+
std::pair<HttpClientMetricsType, const char *>(HttpClientMetricsType::TimeToConnect, HTTP_CLIENT_METRICS_TIME_TO_CONNECT),
4044
};
4145

4246
HttpClientMetricsType GetHttpClientMetricTypeByName(const Aws::String& name)

0 commit comments

Comments
 (0)