Class LLMHealthIndicator
java.lang.Object
com.tnsai.quality.observability.health.LLMHealthIndicator
- All Implemented Interfaces:
HealthIndicator
Health indicator for LLM providers.
Checks LLM client health by:
- Verifying client configuration
- Optionally making a test call (ping)
- Checking recent call success rate
- Monitoring response latency
Example usage:
LLMClient client = new OpenAIClient();
// Basic health indicator (no ping)
HealthRegistry.getInstance()
.register(new LLMHealthIndicator(client, "openai"));
// With ping check (makes actual API call)
HealthRegistry.getInstance()
.register(new LLMHealthIndicator(client, "openai", true));
Note: Enabling ping checks will make actual API calls, which may incur costs and add latency to health checks.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for LLMHealthIndicator. -
Field Summary
Fields inherited from interface com.tnsai.quality.observability.health.HealthIndicator
DEFAULT_TIMEOUT -
Constructor Summary
ConstructorsConstructorDescriptionLLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName) Creates an LLM health indicator without ping.LLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName, boolean enablePing) Creates an LLM health indicator.LLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName, boolean enablePing, double maxLatencyMs, double minSuccessRate) Creates an LLM health indicator with custom thresholds. -
Method Summary
Modifier and TypeMethodDescriptionstatic LLMHealthIndicator.Builderbuilder()check()Performs the health check and returns the result.getName()Gets the name of this health indicator.Gets the timeout for this health check.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.quality.observability.health.HealthIndicator
checkAsync, checkWithTimeout
-
Constructor Details
-
LLMHealthIndicator
Creates an LLM health indicator without ping.- Parameters:
client- the LLM clientproviderName- the provider name (e.g., "openai", "anthropic")
-
LLMHealthIndicator
Creates an LLM health indicator.- Parameters:
client- the LLM clientproviderName- the provider nameenablePing- whether to make test API calls
-
LLMHealthIndicator
public LLMHealthIndicator(com.tnsai.llm.LLMClient client, String providerName, boolean enablePing, double maxLatencyMs, double minSuccessRate) Creates an LLM health indicator with custom thresholds.- Parameters:
client- the LLM clientproviderName- the provider nameenablePing- whether to make test API callsmaxLatencyMs- maximum acceptable latency in millisecondsminSuccessRate- minimum success rate (0.0-1.0)
-
-
Method Details
-
getName
Description copied from interface:HealthIndicatorGets the name of this health indicator.Default implementation returns the simple class name.
- Specified by:
getNamein interfaceHealthIndicator- Returns:
- the indicator name
-
check
Description copied from interface:HealthIndicatorPerforms the health check and returns the result.Implementations should:
- Return quickly (under 10 seconds)
- Not throw exceptions (return DOWN status instead)
- Include relevant details in the result
- Specified by:
checkin interfaceHealthIndicator- Returns:
- the health check result
-
getTimeout
Description copied from interface:HealthIndicatorGets the timeout for this health check.- Specified by:
getTimeoutin interfaceHealthIndicator- Returns:
- the timeout duration
-
builder
-