sk0x50 commented on code in PR #1027: URL: https://github.com/apache/ignite-3/pull/1027#discussion_r957457134
########## modules/metrics/src/main/java/org/apache/ignite/internal/metrics/exporters/PushMetricExporter.java: ########## @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.metrics.exporters; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.thread.NamedThreadFactory; +import org.apache.ignite.internal.util.IgniteUtils; + +/** + * Base class for push metrics exporters, according to terminology from {@link MetricExporter} docs. + * Every {@code period} of time {@link PushMetricExporter#report()} will be called + * to push metrics to the external system. + */ +public abstract class PushMetricExporter extends BasicMetricExporter { + /** Logger. */ + protected final IgniteLogger log = Loggers.forClass(getClass()); + + /** Default export period in milliseconds. */ + public static final long DFLT_EXPORT_PERIOD = 60_000; + + /** Export period. */ + private long period = DFLT_EXPORT_PERIOD; + + /** Export task future. */ + private ScheduledFuture<?> fut; + + /** Export scheduler. */ + private ScheduledExecutorService scheduler; + + /** {@inheritDoc} */ + @Override + public void start() { + scheduler = + Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("metrics-exporter", log)); + + fut = scheduler.scheduleWithFixedDelay(() -> { + try { + report(); + } catch (Throwable th) { + log.error("Metrics export error. " + + "This exporter will be stopped [class=" + getClass() + ",name=" + name() + ']', th); + + throw th; Review Comment: Well, in this case the thread pool will be terminated and metric updates will not be pushed anymore. Anyway, I think we need clarify this moment and update javadoc in accordance with that. -- 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]
