Skip to content

Commit

Permalink
Merge pull request #26403 from Ladicek/fault-tolerance-dev-ui
Browse files Browse the repository at this point in the history
Add dev UI for SmallRye Fault Tolerance
  • Loading branch information
gsmet authored Jul 4, 2022
2 parents 5aff414 + c9282ca commit 7c5db92
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 4 deletions.
2 changes: 1 addition & 1 deletion extensions/smallrye-fault-tolerance/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-smallrye-fault-tolerance-deployment</artifactId>
<name>Quarkus - SmallRye Fault tolerance - Deployment</name>
<name>Quarkus - SmallRye Fault Tolerance - Deployment</name>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.smallrye.faulttolerance.deployment.devconsole;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem;
import io.quarkus.smallrye.faulttolerance.runtime.FaultToleranceOperationsDevConsoleSupplier;

public class FaultToleranceDevConsoleProcessor {
@BuildStep(onlyIf = IsDevelopment.class)
DevConsoleRuntimeTemplateInfoBuildItem collectInfo(CurateOutcomeBuildItem curateOutcome) {
return new DevConsoleRuntimeTemplateInfoBuildItem("ftOperations", new FaultToleranceOperationsDevConsoleSupplier(),
this.getClass(), curateOutcome);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="{urlbase}/ft-operations" class="badge badge-light">
<i class="fa fa-life-ring fa-fw"></i>
Guarded Methods <span class="badge badge-light">{info:ftOperations.size}</span></a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{#include main fluid=true}
{#style}
.annotation {
color: gray;
font-style: italic;
}
span.larger-badge {
font-size: 0.9em;
}
span.app-class {
cursor:pointer;
color:blue;
text-decoration:underline;
}
{/style}

{#script}
$(document).ready(function(){
if (!ideKnown()) {
return;
}
$(".class-candidate").each(function() {
var className = $(this).text();
if (appClassLocation(className)) {
$(this).addClass("app-class");
}
});

$(".app-class").on("click", function() {
openInIDE($(this).text());
});
});
{/script}

{#title}Guarded Methods{/title}

{#body}
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Bean Class</th>
<th scope="col">Method</th>
<th scope="col">Fault Tolerance Strategies</th>
</tr>
</thead>
<tbody>
{#for ftOperation in info:ftOperations}
<tr>
<td>{ftOperation_count}</td>
<td>
<span class="class-candidate" title="{ftOperation.beanClass.name}">{#if ftOperation.beanClass.name.length > 70}{ftOperation.beanClass.name.substring(0,70)}...{#else}{ftOperation.beanClass.name}{/if}</span>
</td>
<td>
<code><span title="{ftOperation.methodDescriptor.declaringClass.name}#{ftOperation.methodDescriptor.name}()">{ftOperation.methodDescriptor.name}()</span></code>
</td>
<td>
<ul>
{#if ftOperation.applyFaultTolerance}
<li>
@ApplyFaultTolerance<span class="annotation">("{ftOperation.applyFaultTolerance.value}")</span>
</li>
{/if}

{#if ftOperation.asynchronous}
<li>@Asynchronous</li>
{/if}

{#if ftOperation.blocking}
<li>@Blocking</li>
{/if}

{#if ftOperation.nonBlocking}
<li>@NonBlocking</li>
{/if}

{#if ftOperation.bulkhead}
<li>@Bulkhead<span class="annotation">(value = {ftOperation.bulkhead.value},
waitingTaskQueue = {ftOperation.bulkhead.waitingTaskQueue})</span></li>
{/if}

{#if ftOperation.circuitBreaker}
<li>
@CircuitBreaker<span class="annotation">(delay = {ftOperation.circuitBreaker.delay} {ftOperation.circuitBreaker.delayUnit.name},
requestVolumeThreshold = {ftOperation.circuitBreaker.requestVolumeThreshold},
failureRatio = {ftOperation.circuitBreaker.failureRatio},
successThreshold = {ftOperation.circuitBreaker.successThreshold},
failOn = [{#each ftOperation.circuitBreaker.failOn}{it.name}{#if it_hasNext}, {/if}{/each}],
skipOn = [{#each ftOperation.circuitBreaker.skipOn}{it.name}{#if it_hasNext}, {/if}{/each}])</span>
{#if ftOperation.circuitBreakerName}
<ul>
<li>@CircuitBreakerName<span class="annotation">("{ftOperation.circuitBreakerName.value}")</span></li>
</ul>
{/if}
</li>
{/if}

{#if ftOperation.fallback}
<li>
@Fallback<span class="annotation">(value = {ftOperation.fallback.value.name},
fallbackMethod = "{ftOperation.fallback.fallbackMethod}",
applyOn = [{#each ftOperation.fallback.applyOn}{it.name}{#if it_hasNext}, {/if}{/each}],
skipOn = [{#each ftOperation.fallback.skipOn}{it.name}{#if it_hasNext}, {/if}{/each}])</span>
</li>
{/if}

{#if ftOperation.retry}
<li>
@Retry<span class="annotation">(maxRetries = {ftOperation.retry.maxRetries},
delay = {ftOperation.retry.delay} {ftOperation.retry.delayUnit.name},
maxDuration = {ftOperation.retry.maxDuration} {ftOperation.retry.durationUnit.name},
jitter = {ftOperation.retry.jitter} {ftOperation.retry.jitterDelayUnit.name},
retryOn = [{#each ftOperation.retry.retryOn}{it.name}{#if it_hasNext}, {/if}{/each}],
abortOn = [{#each ftOperation.retry.abortOn}{it.name}{#if it_hasNext}, {/if}{/each}])</span>
{#if ftOperation.exponentialBackoff || ftOperation.fibonacciBackoff || ftOperation.customBackoff}
<ul>
{#if ftOperation.exponentialBackoff}
<li>@ExponentialBackoff<span class="annotation">(factor = {ftOperation.exponentialBackoff.factor},
maxDelay = {ftOperation.exponentialBackoff.maxDelay} {ftOperation.exponentialBackoff.maxDelayUnit.name})</span></li>
{/if}
{#if ftOperation.fibonacciBackoff}
<li>@FibonacciBackoff<span class="annotation">(maxDelay = {ftOperation.fibonacciBackoff.maxDelay} {ftOperation.fibonacciBackoff.maxDelayUnit.name})</span></li>
{/if}
{#if ftOperation.customBackoff}
<li>@CustomBackoff<span class="annotation">({ftOperation.customBackoff.value.name})</span></li>
{/if}
</ul>
{/if}
</li>
{/if}

{#if ftOperation.timeout}
<li>
@Timeout<span class="annotation">({ftOperation.timeout.value} {ftOperation.timeout.unit.name})</span>
</li>
{/if}
</ul>
</td>
</tr>
{/for}
</tbody>
</table>
{/body}
{/include}
2 changes: 1 addition & 1 deletion extensions/smallrye-fault-tolerance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-smallrye-fault-tolerance-parent</artifactId>
<name>Quarkus - SmallRye Fault tolerance</name>
<name>Quarkus - SmallRye Fault Tolerance</name>

<packaging>pom</packaging>
<modules>
Expand Down
4 changes: 2 additions & 2 deletions extensions/smallrye-fault-tolerance/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
<name>Quarkus - SmallRye Fault tolerance - Runtime</name>
<description>Define fault-tolerant services</description>
<name>Quarkus - SmallRye Fault Tolerance - Runtime</name>
<description>Build fault-tolerant network services</description>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.smallrye.faulttolerance.runtime;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;

import io.quarkus.arc.Arc;
import io.smallrye.faulttolerance.config.FaultToleranceOperation;

public class FaultToleranceOperationsDevConsoleSupplier implements Supplier<List<FaultToleranceOperation>> {
@Override
public List<FaultToleranceOperation> get() {
QuarkusFaultToleranceOperationProvider provider = Arc.container()
.select(QuarkusFaultToleranceOperationProvider.class).get();
List<FaultToleranceOperation> operations = new ArrayList<>(provider.getOperationCache().values());
operations.sort(Comparator.comparing(FaultToleranceOperation::getName));
for (FaultToleranceOperation operation : operations) {
operation.materialize();
}
return operations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private FaultToleranceOperation createAtRuntime(CacheKey key) {
return FaultToleranceOperation.create(FaultToleranceMethods.create(key.beanClass, key.method));
}

Map<CacheKey, FaultToleranceOperation> getOperationCache() {
return operationCache;
}

static class CacheKey {
private Class<?> beanClass;
private Method method;
Expand Down

0 comments on commit 7c5db92

Please sign in to comment.