Class: OpenObserve::Dashboard

Inherits:
Record
  • Object
show all
Defined in:
lib/openobserve/dashboard.rb

Overview

A dashboard, in either of the two shapes OpenObserve answers with.

GET/POST/PUT on a single dashboard return a version envelopehash, updatedAt, version and eight v1v8 slots of which exactly one is filled. The list endpoint returns a flatter item: the same version/v{n} pair, plus dashboard_id, title, hash and the folder at the top level.

The two are reconciled here so callers never branch on which endpoint produced the record: #id and #title read the top level first and fall back to the definition, and #definition always yields the dashboard body itself.

Note the name of #revision. The API field is called hash, but Record#hash implements Ruby's Object#hash contract so records key Hashes and Sets correctly; shadowing it with a String would break every such use, silently. The raw field stays reachable as dashboard['hash'].

Instance Attribute Summary

Attributes inherited from Record

#raw

Instance Method Summary collapse

Methods inherited from Record

#==, #[], from, #hash, #initialize, #to_h

Constructor Details

This class inherits a constructor from OpenObserve::Record

Instance Method Details

#definitionHash

The dashboard body, unwrapped from the v{version} slot it travels in.

Returns:

  • (Hash)

    the definition, or an empty Hash when no slot is filled



27
28
29
# File 'lib/openobserve/dashboard.rb', line 27

def definition
  version.nil? ? {} : (self["v#{version}"] || {})
end

#folder_idString?

Returns the folder the dashboard lives in; only list items carry it.

Returns:

  • (String, nil)

    the folder the dashboard lives in; only list items carry it



42
43
44
# File 'lib/openobserve/dashboard.rb', line 42

def folder_id
  self['folder_id']
end

#idString?

Returns the server-assigned dashboard id.

Returns:

  • (String, nil)

    the server-assigned dashboard id



32
33
34
# File 'lib/openobserve/dashboard.rb', line 32

def id
  self['dashboard_id'] || definition['dashboardId']
end

#revisionString?

The server's content hash, which OpenObserve::Dashboards#update must echo back for OpenObserve to accept the write. Named revision rather than hash — see the class note.

Returns:

  • (String, nil)


50
51
52
# File 'lib/openobserve/dashboard.rb', line 50

def revision
  self['hash']
end

#titleString?

Returns the dashboard title, which OpenObserve::Dashboards#sync keys on.

Returns:



37
38
39
# File 'lib/openobserve/dashboard.rb', line 37

def title
  self['title'] || definition['title']
end

#versionInteger?

Returns the dashboard schema version (5 for the current format).

Returns:

  • (Integer, nil)

    the dashboard schema version (5 for the current format)



21
22
23
# File 'lib/openobserve/dashboard.rb', line 21

def version
  self['version']
end