2222import java .util .concurrent .CountDownLatch ;
2323import java .util .concurrent .TimeUnit ;
2424import javax .management .JMException ;
25+
2526import org .apache .yetus .audience .InterfaceAudience ;
2627import org .apache .zookeeper .audit .ZKAuditProvider ;
2728import org .apache .zookeeper .jmx .ManagedUtil ;
@@ -115,6 +116,7 @@ protected void initializeAndRun(String[] args) throws ConfigException, IOExcepti
115116
116117 /**
117118 * Run from a ServerConfig.
119+ *
118120 * @param config ServerConfig to use.
119121 * @throws IOException
120122 * @throws AdminServerException
@@ -125,12 +127,13 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
125127 try {
126128 try {
127129 metricsProvider = MetricsProviderBootstrap .startMetricsProvider (
128- config .getMetricsProviderClassName (),
129- config .getMetricsProviderConfiguration ());
130+ config .getMetricsProviderClassName (),
131+ config .getMetricsProviderConfiguration ());
130132 } catch (MetricsProviderLifeCycleException error ) {
131133 throw new IOException ("Cannot boot MetricsProvider " + config .getMetricsProviderClassName (), error );
132134 }
133- ServerMetrics .metricsProviderInitialized (metricsProvider );
135+
136+ metricsProviderInitialized ();
134137 ProviderRegistry .initialize ();
135138 // Note that this thread isn't going to be doing anything else,
136139 // so rather than spawning another thread, we will just call
@@ -169,11 +172,11 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
169172 }
170173
171174 containerManager = new ContainerManager (
172- zkServer .getZKDatabase (),
173- zkServer .firstProcessor ,
174- Integer .getInteger ("znode.container.checkIntervalMs" , (int ) TimeUnit .MINUTES .toMillis (1 )),
175- Integer .getInteger ("znode.container.maxPerMinute" , 10000 ),
176- Long .getLong ("znode.container.maxNeverUsedIntervalMs" , 0 )
175+ zkServer .getZKDatabase (),
176+ zkServer .firstProcessor ,
177+ Integer .getInteger ("znode.container.checkIntervalMs" , (int ) TimeUnit .MINUTES .toMillis (1 )),
178+ Integer .getInteger ("znode.container.maxPerMinute" , 10000 ),
179+ Long .getLong ("znode.container.maxNeverUsedIntervalMs" , 0 )
177180 );
178181 containerManager .start ();
179182 ZKAuditProvider .addZKStartStopAuditLog ();
@@ -210,6 +213,18 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
210213 }
211214 }
212215
216+ private void metricsProviderInitialized () {
217+ try {
218+ ServerMetrics .metricsProviderInitialized (metricsProvider );
219+ } catch (Exception e ) {
220+ if (e instanceof ClassNotFoundException ) {
221+ LOG .warn ("Metrics provider not found, metrics will not be reported" );
222+ return ;
223+ }
224+ throw e ;
225+ }
226+ }
227+
213228 /**
214229 * Shutdown the serving instance
215230 */
0 commit comments