Skip to content

Commit 0770d35

Browse files
TingDaoKgraebm
andauthored
add request ID to debug level log (#504)
Co-authored-by: Michael Graeb <[email protected]>
1 parent 408e9c9 commit 0770d35

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

include/aws/s3/private/s3_request.h

+5
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ struct aws_s3_request {
210210
/* Returned response status of this request. */
211211
int response_status;
212212

213+
/* Returned request ID of this request. */
214+
struct aws_string *request_id;
215+
/* Returned amz ID 2 of this request. */
216+
struct aws_string *amz_id_2;
217+
213218
/* The metrics for the request telemetry */
214219
struct aws_s3_request_metrics *metrics;
215220

include/aws/s3/private/s3_util.h

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ extern const struct aws_byte_cursor g_range_header_name;
127127
extern const struct aws_byte_cursor g_if_match_header_name;
128128

129129
extern const struct aws_byte_cursor g_request_id_header_name;
130+
extern const struct aws_byte_cursor g_amz_id_2_header_name;
130131

131132
AWS_S3_API
132133
extern const struct aws_byte_cursor g_content_range_header_name;

source/s3_meta_request.c

+26-18
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ static int s_s3_meta_request_incoming_headers(
12761276

12771277
struct aws_s3_meta_request *meta_request = request->meta_request;
12781278
AWS_PRECONDITION(meta_request);
1279+
bool collect_metrics = request->send_data.metrics != NULL;
12791280

12801281
if (aws_http_stream_get_incoming_response_status(stream, &request->send_data.response_status)) {
12811282
AWS_LOGF_ERROR(
@@ -1284,23 +1285,13 @@ static int s_s3_meta_request_incoming_headers(
12841285
(void *)meta_request,
12851286
(void *)request);
12861287
}
1287-
if (request->send_data.metrics) {
1288+
1289+
if (collect_metrics) {
12881290
/* Record the headers to the metrics */
12891291
struct aws_s3_request_metrics *s3_metrics = request->send_data.metrics;
12901292
if (s3_metrics->req_resp_info_metrics.response_headers == NULL) {
12911293
s3_metrics->req_resp_info_metrics.response_headers = aws_http_headers_new(meta_request->allocator);
12921294
}
1293-
1294-
for (size_t i = 0; i < headers_count; ++i) {
1295-
const struct aws_byte_cursor *name = &headers[i].name;
1296-
const struct aws_byte_cursor *value = &headers[i].value;
1297-
if (aws_byte_cursor_eq(name, &g_request_id_header_name)) {
1298-
s3_metrics->req_resp_info_metrics.request_id =
1299-
aws_string_new_from_cursor(connection->request->allocator, value);
1300-
}
1301-
1302-
aws_http_headers_add(s3_metrics->req_resp_info_metrics.response_headers, *name, *value);
1303-
}
13041295
s3_metrics->req_resp_info_metrics.response_status = request->send_data.response_status;
13051296
}
13061297

@@ -1320,11 +1311,25 @@ static int s_s3_meta_request_incoming_headers(
13201311
if (request->send_data.response_headers == NULL) {
13211312
request->send_data.response_headers = aws_http_headers_new(meta_request->allocator);
13221313
}
1314+
}
13231315

1324-
for (size_t i = 0; i < headers_count; ++i) {
1325-
const struct aws_byte_cursor *name = &headers[i].name;
1326-
const struct aws_byte_cursor *value = &headers[i].value;
1327-
1316+
for (size_t i = 0; i < headers_count; ++i) {
1317+
const struct aws_byte_cursor *name = &headers[i].name;
1318+
const struct aws_byte_cursor *value = &headers[i].value;
1319+
if (request->send_data.request_id == NULL && aws_byte_cursor_eq(name, &g_request_id_header_name)) {
1320+
request->send_data.request_id = aws_string_new_from_cursor(connection->request->allocator, value);
1321+
if (collect_metrics) {
1322+
request->send_data.metrics->req_resp_info_metrics.request_id =
1323+
aws_string_new_from_cursor(connection->request->allocator, value);
1324+
}
1325+
}
1326+
if (request->send_data.amz_id_2 == NULL && aws_byte_cursor_eq(name, &g_amz_id_2_header_name)) {
1327+
request->send_data.amz_id_2 = aws_string_new_from_cursor(connection->request->allocator, value);
1328+
}
1329+
if (collect_metrics) {
1330+
aws_http_headers_add(request->send_data.metrics->req_resp_info_metrics.response_headers, *name, *value);
1331+
}
1332+
if (should_record_headers) {
13281333
aws_http_headers_add(request->send_data.response_headers, *name, *value);
13291334
}
13301335
}
@@ -1624,12 +1629,15 @@ void aws_s3_meta_request_send_request_finish_default(
16241629

16251630
AWS_LOGF_DEBUG(
16261631
AWS_LS_S3_META_REQUEST,
1627-
"id=%p: Request %p finished with error code %d (%s) and response status %d",
1632+
"id=%p: Request %p finished with error code %d (%s) and response status %d, x-amz-request-id: %s, x-amz-id-2: "
1633+
"%s",
16281634
(void *)meta_request,
16291635
(void *)request,
16301636
error_code,
16311637
aws_error_debug_str(error_code),
1632-
response_status);
1638+
response_status,
1639+
request->send_data.request_id ? aws_string_c_str(request->send_data.request_id) : "N/A",
1640+
request->send_data.amz_id_2 ? aws_string_c_str(request->send_data.amz_id_2) : "N/A");
16331641

16341642
enum aws_s3_connection_finish_code finish_code = AWS_S3_CONNECTION_FINISH_CODE_FAILED;
16351643

source/s3_request.c

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ void aws_s3_request_clean_up_send_data(struct aws_s3_request *request) {
100100
request->send_data.signable = NULL;
101101
aws_http_headers_release(request->send_data.response_headers);
102102
request->send_data.response_headers = NULL;
103+
aws_string_destroy(request->send_data.request_id);
104+
aws_string_destroy(request->send_data.amz_id_2);
103105

104106
aws_byte_buf_clean_up(&request->send_data.response_body);
105107

source/s3_util.c

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const struct aws_byte_cursor g_host_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_
2929
const struct aws_byte_cursor g_range_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Range");
3030
const struct aws_byte_cursor g_if_match_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-Match");
3131
const struct aws_byte_cursor g_request_id_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-request-id");
32+
const struct aws_byte_cursor g_amz_id_2_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-id-2");
3233
const struct aws_byte_cursor g_etag_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ETag");
3334
const struct aws_byte_cursor g_content_range_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Range");
3435
const struct aws_byte_cursor g_content_type_header_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Type");

0 commit comments

Comments
 (0)