Class: OpenObserve::Client
- Inherits:
-
Object
- Object
- OpenObserve::Client
- Defined in:
- lib/openobserve/client.rb,
lib/openobserve/client/error.rb,
lib/openobserve/client/conflict.rb,
lib/openobserve/client/forbidden.rb,
lib/openobserve/client/not_found.rb,
lib/openobserve/client/unauthorized.rb
Overview
The business-facing OpenObserve client. One instance targets one OpenObserve instance and one organization; there is no global singleton, so several may coexist.
Configuration is read from the environment by default — OPENOBSERVE_BASE_URL,
OPENOBSERVE_USER, OPENOBSERVE_PASSWORD, OPENOBSERVE_ORG — and may be overridden
per instance.
Defined Under Namespace
Classes: Conflict, Error, Forbidden, NotFound, Unauthorized
Constant Summary collapse
- ENV_BASE_URL =
Environment variable holding the OpenObserve base URL (e.g.
https://oo.example.org). 'OPENOBSERVE_BASE_URL'- ENV_USER =
Environment variable holding the account e-mail.
'OPENOBSERVE_USER'- ENV_PASSWORD =
Environment variable holding the account password.
'OPENOBSERVE_PASSWORD'- ENV_ORG =
Environment variable holding the organization; optional, defaults to DEFAULT_ORG.
'OPENOBSERVE_ORG'- DEFAULT_ORG =
OpenObserve creates this organization on first boot; it is the one a single-tenant install ever uses.
'default'
Instance Attribute Summary collapse
-
#base_url ⇒ String
readonly
The OpenObserve base URL.
-
#folder ⇒ String?
readonly
The alert folder domains default to; nil lets the server choose.
-
#organization ⇒ String
readonly
The organization every request is scoped to.
Instance Method Summary collapse
-
#alerts ⇒ OpenObserve::Alerts
Alert definitions (served by the v2 API).
-
#connection ⇒ OpenObserve::Api::Connection
The raw transport connection — the single HTTP choke-point domains call through.
-
#credential ⇒ String
The
Authorizationheader value every request carries. -
#dashboards ⇒ OpenObserve::Dashboards
Dashboards, and their directory synchronisation.
-
#destinations ⇒ OpenObserve::Destinations
Alert destinations (served by the v1 API).
-
#incidents ⇒ OpenObserve::Incidents
Alert incidents (served by the v2 API).
-
#initialize(base_url: ENV.fetch(ENV_BASE_URL, nil), user: ENV.fetch(ENV_USER, nil), password: ENV.fetch(ENV_PASSWORD, nil), organization: ENV.fetch(ENV_ORG, nil), folder: nil, ssl: {}) ⇒ Client
constructor
A new instance of Client.
-
#search ⇒ OpenObserve::Search
Log search and exploration.
-
#sourcemaps ⇒ OpenObserve::Sourcemaps
JavaScript source maps for RUM symbolication.
-
#streams ⇒ OpenObserve::Streams
Streams listing and schema (read-only).
-
#templates ⇒ OpenObserve::Templates
Alert templates (served by the v1 API).
-
#transport ⇒ OpenObserve::Api::Client
The underlying openobserve-api transport client.
Constructor Details
#initialize(base_url: ENV.fetch(ENV_BASE_URL, nil), user: ENV.fetch(ENV_USER, nil), password: ENV.fetch(ENV_PASSWORD, nil), organization: ENV.fetch(ENV_ORG, nil), folder: nil, ssl: {}) ⇒ Client
Returns a new instance of Client.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/openobserve/client.rb', line 47 def initialize( base_url: ENV.fetch(ENV_BASE_URL, nil), user: ENV.fetch(ENV_USER, nil), password: ENV.fetch(ENV_PASSWORD, nil), organization: ENV.fetch(ENV_ORG, nil), folder: nil, ssl: {} ) @base_url = require_config!(base_url, ENV_BASE_URL) @user = require_config!(user, ENV_USER) @password = require_config!(password, ENV_PASSWORD) @organization = normalize_organization(organization) @folder = folder @ssl = ssl || {} reset_domains! end |
Instance Attribute Details
#base_url ⇒ String (readonly)
Returns the OpenObserve base URL.
34 35 36 |
# File 'lib/openobserve/client.rb', line 34 def base_url @base_url end |
#folder ⇒ String? (readonly)
Returns the alert folder domains default to; nil lets the server choose.
38 39 40 |
# File 'lib/openobserve/client.rb', line 38 def folder @folder end |
#organization ⇒ String (readonly)
Returns the organization every request is scoped to.
36 37 38 |
# File 'lib/openobserve/client.rb', line 36 def organization @organization end |
Instance Method Details
#alerts ⇒ OpenObserve::Alerts
Returns alert definitions (served by the v2 API).
110 111 112 |
# File 'lib/openobserve/client.rb', line 110 def alerts @alerts ||= Alerts.new(self) end |
#connection ⇒ OpenObserve::Api::Connection
The raw transport connection — the single HTTP choke-point domains call through.
95 96 97 |
# File 'lib/openobserve/client.rb', line 95 def connection transport.connection end |
#credential ⇒ String
The Authorization header value every request carries.
OpenObserve expects HTTP Basic, but its OpenAPI document declares BasicAuth without
a single operation referencing it: all 210 authenticated operations declare the
free-form Authorization apiKey scheme instead. The transport therefore never applies
its own username/password, so the wrapper builds the header value itself.
pack("m0") is strict Base64 from core Ruby — no base64 stdlib dependency, which
stopped being a default gem in Ruby 3.4. Strict means no line breaks, which a long
user/password pair would otherwise get.
77 78 79 |
# File 'lib/openobserve/client.rb', line 77 def credential @credential ||= "Basic #{["#{@user}:#{@password}"].pack('m0')}" end |
#dashboards ⇒ OpenObserve::Dashboards
Returns dashboards, and their directory synchronisation.
130 131 132 |
# File 'lib/openobserve/client.rb', line 130 def dashboards @dashboards ||= Dashboards.new(self) end |
#destinations ⇒ OpenObserve::Destinations
Returns alert destinations (served by the v1 API).
115 116 117 |
# File 'lib/openobserve/client.rb', line 115 def destinations @destinations ||= Destinations.new(self) end |
#incidents ⇒ OpenObserve::Incidents
Returns alert incidents (served by the v2 API).
125 126 127 |
# File 'lib/openobserve/client.rb', line 125 def incidents @incidents ||= Incidents.new(self) end |
#search ⇒ OpenObserve::Search
Returns log search and exploration.
100 101 102 |
# File 'lib/openobserve/client.rb', line 100 def search @search ||= Search.new(self) end |
#sourcemaps ⇒ OpenObserve::Sourcemaps
Returns JavaScript source maps for RUM symbolication.
135 136 137 |
# File 'lib/openobserve/client.rb', line 135 def sourcemaps @sourcemaps ||= Sourcemaps.new(self) end |
#streams ⇒ OpenObserve::Streams
Returns streams listing and schema (read-only).
105 106 107 |
# File 'lib/openobserve/client.rb', line 105 def streams @streams ||= Streams.new(self) end |
#templates ⇒ OpenObserve::Templates
Returns alert templates (served by the v1 API).
120 121 122 |
# File 'lib/openobserve/client.rb', line 120 def templates @templates ||= Templates.new(self) end |
#transport ⇒ OpenObserve::Api::Client
The underlying openobserve-api transport client. Lazily built and memoised, one per instance (no global state).
ssl is forwarded because TLS is settled when Faraday builds the connection: an
OpenObserve behind a private CA — a container stack fronted by step-ca, say — is
unreachable without it, the default trust store holding public authorities only.
88 89 90 |
# File 'lib/openobserve/client.rb', line 88 def transport @transport ||= OpenObserve::Api::Client.new(base_url: base_url, api_key: credential, ssl: @ssl) end |