This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 72430fb15 [clock] instantiate 'clock_ntp_status' first thing in
SystemNtp::Init()
72430fb15 is described below
commit 72430fb15b076e32d94eb75a850569d630785823
Author: Alexey Serbin <[email protected]>
AuthorDate: Mon Aug 28 15:34:13 2023 -0700
[clock] instantiate 'clock_ntp_status' first thing in SystemNtp::Init()
This moves the instantiation of the 'clock_ntp_status' metric to come
before various calls that might return an error. This follows the
semantics of the metrics more closely and also makes the
HybridClockTest.TestNtpDiagnostics test scenario to pass even on
machines where ntp_adjtime() returns an error (e.g., very ancient
Docker versions).
Change-Id: I2a75fc03c7bb625b0e4f15ea7944442a1cfe4b2e
Reviewed-on: http://gerrit.cloudera.org:8080/20433
Reviewed-by: Abhishek Chennaka <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
---
src/kudu/clock/system_ntp.cc | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/kudu/clock/system_ntp.cc b/src/kudu/clock/system_ntp.cc
index 4c2debbc7..ca8965c14 100644
--- a/src/kudu/clock/system_ntp.cc
+++ b/src/kudu/clock/system_ntp.cc
@@ -128,6 +128,13 @@ SystemNtp::SystemNtp(const scoped_refptr<MetricEntity>&
metric_entity)
}
Status SystemNtp::Init() {
+ // Register the metric before trying to call NTP-related calls which could
+ // return an error. The metric is here to provide useful diagnostics under
+ // all possible conditions.
+ METRIC_clock_ntp_status.InstantiateFunctionGauge(
+ metric_entity_, []() { return ClockNtpStatusForMetrics(); })->
+ AutoDetachToLastValue(&metric_detacher_);
+
timex t;
t.modes = 0; // set mode to 0 for read-only query
const int rc = ntp_adjtime(&t);
@@ -140,10 +147,6 @@ Status SystemNtp::Init() {
skew_ppm_ = t.tolerance >> 16;
VLOG(1) << "ntp_adjtime(): tolerance is " << t.tolerance;
- METRIC_clock_ntp_status.InstantiateFunctionGauge(
- metric_entity_, []() { return ClockNtpStatusForMetrics(); })->
- AutoDetachToLastValue(&metric_detacher_);
-
return Status::OK();
}