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

add enabled configuration for metrics #1266

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -219,6 +219,11 @@ public class ConfigurationKeys {
*/
public static final String METRICS_PREFIX = "metrics.";

/**
* The constant METRICS_ENABLED.
*/
public static final String METRICS_ENABLED = "enabled";

/**
* The constant METRICS_REGISTRY_TYPE.
*/
Expand Down
20 changes: 13 additions & 7 deletions server/src/main/java/io/seata/server/metrics/MetricsManager.java
Expand Up @@ -17,6 +17,8 @@

import java.util.List;

import io.seata.config.ConfigurationFactory;
import io.seata.core.constants.ConfigurationKeys;
import io.seata.metrics.exporter.Exporter;
import io.seata.metrics.exporter.ExporterFactory;
import io.seata.metrics.registry.Registry;
Expand Down Expand Up @@ -44,13 +46,17 @@ public Registry getRegistry() {
}

public void init() {
registry = RegistryFactory.getInstance();
if (registry != null) {
List<Exporter> exporters = ExporterFactory.getInstanceList();
//only at least one metrics exporter implement had imported in pom then need register MetricsSubscriber
if (exporters.size() != 0) {
exporters.forEach(exporter -> exporter.setRegistry(registry));
EventBusManager.get().register(new MetricsSubscriber(registry));
boolean enabled = ConfigurationFactory.getInstance().getBoolean(
ConfigurationKeys.METRICS_PREFIX + ConfigurationKeys.METRICS_ENABLED, false);
if (enabled) {
registry = RegistryFactory.getInstance();
if (registry != null) {
List<Exporter> exporters = ExporterFactory.getInstanceList();
//only at least one metrics exporter implement had imported in pom then need register MetricsSubscriber
if (exporters.size() != 0) {
exporters.forEach(exporter -> exporter.setRegistry(registry));
EventBusManager.get().register(new MetricsSubscriber(registry));
}
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions server/src/main/resources/file.conf
Expand Up @@ -111,9 +111,10 @@ transaction {
}

## metrics settings
#metrics {
# registry-type = "compact"
# # multi exporters use comma divided
# exporter-list = "prometheus"
# exporter-prometheus-port = 9898
#}
metrics {
enabled = false
registry-type = "compact"
# multi exporters use comma divided
exporter-list = "prometheus"
exporter-prometheus-port = 9898
}
1 change: 1 addition & 0 deletions server/src/test/resources/file.conf
Expand Up @@ -6,6 +6,7 @@ recovery {

## metrics settings
metrics {
enabled = true
registry-type = "compact"
# multi exporters use comma divided
exporter-list = "prometheus"
Expand Down