chenBright commented on code in PR #3773:
URL: https://github.com/apache/brpc/pull/3773#discussion_r4729536556
##########
test/brpc_builtin_service_unittest.cpp:
##########
@@ -171,6 +171,40 @@ void CheckTraceId(const brpc::Controller& cntl,
ASSERT_TRUE(pos != std::string::npos) << expect_str;
}
+void CheckCreatedTimeNearNow(const brpc::Controller& cntl) {
+ const std::string& content = cntl.response_attachment().to_string();
+ const std::size_t header = content.find("CreatedTime");
+ ASSERT_NE(std::string::npos, header) << content;
+ const std::size_t header_end = content.find('\n', header);
+ ASSERT_NE(std::string::npos, header_end) << content;
+ const std::size_t col_end = content.find('|', header_end);
+ ASSERT_NE(std::string::npos, col_end) << content;
+ const std::string created =
+ content.substr(header_end + 1, col_end - header_end - 1);
+ int year = 0, month = 0, day = 0;
+ int hour = 0, minute = 0, second = 0, usec = 0;
+ ASSERT_EQ(7, sscanf(created.c_str(), "%d/%d/%d-%d:%d:%d.%d",
+ &year, &month, &day, &hour, &minute, &second, &usec))
+ << "created=" << created;
+
+ struct tm tm_val;
+ memset(&tm_val, 0, sizeof(tm_val));
+ tm_val.tm_year = year - 1900;
+ tm_val.tm_mon = month - 1;
+ tm_val.tm_mday = day;
+ tm_val.tm_hour = hour;
+ tm_val.tm_min = minute;
+ tm_val.tm_sec = second;
+ tm_val.tm_isdst = -1;
+ const time_t created_s = mktime(&tm_val);
Review Comment:
When daylight saving time ends and clocks are set back, `01:30` on the page
can correspond to two times an hour apart. `tm_isdst = -1` cannot determine
which occurrence the string refers to, so if `mktime` selects the other one,
correct output will exceed the 10-minute threshold.
##########
src/brpc/builtin/connections_service.cpp:
##########
@@ -244,7 +245,9 @@ void ConnectionsService::PrintConnections(
}
}
ptr->GetStat(&stat);
- PrintRealDateTime(os, ptr->_reset_fd_real_us);
+ const int64_t reset_fd_to_now_us =
+ butil::cpuwide_time_us() - ptr->_reset_fd_real_us;
+ PrintRealDateTime(os, butil::gettimeofday_us() -
reset_fd_to_now_us);
Review Comment:
This uses the wall clock at query time to work backward to the fd's reset
time. In the default Linux build, after the host sleeps for 30 minutes,
`CLOCK_MONOTONIC` accumulates 30 minutes less, so the same still-live
connection will appear to have been created 30 minutes later after a refresh.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]