File: summary_spec.rb

package info (click to toggle)
ruby-prometheus-client-mmap 1.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: ruby: 3,149; sh: 54; makefile: 21
file content (56 lines) | stat: -rw-r--r-- 1,461 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# encoding: UTF-8

require 'prometheus/client/summary'
require 'examples/metric_example'

describe Prometheus::Client::Summary do
  let(:summary) { Prometheus::Client::Summary.new(:bar, 'bar description') }

  it_behaves_like Prometheus::Client::Metric do
    let(:type) { Float }
  end

  describe '#observe' do
    it 'records the given value' do
      expect do
        summary.observe({}, 5)
      end.to change { summary.get }
    end
  end

  xdescribe '#get' do
    before do
      summary.observe({ foo: 'bar' }, 3)
      summary.observe({ foo: 'bar' }, 5.2)
      summary.observe({ foo: 'bar' }, 13)
      summary.observe({ foo: 'bar' }, 4)
    end

    it 'returns a set of quantile values' do
      expect(summary.get(foo: 'bar')).to eql(0.5 => 4, 0.9 => 5.2, 0.99 => 5.2)
    end

    it 'returns a value which responds to #sum and #total' do
      value = summary.get(foo: 'bar')

      expect(value.sum).to eql(25.2)
      expect(value.total).to eql(4)
    end

    it 'uses nil as default value' do
      expect(summary.get({})).to eql(0.5 => nil, 0.9 => nil, 0.99 => nil)
    end
  end

  xdescribe '#values' do
    it 'returns a hash of all recorded summaries' do
      summary.observe({ status: 'bar' }, 3)
      summary.observe({ status: 'foo' }, 5)

      expect(summary.values).to eql(
        { status: 'bar' } => { 0.5 => 3, 0.9 => 3, 0.99 => 3 },
        { status: 'foo' } => { 0.5 => 5, 0.9 => 5, 0.99 => 5 },
      )
    end
  end
end