Class: OpenObserve::Streams

Inherits:
Resource show all
Defined in:
lib/openobserve/streams.rb

Overview

Streams — the containers logs, metrics and traces land in.

Read-only by design here: creating, deleting or re-configuring a stream is an administration act, outside this gem's working set (search and alerting).

Reads go through Resource#raw rather than Api::Api::Streams, which pins type: Api::Models::StreamList200Response on its listing — see Resource#raw for why a declared response type is unusable here.

Constant Summary

Constants inherited from Resource

Resource::AUTH

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from OpenObserve::Resource

Instance Method Details

#list(type: nil, keyword: nil, limit: nil, offset: nil, sort: nil) ⇒ Array<OpenObserve::Stream>

Parameters:

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

    restrict to a stream type ("logs", "metrics", "traces")

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/openobserve/streams.rb', line 15

def list(type: nil, keyword: nil, limit: nil, offset: nil, sort: nil)
  envelope = collection do
    raw(:GET, "/api/#{encode(organization)}/streams",
        query: { 'type' => type, 'keyword' => keyword, 'limit' => limit,
                 'offset' => offset, 'sort' => sort, })
  end

  Array(envelope && envelope['list']).map { |stream| Stream.from(stream) }
end

#namesArray<String>

Returns stream names only.

Returns:

  • (Array<String>)

    stream names only



26
27
28
# File 'lib/openobserve/streams.rb', line 26

def names(...)
  list(...).map { |stream| stream['name'] }
end

#schema(name, type: nil) ⇒ OpenObserve::Stream

Returns the stream and its field list.

Parameters:

  • name (String)

    stream name

Returns:

Raises:



33
34
35
36
37
38
39
40
# File 'lib/openobserve/streams.rb', line 33

def schema(name, type: nil)
  payload = one('stream') do
    raw(:GET, "/api/#{encode(organization)}/streams/#{encode(name)}/schema",
        query: { 'type' => type })
  end

  Stream.from(payload)
end