Skip to content

Commit

Permalink
Support customize collector sync period (#13140)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ authored Sep 28, 2023
1 parent 0d88f62 commit 34c5bbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public interface MetricsConstants {

String ENABLE_COLLECTOR_SYNC_KEY = "enable.collector.sync";

String COLLECTOR_SYNC_PERIOD_KEY = "collector.sync.period";

String AGGREGATION_COLLECTOR_KEY = "aggregation";

String AGGREGATION_ENABLED_KEY = "aggregation.enabled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class MetricsConfig extends AbstractConfig {
*/
private Boolean enableCollectorSync;

/**
* Collector sync period.
*/
private Integer collectorSyncPeriod;

/**
* @deprecated After metrics config is refactored.
* This parameter should no longer use and will be deleted in the future.
Expand Down Expand Up @@ -248,6 +253,14 @@ public void setEnableCollectorSync(Boolean enableCollectorSync) {
this.enableCollectorSync = enableCollectorSync;
}

public Integer getCollectorSyncPeriod() {
return collectorSyncPeriod;
}

public void setCollectorSyncPeriod(Integer collectorSyncPeriod) {
this.collectorSyncPeriod = collectorSyncPeriod;
}

public Boolean getUseGlobalRegistry() {
return useGlobalRegistry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_METRICS_COLLECTOR_EXCEPTION;
import static org.apache.dubbo.common.constants.MetricsConstants.COLLECTOR_SYNC_PERIOD_KEY;
import static org.apache.dubbo.common.constants.MetricsConstants.ENABLE_COLLECTOR_SYNC_KEY;
import static org.apache.dubbo.common.constants.MetricsConstants.ENABLE_JVM_METRICS_KEY;

Expand All @@ -77,7 +78,7 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
private ScheduledExecutorService collectorSyncJobExecutor = null;

private static final int DEFAULT_SCHEDULE_INITIAL_DELAY = 5;
private static final int DEFAULT_SCHEDULE_PERIOD = 3;
private static final int DEFAULT_SCHEDULE_PERIOD = 60;

protected AbstractMetricsReporter(URL url, ApplicationModel applicationModel) {
this.url = url;
Expand Down Expand Up @@ -143,9 +144,11 @@ private void initCollectors() {
private void scheduleMetricsCollectorSyncJob() {
boolean enableCollectorSync = url.getParameter(ENABLE_COLLECTOR_SYNC_KEY, true);
if (enableCollectorSync) {
int collectSyncPeriod = url.getParameter(COLLECTOR_SYNC_PERIOD_KEY, DEFAULT_SCHEDULE_PERIOD);

NamedThreadFactory threadFactory = new NamedThreadFactory("metrics-collector-sync-job", true);
collectorSyncJobExecutor = Executors.newScheduledThreadPool(1, threadFactory);
collectorSyncJobExecutor.scheduleWithFixedDelay(this::refreshData, DEFAULT_SCHEDULE_INITIAL_DELAY, DEFAULT_SCHEDULE_PERIOD, TimeUnit.SECONDS);
collectorSyncJobExecutor.scheduleWithFixedDelay(this::refreshData, DEFAULT_SCHEDULE_INITIAL_DELAY, collectSyncPeriod, TimeUnit.SECONDS);
}
}

Expand Down

0 comments on commit 34c5bbf

Please sign in to comment.