Class CollectorHealthClient

java.lang.Object
codes.grow.packages.otelcollector.CollectorHealthClient
All Implemented Interfaces:
AutoCloseable

public final class CollectorHealthClient extends Object implements AutoCloseable
Health of an OpenTelemetry Collector: GET {healthUrl} (health_check extension, port 13133) and, when that endpoint is unreachable (stock Grow stacks bind it to localhost), GET {zpagesUrl}/debug/servicez (port 55679). Also reads the collector version.

Admin endpoints are unauthenticated: the configured export headers are never sent to them. Thread-safe; close it when done (a health client obtained from OtelCollectorClient.collectorHealth() is closed with the client).

  • Field Details

  • Method Details

    • create

      public static CollectorHealthClient create(OtelCollectorConfig config)
      Creates a health client.
      Parameters:
      config - validated configuration
      Returns:
      a new client
    • fromEnv

      public static CollectorHealthClient fromEnv()
      Creates a health client from the environment (see OtelCollectorConfig.fromEnv()).
      Returns:
      a new client
    • config

      public OtelCollectorConfig config()
      Returns the configuration.
      Returns:
      the configuration
    • parseServicezVersion

      public static Optional<String> parseServicezVersion(String html)
      Parses the collector version from the zpages /debug/servicez HTML.
      Parameters:
      html - page
      Returns:
      the version, or empty
    • parseTargetInfoVersion

      public static Optional<String> parseTargetInfoVersion(String metrics)
      Parses service_version of the Prometheus target_info series.
      Parameters:
      metrics - exposition text
      Returns:
      the version, or empty
    • health

      public HealthStatus health()
      Collector health. 200 {"status":"Server available",…} → healthy=true, status="ok" with details source=health_check, vendorStatus, upSince, uptime; another status (503 while starting or stopping) → unhealthy; unreachable → zpages fallback (details.source=zpages), else unreachable. Never throws for an unhealthy or unreachable collector.
      Returns:
      the status
      Throws:
      CancelledException - when interrupted or closed
    • healthAsync

      public CompletableFuture<HealthStatus> healthAsync()
      Asynchronous health().
      Returns:
      a future with the status (failed only for cancellation and configuration errors)
    • waitUntilReady

      public HealthStatus waitUntilReady()
      Polls health() until the collector is healthy, for at most DEFAULT_READY_TIMEOUT.
      Returns:
      the healthy status
      Throws:
      TimeoutException - at the deadline
      CancelledException - when interrupted
    • waitUntilReady

      public HealthStatus waitUntilReady(Duration timeout)
      Polls health() until the collector is healthy.
      Parameters:
      timeout - deadline
      Returns:
      the healthy status
      Throws:
      TimeoutException - at the deadline
      CancelledException - when interrupted
    • waitUntilReadyAsync

      public CompletableFuture<HealthStatus> waitUntilReadyAsync(Duration timeout)
      Asynchronous waitUntilReady(Duration): no thread blocks between probes.
      Parameters:
      timeout - deadline
      Returns:
      a future with the healthy status, failed with TimeoutException
    • serverVersion

      public String serverVersion()
      Collector version: the zpages /debug/servicez "Version" row (works on stock stacks), else service_version of target_info at OtelCollectorConfig.telemetryUrl().
      Returns:
      the version, such as 0.165.0
      Throws:
      UnsupportedException - when neither source answers with a version
    • serverVersionAsync

      public CompletableFuture<String> serverVersionAsync()
      Asynchronous serverVersion().
      Returns:
      a future with the version
    • close

      public void close()
      Releases connections. Idempotent.
      Specified by:
      close in interface AutoCloseable