From 164df8d4660ac5ed73db0b5ea74b99c391f7dbf8 Mon Sep 17 00:00:00 2001 From: "Wang, Fei" Date: Thu, 26 Dec 2024 18:22:48 -0800 Subject: [PATCH] [KYUUBI #6866][FOLLOWUP] Prevent register gauge conflicts if both thrift binary SSL and thrift http SSL enabled ### Why are the changes needed? Followup for https://github.com/apache/kyuubi/pull/6866 It would throw exception if both thrift binary SSL and thrift http SSL enabled ### How was this patch tested? ### Was this patch authored or co-authored using generative AI tooling? No. Closes #6872 from turboFei/duplicate_gauge. Closes #6866 ea356766e [Wang, Fei] prevent conflicts 982f175fd [Wang, Fei] conflicts Authored-by: Wang, Fei Signed-off-by: Wang, Fei --- .../org/apache/kyuubi/metrics/MetricsSystem.scala | 4 ++++ .../main/scala/org/apache/kyuubi/util/SSLUtils.scala | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala index 26344ca56a3..3db6daba4b2 100644 --- a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala +++ b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala @@ -58,6 +58,10 @@ class MetricsSystem extends CompositeService("MetricsSystem") { meter.mark(value) } + def getGauge[T](name: String): Option[Gauge[T]] = { + Option(registry.gauge(name)) + } + def registerGauge[T](name: String, value: => T, default: T): Unit = { registry.register( MetricRegistry.name(name), diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/util/SSLUtils.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/util/SSLUtils.scala index f73f87b904e..c0765b9a40b 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/util/SSLUtils.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/util/SSLUtils.scala @@ -56,13 +56,15 @@ object SSLUtils extends Logging { keyStorePath.get, keyStorePassword.get, keyStoreType).foreach { expiration => - info(s"Thrift SSL Serve KeyStore ${keyStorePath.get} will expire at:" + + info(s"Thrift SSL Server KeyStore ${keyStorePath.get} will expire at:" + s" ${Utils.getDateFromTimestamp(expiration)}") MetricsSystem.tracing { ms => - ms.registerGauge( - MetricsConstants.THRIFT_SSL_CERT_EXPIRATION, - expiration - System.currentTimeMillis(), - 0L) + if (ms.getGauge(MetricsConstants.THRIFT_SSL_CERT_EXPIRATION).isEmpty) { + ms.registerGauge( + MetricsConstants.THRIFT_SSL_CERT_EXPIRATION, + expiration - System.currentTimeMillis(), + 0L) + } } } }