Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customize collector sync period #13140

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading