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

Reuse APMMeterService of APMTelemetryProvider #104906

Merged
merged 1 commit into from
Jan 30, 2024
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 @@ -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