-
Notifications
You must be signed in to change notification settings - Fork 219
feat: runtime info for health probes #1594
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
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c3372ac
feat: runtime info for health probes
csviri a727960
wip
csviri b8a7274
unit test
csviri 51440f1
integration test
csviri d5fa459
sample
csviri 3e2e7c4
imroved probe setting
csviri b2b49da
docs
csviri 3ca4ec1
docs
csviri a0cfe1f
docs improvements
csviri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
81 changes: 81 additions & 0 deletions
81
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RuntimeInfo.java
This file contains hidden or 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,81 @@ | ||
package io.javaoperatorsdk.operator; | ||
|
||
import java.util.*; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.javaoperatorsdk.operator.health.EventSourceHealthIndicator; | ||
import io.javaoperatorsdk.operator.health.InformerWrappingEventSourceHealthIndicator; | ||
|
||
/** | ||
* RuntimeInfo in general is available when operator is fully started. You can use "isStarted" to | ||
* check that. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class RuntimeInfo { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(RuntimeInfo.class); | ||
|
||
private final Set<RegisteredController> registeredControllers; | ||
private final Operator operator; | ||
|
||
public RuntimeInfo(Operator operator) { | ||
this.registeredControllers = operator.getRegisteredControllers(); | ||
this.operator = operator; | ||
} | ||
|
||
public boolean isStarted() { | ||
return operator.isStarted(); | ||
} | ||
|
||
public Set<RegisteredController> getRegisteredControllers() { | ||
checkIfStarted(); | ||
return registeredControllers; | ||
} | ||
|
||
private void checkIfStarted() { | ||
if (!isStarted()) { | ||
log.warn( | ||
"Operator not started yet while accessing runtime info, this might lead to an unreliable behavior"); | ||
} | ||
} | ||
|
||
public boolean allEventSourcesAreHealthy() { | ||
checkIfStarted(); | ||
return registeredControllers.stream() | ||
.filter(rc -> !rc.getControllerHealthInfo().unhealthyEventSources().isEmpty()) | ||
.findFirst().isEmpty(); | ||
} | ||
|
||
/** | ||
* @return Aggregated Map with controller related event sources. | ||
*/ | ||
|
||
public Map<String, Map<String, EventSourceHealthIndicator>> unhealthyEventSources() { | ||
checkIfStarted(); | ||
Map<String, Map<String, EventSourceHealthIndicator>> res = new HashMap<>(); | ||
for (var rc : registeredControllers) { | ||
res.put(rc.getConfiguration().getName(), | ||
rc.getControllerHealthInfo().unhealthyEventSources()); | ||
} | ||
return res; | ||
} | ||
|
||
/** | ||
* @return Aggregated Map with controller related event sources that wraps an informer. Thus, | ||
* either a | ||
* {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource} | ||
* or an | ||
* {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}. | ||
*/ | ||
public Map<String, Map<String, InformerWrappingEventSourceHealthIndicator>> unhealthyInformerWrappingEventSourceHealthIndicator() { | ||
checkIfStarted(); | ||
Map<String, Map<String, InformerWrappingEventSourceHealthIndicator>> res = new HashMap<>(); | ||
for (var rc : registeredControllers) { | ||
res.put(rc.getConfiguration().getName(), rc.getControllerHealthInfo() | ||
.unhealthyInformerEventSourceHealthIndicators()); | ||
} | ||
return res; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...framework-core/src/main/java/io/javaoperatorsdk/operator/health/ControllerHealthInfo.java
This file contains hidden or 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,50 @@ | ||
package io.javaoperatorsdk.operator.health; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import io.javaoperatorsdk.operator.processing.event.EventSourceManager; | ||
|
||
@SuppressWarnings("rawtypes") | ||
public class ControllerHealthInfo { | ||
|
||
private EventSourceManager<?> eventSourceManager; | ||
|
||
public ControllerHealthInfo(EventSourceManager eventSourceManager) { | ||
this.eventSourceManager = eventSourceManager; | ||
} | ||
|
||
public Map<String, EventSourceHealthIndicator> eventSourceHealthIndicators() { | ||
return eventSourceManager.allEventSources().entrySet().stream() | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public Map<String, EventSourceHealthIndicator> unhealthyEventSources() { | ||
return eventSourceManager.allEventSources().entrySet().stream() | ||
.filter(e -> e.getValue().getStatus() == Status.UNHEALTHY) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public Map<String, InformerWrappingEventSourceHealthIndicator> informerEventSourceHealthIndicators() { | ||
return eventSourceManager.allEventSources().entrySet().stream() | ||
.filter(e -> e.getValue() instanceof InformerWrappingEventSourceHealthIndicator) | ||
.collect(Collectors.toMap(Map.Entry::getKey, | ||
e -> (InformerWrappingEventSourceHealthIndicator) e.getValue())); | ||
|
||
} | ||
|
||
/** | ||
* @return Map with event sources that wraps an informer. Thus, either a | ||
* {@link io.javaoperatorsdk.operator.processing.event.source.controller.ControllerResourceEventSource} | ||
* or an | ||
* {@link io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource}. | ||
*/ | ||
public Map<String, InformerWrappingEventSourceHealthIndicator> unhealthyInformerEventSourceHealthIndicators() { | ||
return eventSourceManager.allEventSources().entrySet().stream() | ||
.filter(e -> e.getValue().getStatus() == Status.UNHEALTHY) | ||
.filter(e -> e.getValue() instanceof InformerWrappingEventSourceHealthIndicator) | ||
.collect(Collectors.toMap(Map.Entry::getKey, | ||
e -> (InformerWrappingEventSourceHealthIndicator) e.getValue())); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...ork-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java
This file contains hidden or 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,6 @@ | ||
package io.javaoperatorsdk.operator.health; | ||
|
||
public interface EventSourceHealthIndicator { | ||
|
||
Status getStatus(); | ||
} |
17 changes: 17 additions & 0 deletions
17
...mework-core/src/main/java/io/javaoperatorsdk/operator/health/InformerHealthIndicator.java
This file contains hidden or 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.javaoperatorsdk.operator.health; | ||
|
||
public interface InformerHealthIndicator extends EventSourceHealthIndicator { | ||
|
||
boolean hasSynced(); | ||
|
||
boolean isWatching(); | ||
|
||
boolean isRunning(); | ||
|
||
@Override | ||
default Status getStatus() { | ||
return isRunning() && hasSynced() && isWatching() ? Status.HEALTHY : Status.UNHEALTHY; | ||
} | ||
|
||
String getTargetNamespace(); | ||
} |
22 changes: 22 additions & 0 deletions
22
...n/java/io/javaoperatorsdk/operator/health/InformerWrappingEventSourceHealthIndicator.java
This file contains hidden or 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,22 @@ | ||
package io.javaoperatorsdk.operator.health; | ||
|
||
import java.util.Map; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.javaoperatorsdk.operator.api.config.ResourceConfiguration; | ||
|
||
public interface InformerWrappingEventSourceHealthIndicator<R extends HasMetadata> | ||
extends EventSourceHealthIndicator { | ||
|
||
Map<String, InformerHealthIndicator> informerHealthIndicators(); | ||
|
||
@Override | ||
default Status getStatus() { | ||
var nonUp = informerHealthIndicators().values().stream() | ||
.filter(i -> i.getStatus() != Status.HEALTHY).findAny(); | ||
|
||
return nonUp.isPresent() ? Status.UNHEALTHY : Status.HEALTHY; | ||
} | ||
|
||
ResourceConfiguration<R> getInformerConfiguration(); | ||
} |
11 changes: 11 additions & 0 deletions
11
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java
This file contains hidden or 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,11 @@ | ||
package io.javaoperatorsdk.operator.health; | ||
|
||
public enum Status { | ||
|
||
HEALTHY, UNHEALTHY, | ||
/** | ||
* For event sources where it cannot be determined if it is healthy ot not. | ||
*/ | ||
UNKNOWN | ||
|
||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence doesn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformulated.