Skip to content

Commit

Permalink
[WFLY-19324] Anonymous 'captor' service does not reliably provide Ope…
Browse files Browse the repository at this point in the history
…nTelemetryConfig; use the DeploymentUnit AttachmentKey mechanism
  • Loading branch information
bstansberry committed Aug 3, 2024
1 parent 5f5fd69 commit 3e5f98d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.wildfly.extension.microprofile.telemetry.MicroProfileTelemetrySubsystemDefinition.EXPORTED_MODULES;

import org.jboss.as.controller.ServiceNameFactory;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand All @@ -15,17 +16,18 @@
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.service.ServiceName;
import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig;
import org.wildfly.service.ServiceDependency;

class MicroProfileTelemetryDependencyProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) {
addDependencies(phaseContext.getDeploymentUnit());

// Ensure the OpenTelemetryConfig is available before the next phase DeploymentUnitPhaseService starts
phaseContext.requires(ServiceDependency.on(ServiceName.parse(WildFlyOpenTelemetryConfig.SERVICE_DESCRIPTOR.getName())));
// Ensure the OpenTelemetryConfig is available to the Phase.POST_MODULE MicroProfileTelemetryDeploymentProcessor
// TODO WFCORE-6491 the kernel should support an API such that an OSH can record this requirement without
// needing to involve a DUP like this one that is separate from the one that consumes the dependency.
phaseContext.addDeploymentDependency(ServiceNameFactory.resolveServiceName(WildFlyOpenTelemetryConfig.SERVICE_DESCRIPTOR),
MicroProfileTelemetryDeploymentProcessor.CONFIG_ATTACHMENT_KEY);
}

private void addDependencies(DeploymentUnit deploymentUnit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand All @@ -25,11 +25,8 @@
import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig;

public class MicroProfileTelemetryDeploymentProcessor implements DeploymentUnitProcessor {
private final Supplier<WildFlyOpenTelemetryConfig> configSupplier;

public MicroProfileTelemetryDeploymentProcessor(Supplier<WildFlyOpenTelemetryConfig> configSupplier) {
this.configSupplier = configSupplier;
}
static final AttachmentKey<WildFlyOpenTelemetryConfig> CONFIG_ATTACHMENT_KEY = AttachmentKey.create(WildFlyOpenTelemetryConfig.class);

@Override
public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws DeploymentUnitProcessingException {
Expand All @@ -41,11 +38,12 @@ public void deploy(DeploymentPhaseContext deploymentPhaseContext) throws Deploym
try {
final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
final WeldCapability weldCapability = support.getCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class);
if (weldCapability != null && !weldCapability.isPartOfWeldDeployment(deploymentUnit)) {
if (weldCapability == null || !weldCapability.isPartOfWeldDeployment(deploymentUnit)) {
MPTEL_LOGGER.debug("The deployment does not have Jakarta Contexts and Dependency Injection enabled. " +
"Skipping MicroProfile Telemetry integration.");
} else {
Map<String, String> properties = new HashMap<>(configSupplier.get().properties());
WildFlyOpenTelemetryConfig config = deploymentUnit.getAttachment(CONFIG_ATTACHMENT_KEY);
Map<String, String> properties = new HashMap<>(config.properties());
if (!properties.containsKey("otel.service.name")) {
properties.put("otel.service.name", getServiceName(deploymentUnit));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@

import static org.wildfly.extension.microprofile.telemetry.MicroProfileTelemetryExtensionLogger.MPTEL_LOGGER;

import java.util.concurrent.atomic.AtomicReference;

import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
import org.jboss.dmr.ModelNode;
import org.wildfly.extension.opentelemetry.api.WildFlyOpenTelemetryConfig;
import org.wildfly.subsystem.service.ServiceDependency;
import org.wildfly.subsystem.service.ServiceInstaller;

public class MicroProfileTelemetrySubsystemAdd extends AbstractBoottimeAddStepHandler {
private final AtomicReference<WildFlyOpenTelemetryConfig> openTelemetryConfig = new AtomicReference<>();

MicroProfileTelemetrySubsystemAdd() {
super();
Expand All @@ -36,12 +30,6 @@ protected void performBoottime(OperationContext context, ModelNode operation, Mo

super.performBoottime(context, operation, model);

ServiceInstaller.builder(ServiceDependency.on(WildFlyOpenTelemetryConfig.SERVICE_DESCRIPTOR))
.withCaptor(openTelemetryConfig::set)
.build()
.install(context);


context.addStep(new AbstractDeploymentChainStep() {
@Override
public void execute(DeploymentProcessorTarget processorTarget) {
Expand All @@ -55,7 +43,7 @@ public void execute(DeploymentProcessorTarget processorTarget) {
MicroProfileTelemetryExtension.SUBSYSTEM_NAME,
Phase.POST_MODULE,
Phase.POST_MODULE_MICROPROFILE_TELEMETRY,
new MicroProfileTelemetryDeploymentProcessor(openTelemetryConfig::get));
new MicroProfileTelemetryDeploymentProcessor());
}
}, OperationContext.Stage.RUNTIME);
}
Expand Down

0 comments on commit 3e5f98d

Please sign in to comment.