Class: Nonnative::Observability

Inherits:
HTTPClient
  • Object
show all
Defined in:
lib/nonnative/observability.rb

Overview

HTTP client for common observability endpoints exposed by the system under test.

This client is returned by observability and builds endpoint paths from Configuration#name.

Endpoints:

  • /<name>/healthz
  • /<name>/livez
  • /<name>/readyz
  • /<name>/metrics

Requests are performed using HTTPClient, so callers may pass RestClient options such as headers, open_timeout, and read_timeout. HTTP error statuses are returned as response objects; broken connections raise their RestClient exceptions, and a timeout raises either a RestClient timeout exception or Timeout::Error (the latter when read_timeout bounds a Net::HTTP retry of an idempotent verb). Requests are not retried automatically.

Examples:

Nonnative.configure do |config|
  config.name = 'my-service'
  config.url = 'http://127.0.0.1:8080'
end

response = Nonnative.observability.health(read_timeout: 2, open_timeout: 2)
response.code # => 200

See Also:

Instance Method Summary collapse

Instance Method Details

#health(opts = {}) ⇒ RestClient::Response, String

Calls /<name>/healthz.

Parameters:

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

    RestClient options (e.g. headers, read_timeout, open_timeout)

Returns:

  • (RestClient::Response, String)

    response for non-2xx errors, otherwise the RestClient result



37
38
39
# File 'lib/nonnative/observability.rb', line 37

def health(opts = {})
  get("#{name}/healthz", opts)
end

#liveness(opts = {}) ⇒ RestClient::Response, String

Calls /<name>/livez.

Parameters:

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

    RestClient options (e.g. headers, read_timeout, open_timeout)

Returns:

  • (RestClient::Response, String)

    response for non-2xx errors, otherwise the RestClient result



45
46
47
# File 'lib/nonnative/observability.rb', line 45

def liveness(opts = {})
  get("#{name}/livez", opts)
end

#metrics(opts = {}) ⇒ RestClient::Response, String

Calls /<name>/metrics.

Parameters:

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

    RestClient options (e.g. headers, read_timeout, open_timeout)

Returns:

  • (RestClient::Response, String)

    response for non-2xx errors, otherwise the RestClient result



61
62
63
# File 'lib/nonnative/observability.rb', line 61

def metrics(opts = {})
  get("#{name}/metrics", opts)
end

#readiness(opts = {}) ⇒ RestClient::Response, String

Calls /<name>/readyz.

Parameters:

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

    RestClient options (e.g. headers, read_timeout, open_timeout)

Returns:

  • (RestClient::Response, String)

    response for non-2xx errors, otherwise the RestClient result



53
54
55
# File 'lib/nonnative/observability.rb', line 53

def readiness(opts = {})
  get("#{name}/readyz", opts)
end