@grow-codes/grafana-loki - v0.1.1
    Preparing search index...

    Class LokiClient

    Client for Grafana Loki: push (JSON, protobuf + Snappy, OTLP), LogQL queries, labels, series, index stats and volume, WebSocket tail, status, multi-tenancy and the logging category (logClient(), logQueryClient()).

    Index
    config: LokiConfig

    The immutable configuration.

    • get tenantId(): string | undefined

      The tenant this client sends as X-Scope-OrgID, if any.

      Returns string | undefined

    • Flushes and closes log clients created by logClient, stops open tails and releases connections (children from withTenant leave the shared connections open). Idempotent.

      Returns Promise<void>

    • Normalizes a LogQL query on the server (GET /loki/api/v1/format_query).

      Parameters

      Returns Promise<string>

    • Readiness: GET /ready. 200 ready → healthy ok; 503 → unhealthy with Loki's text (e.g. Ingester not ready: waiting for 15s after being ready); network errors → unreachable. Never throws except for CANCELLED and CONFIG.

      Parameters

      Returns Promise<HealthStatus>

    • Values of one label: GET /loki/api/v1/label/{name}/values. The name is validated client side (Loki answers unknown and invalid names with an empty result).

      Parameters

      Returns Promise<string[]>

    • Authenticated round trip: GET /loki/api/v1/labels?since=5m with auth and tenant headers. Returns the latency in milliseconds; AuthenticationError without a tenant (multi-tenant Loki) or with wrong gateway credentials.

      Parameters

      Returns Promise<number>

    • Pushes streams with POST /loki/api/v1/push. JSON by default (optionally gzip); format: "protobuf" sends a Snappy-compressed PushRequest. The cardinality guard moves labels outside config.allowedLabels to every entry's structured metadata (unless config.disableLabelGuard), then labels are validated client side. Entries without a timestamp get "now". Retrying is safe: Loki drops entries identical to stored ones (same labels, timestamp and line), so the push is marked idempotent and retried on 5xx and network errors. Status 260 (ingestion blocked by the operator) throws a non-retryable error.

      Parameters

      Returns Promise<void>

    • Pushes records as OTLP/JSON to POST /otlp/v1/logs (Loki's OTLP endpoint). Loki promotes its default resource attributes (service.name, deployment.environment, …) to labels and stores everything else as structured metadata.

      Parameters

      Returns Promise<void>

    • Series matching any of the selectors: GET /loki/api/v1/series (at least one matcher).

      Parameters

      • matchers: string | readonly string[]
      • options: SeriesOptions = {}

      Returns Promise<Record<string, string>[]>

    • Server version (buildInfo().version, e.g. "3.7.10").

      Parameters

      Returns Promise<string>

    • Live tail over WebSocket (/loki/api/v1/tail). Resolves once connected; handshake errors reject (AuthenticationError, ValidationError, …). onEntries receives the streams of every frame; dropped entries go to onDropped, later errors to onError. Only log queries (starting with {) are allowed. Stop with handle.stop() or close(). Proxies are not used for the WebSocket.

      Parameters

      Returns Promise<LokiTail>

    • A client for another tenant: shares this client's connections, sends X-Scope-OrgID: id on every request and on the tail handshake. This client is unchanged. Closing the child does not close the shared connections. Throws ValidationError for an invalid id.

      Parameters

      • id: string

      Returns LokiClient