Class: OpenObserve::Client

Inherits:
Object
  • Object
show all
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.

Examples:

oo = OpenObserve::Client.new                          # from ENV
oo = OpenObserve::Client.new(                         # explicit
  base_url:     "https://oo.example.org",
  user:         "root@example.com",
  password:     "xxxxxxxx",
  organization: "acme",
)

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

Instance Method Summary collapse

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.

Parameters:

  • base_url (String) (defaults to: ENV.fetch(ENV_BASE_URL, nil))

    base URL; defaults to ENV

  • user (String) (defaults to: ENV.fetch(ENV_USER, nil))

    account e-mail; defaults to ENV

  • password (String) (defaults to: ENV.fetch(ENV_PASSWORD, nil))

    account password; defaults to ENV

  • organization (String) (defaults to: ENV.fetch(ENV_ORG, nil))

    organization; defaults to ENV or "default"

  • folder (String, nil) (defaults to: nil)

    default alert folder; nil leaves the choice to the server

  • ssl (Hash) (defaults to: {})

    TLS options handed to Faraday, e.g. { ca_file: "/path/root.crt" }

Raises:



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_urlString (readonly)

Returns the OpenObserve base URL.

Returns:

  • (String)

    the OpenObserve base URL



34
35
36
# File 'lib/openobserve/client.rb', line 34

def base_url
  @base_url
end

#folderString? (readonly)

Returns the alert folder domains default to; nil lets the server choose.

Returns:

  • (String, nil)

    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

#organizationString (readonly)

Returns the organization every request is scoped to.

Returns:

  • (String)

    the organization every request is scoped to



36
37
38
# File 'lib/openobserve/client.rb', line 36

def organization
  @organization
end

Instance Method Details

#alertsOpenObserve::Alerts

Returns alert definitions (served by the v2 API).

Returns:



110
111
112
# File 'lib/openobserve/client.rb', line 110

def alerts
  @alerts ||= Alerts.new(self)
end

#connectionOpenObserve::Api::Connection

The raw transport connection — the single HTTP choke-point domains call through.

Returns:

  • (OpenObserve::Api::Connection)


95
96
97
# File 'lib/openobserve/client.rb', line 95

def connection
  transport.connection
end

#credentialString

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.

Returns:

  • (String)


77
78
79
# File 'lib/openobserve/client.rb', line 77

def credential
  @credential ||= "Basic #{["#{@user}:#{@password}"].pack('m0')}"
end

#dashboardsOpenObserve::Dashboards

Returns dashboards, and their directory synchronisation.

Returns:



130
131
132
# File 'lib/openobserve/client.rb', line 130

def dashboards
  @dashboards ||= Dashboards.new(self)
end

#destinationsOpenObserve::Destinations

Returns alert destinations (served by the v1 API).

Returns:



115
116
117
# File 'lib/openobserve/client.rb', line 115

def destinations
  @destinations ||= Destinations.new(self)
end

#incidentsOpenObserve::Incidents

Returns alert incidents (served by the v2 API).

Returns:



125
126
127
# File 'lib/openobserve/client.rb', line 125

def incidents
  @incidents ||= Incidents.new(self)
end

#searchOpenObserve::Search

Returns log search and exploration.

Returns:



100
101
102
# File 'lib/openobserve/client.rb', line 100

def search
  @search ||= Search.new(self)
end

#sourcemapsOpenObserve::Sourcemaps

Returns JavaScript source maps for RUM symbolication.

Returns:



135
136
137
# File 'lib/openobserve/client.rb', line 135

def sourcemaps
  @sourcemaps ||= Sourcemaps.new(self)
end

#streamsOpenObserve::Streams

Returns streams listing and schema (read-only).

Returns:



105
106
107
# File 'lib/openobserve/client.rb', line 105

def streams
  @streams ||= Streams.new(self)
end

#templatesOpenObserve::Templates

Returns alert templates (served by the v1 API).

Returns:



120
121
122
# File 'lib/openobserve/client.rb', line 120

def templates
  @templates ||= Templates.new(self)
end

#transportOpenObserve::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.

Returns:

  • (OpenObserve::Api::Client)


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