-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #681 from smallrye/observability
Stork observability support
- Loading branch information
Showing
22 changed files
with
945 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/src/main/java/io/smallrye/stork/api/observability/NoopObservationCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.smallrye.stork.api.observability; | ||
|
||
import java.util.List; | ||
|
||
import io.smallrye.stork.api.ServiceInstance; | ||
|
||
public class NoopObservationCollector implements ObservationCollector { | ||
|
||
private static final StorkEventHandler NOOP_HANDLER = ev -> { | ||
// NOOP | ||
}; | ||
|
||
public static final StorkObservation NOOP_STORK_EVENT = new StorkObservation( | ||
null, null, | ||
null, NOOP_HANDLER) { | ||
@Override | ||
public void onServiceDiscoverySuccess(List<ServiceInstance> instances) { | ||
// Noop | ||
} | ||
|
||
@Override | ||
public void onServiceDiscoveryFailure(Throwable throwable) { | ||
// Noop | ||
} | ||
|
||
@Override | ||
public void onServiceSelectionSuccess(long id) { | ||
// Noop | ||
} | ||
|
||
@Override | ||
public void onServiceSelectionFailure(Throwable throwable) { | ||
// Noop | ||
} | ||
}; | ||
|
||
@Override | ||
public StorkObservation create(String serviceName, String serviceDiscoveryType, | ||
String serviceSelectionType) { | ||
return NOOP_STORK_EVENT; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
api/src/main/java/io/smallrye/stork/api/observability/ObservationCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.smallrye.stork.api.observability; | ||
|
||
public interface ObservationCollector { | ||
|
||
StorkObservation create(String serviceName, String serviceDiscoveryType, String serviceSelectionType); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/java/io/smallrye/stork/api/observability/StorkEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.smallrye.stork.api.observability; | ||
|
||
public interface StorkEventHandler { | ||
void complete(StorkObservation event); | ||
} |
117 changes: 117 additions & 0 deletions
117
api/src/main/java/io/smallrye/stork/api/observability/StorkObservation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package io.smallrye.stork.api.observability; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import io.smallrye.stork.api.ServiceInstance; | ||
|
||
public class StorkObservation { | ||
// Handler / Reporter | ||
private final StorkEventHandler handler; | ||
|
||
// Metadata | ||
private final String serviceName; | ||
private final String serviceDiscoveryType; | ||
private final String serviceSelectionType; | ||
|
||
// Time | ||
private final long begin; | ||
private volatile long endOfServiceDiscovery; | ||
private volatile long endOfServiceSelection; | ||
|
||
// Service discovery data | ||
private volatile int instancesCount = -1; | ||
|
||
// Service selection data | ||
private volatile long selectedInstanceId = -1L; | ||
|
||
// Overall status | ||
private volatile boolean done; | ||
private volatile boolean serviceDiscoverySuccessful = false; | ||
private volatile Throwable failure; | ||
|
||
public StorkObservation(String serviceName, String serviceDiscoveryType, String serviceSelectionType, | ||
StorkEventHandler handler) { | ||
this.handler = handler; | ||
this.serviceName = serviceName; | ||
this.serviceDiscoveryType = serviceDiscoveryType; | ||
this.serviceSelectionType = serviceSelectionType; | ||
this.begin = System.nanoTime(); | ||
} | ||
|
||
public void onServiceDiscoverySuccess(List<ServiceInstance> instances) { | ||
this.endOfServiceDiscovery = System.nanoTime(); | ||
this.serviceDiscoverySuccessful = true; | ||
if (instances != null) { | ||
this.instancesCount = instances.size(); | ||
} else { | ||
this.instancesCount = 0; | ||
} | ||
} | ||
|
||
public void onServiceDiscoveryFailure(Throwable throwable) { | ||
this.endOfServiceDiscovery = System.nanoTime(); | ||
this.failure = throwable; | ||
} | ||
|
||
public void onServiceSelectionSuccess(long id) { | ||
this.endOfServiceSelection = System.nanoTime(); | ||
this.selectedInstanceId = id; | ||
this.done = true; | ||
this.handler.complete(this); | ||
} | ||
|
||
public void onServiceSelectionFailure(Throwable throwable) { | ||
this.endOfServiceSelection = System.nanoTime(); | ||
if (failure != throwable) { | ||
this.failure = throwable; | ||
} | ||
this.handler.complete(this); | ||
} | ||
|
||
public boolean isDone() { | ||
return done || failure != null; | ||
} | ||
|
||
public Duration getOverallDuration() { | ||
if (!isDone()) { | ||
return null; | ||
} | ||
return Duration.ofNanos(endOfServiceSelection - begin); | ||
} | ||
|
||
public Duration getServiceDiscoveryDuration() { | ||
return Duration.ofNanos(endOfServiceDiscovery - begin); | ||
} | ||
|
||
public Duration getServiceSelectionDuration() { | ||
if (!isDone()) { | ||
return null; | ||
} | ||
return Duration.ofNanos(endOfServiceSelection - endOfServiceDiscovery); | ||
} | ||
|
||
public String getServiceName() { | ||
return serviceName; | ||
} | ||
|
||
public String getServiceDiscoveryType() { | ||
return serviceDiscoveryType; | ||
} | ||
|
||
public String getServiceSelectionType() { | ||
return serviceSelectionType; | ||
} | ||
|
||
public int getDiscoveredInstancesCount() { | ||
return instancesCount; | ||
} | ||
|
||
public Throwable failure() { | ||
return failure; | ||
} | ||
|
||
public boolean isServiceDiscoverySuccessful() { | ||
return serviceDiscoverySuccessful; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/io/smallrye/stork/integration/ObservableStorkInfrastructure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.smallrye.stork.integration; | ||
|
||
import io.smallrye.stork.api.observability.ObservationCollector; | ||
|
||
public class ObservableStorkInfrastructure extends DefaultStorkInfrastructure { | ||
|
||
private final ObservationCollector observationCollector; | ||
|
||
public ObservableStorkInfrastructure(ObservationCollector observationCollector) { | ||
this.observationCollector = observationCollector; | ||
} | ||
|
||
@Override | ||
public ObservationCollector getObservationCollector() { | ||
return observationCollector; | ||
} | ||
} |
Oops, something went wrong.