use of org.eclipse.che.workspace.infrastructure.kubernetes.util.TracingSpanConstants.CHECK_SERVERS in project che-server by eclipse-che.
the class KubernetesInternalRuntime method checkServers.
/**
* Returns a function, the result of which the completable stage that performs servers checks and
* start of servers probes.
*/
private Function<Void, CompletionStage<Void>> checkServers(List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) {
// Need to get active span here to allow use in returned function;
final Span activeSpan = tracer.activeSpan();
return ignored -> {
// Span must be created within this lambda block, otherwise the span begins as soon as
// this function is called (i.e. before the previous steps in the machine boot chain
// are complete
final Span tracingSpan = tracer.buildSpan(CHECK_SERVERS).asChildOf(activeSpan).start();
TracingTags.WORKSPACE_ID.set(tracingSpan, getContext().getIdentity().getWorkspaceId());
TracingTags.MACHINE_NAME.set(tracingSpan, machine.getName());
// This completable future is used to unity the servers checks and start of probes
final CompletableFuture<Void> serversAndProbesFuture = new CompletableFuture<>();
final String machineName = machine.getName();
final RuntimeIdentity runtimeId = getContext().getIdentity();
final ServersChecker serverCheck = serverCheckerFactory.create(runtimeId, machineName, machine.getServers());
final CompletableFuture<?> serversReadyFuture;
LOG.debug("Performing servers check for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId());
try {
serversReadyFuture = serverCheck.startAsync(new ServerReadinessHandler(machineName));
toCancelFutures.add(serversReadyFuture);
serversAndProbesFuture.whenComplete((ok, ex) -> {
LOG.debug("Servers checks done for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId());
serversReadyFuture.cancel(true);
});
} catch (InfrastructureException ex) {
serversAndProbesFuture.completeExceptionally(ex);
TracingTags.setErrorStatus(tracingSpan, ex);
tracingSpan.finish();
return serversAndProbesFuture;
}
serversReadyFuture.whenComplete((BiConsumer<Object, Throwable>) (ok, ex) -> {
if (ex != null) {
serversAndProbesFuture.completeExceptionally(ex);
TracingTags.setErrorStatus(tracingSpan, ex);
tracingSpan.finish();
return;
}
try {
probeScheduler.schedule(probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler());
} catch (InfrastructureException iex) {
serversAndProbesFuture.completeExceptionally(iex);
}
serversAndProbesFuture.complete(null);
tracingSpan.finish();
});
return serversAndProbesFuture;
};
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.util.TracingSpanConstants.CHECK_SERVERS in project devspaces-images by redhat-developer.
the class KubernetesInternalRuntime method checkServers.
/**
* Returns a function, the result of which the completable stage that performs servers checks and
* start of servers probes.
*/
private Function<Void, CompletionStage<Void>> checkServers(List<CompletableFuture<?>> toCancelFutures, KubernetesMachineImpl machine) {
// Need to get active span here to allow use in returned function;
final Span activeSpan = tracer.activeSpan();
return ignored -> {
// Span must be created within this lambda block, otherwise the span begins as soon as
// this function is called (i.e. before the previous steps in the machine boot chain
// are complete
final Span tracingSpan = tracer.buildSpan(CHECK_SERVERS).asChildOf(activeSpan).start();
TracingTags.WORKSPACE_ID.set(tracingSpan, getContext().getIdentity().getWorkspaceId());
TracingTags.MACHINE_NAME.set(tracingSpan, machine.getName());
// This completable future is used to unity the servers checks and start of probes
final CompletableFuture<Void> serversAndProbesFuture = new CompletableFuture<>();
final String machineName = machine.getName();
final RuntimeIdentity runtimeId = getContext().getIdentity();
final ServersChecker serverCheck = serverCheckerFactory.create(runtimeId, machineName, machine.getServers());
final CompletableFuture<?> serversReadyFuture;
LOG.debug("Performing servers check for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId());
try {
serversReadyFuture = serverCheck.startAsync(new ServerReadinessHandler(machineName));
toCancelFutures.add(serversReadyFuture);
serversAndProbesFuture.whenComplete((ok, ex) -> {
LOG.debug("Servers checks done for machine '{}' in workspace '{}'", machineName, runtimeId.getWorkspaceId());
serversReadyFuture.cancel(true);
});
} catch (InfrastructureException ex) {
serversAndProbesFuture.completeExceptionally(ex);
TracingTags.setErrorStatus(tracingSpan, ex);
tracingSpan.finish();
return serversAndProbesFuture;
}
serversReadyFuture.whenComplete((BiConsumer<Object, Throwable>) (ok, ex) -> {
if (ex != null) {
serversAndProbesFuture.completeExceptionally(ex);
TracingTags.setErrorStatus(tracingSpan, ex);
tracingSpan.finish();
return;
}
try {
probeScheduler.schedule(probesFactory.getProbes(runtimeId, machineName, machine.getServers()), new ServerLivenessHandler());
} catch (InfrastructureException iex) {
serversAndProbesFuture.completeExceptionally(iex);
}
serversAndProbesFuture.complete(null);
tracingSpan.finish();
});
return serversAndProbesFuture;
};
}
Aggregations