Skip to content

Commit

Permalink
Reuse APMMeterService of APMTelemetryProvider (#104906)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosche authored Jan 30, 2024
1 parent 79d6c3e commit a3b1d86
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ public TelemetryProvider getTelemetryProvider(Settings settings) {
@Override
public Collection<?> createComponents(PluginServices services) {
final APMTracer apmTracer = telemetryProvider.get().getTracer();
final APMMeterService apmMeter = telemetryProvider.get().getMeterService();

apmTracer.setClusterName(services.clusterService().getClusterName().value());
apmTracer.setNodeName(services.clusterService().getNodeName());

final APMAgentSettings apmAgentSettings = new APMAgentSettings();
apmAgentSettings.syncAgentSystemProperties(settings);
final APMMeterService apmMeter = new APMMeterService(settings);
apmAgentSettings.addClusterSettingsListeners(services.clusterService(), telemetryProvider.get(), apmMeter);

apmAgentSettings.addClusterSettingsListeners(services.clusterService(), telemetryProvider.get());
logger.info("Sending apm metrics is {}", APMAgentSettings.TELEMETRY_METRICS_ENABLED_SETTING.get(settings) ? "enabled" : "disabled");
logger.info("Sending apm tracing is {}", APMAgentSettings.TELEMETRY_TRACING_ENABLED_SETTING.get(settings) ? "enabled" : "disabled");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ public class APMAgentSettings {

private static final Logger LOGGER = LogManager.getLogger(APMAgentSettings.class);

public void addClusterSettingsListeners(
ClusterService clusterService,
APMTelemetryProvider apmTelemetryProvider,
APMMeterService apmMeterService
) {
public void addClusterSettingsListeners(ClusterService clusterService, APMTelemetryProvider apmTelemetryProvider) {
final ClusterSettings clusterSettings = clusterService.getClusterSettings();
final APMTracer apmTracer = apmTelemetryProvider.getTracer();
final APMMeterService apmMeterService = apmTelemetryProvider.getMeterService();

clusterSettings.addSettingsUpdateConsumer(TELEMETRY_TRACING_ENABLED_SETTING, enabled -> {
apmTracer.setEnabled(enabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public APMMeterRegistry getMeterRegistry() {
}

/**
* @see APMAgentSettings#addClusterSettingsListeners(ClusterService, APMTelemetryProvider, APMMeterService)
* @see APMAgentSettings#addClusterSettingsListeners(ClusterService, APMTelemetryProvider)
*/
void setEnabled(boolean enabled) {
this.enabled = enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import org.elasticsearch.telemetry.apm.internal.tracing.APMTracer;

public class APMTelemetryProvider implements TelemetryProvider {
private final Settings settings;
private final APMTracer apmTracer;
private final APMMeterService apmMeterService;

public APMTelemetryProvider(Settings settings) {
this.settings = settings;
apmTracer = new APMTracer(settings);
apmMeterService = new APMMeterService(settings);
}
Expand All @@ -29,6 +27,10 @@ public APMTracer getTracer() {
return apmTracer;
}

public APMMeterService getMeterService() {
return apmMeterService;
}

@Override
public APMMeterRegistry getMeterRegistry() {
return apmMeterService.getMeterRegistry();
Expand Down

0 comments on commit a3b1d86

Please sign in to comment.