|
58 | 58 | end
|
59 | 59 |
|
60 | 60 |
|
61 |
| - it "sums values from different processes" do |
62 |
| - allow(Process).to receive(:pid).and_return(12345) |
63 |
| - metric_store1 = subject.for_metric(:metric_name, metric_type: :counter) |
64 |
| - metric_store1.set(labels: { foo: "bar" }, val: 1) |
65 |
| - metric_store1.set(labels: { foo: "baz" }, val: 7) |
66 |
| - metric_store1.set(labels: { foo: "yyy" }, val: 3) |
67 |
| - |
68 |
| - allow(Process).to receive(:pid).and_return(23456) |
69 |
| - metric_store2 = subject.for_metric(:metric_name, metric_type: :counter) |
70 |
| - metric_store2.set(labels: { foo: "bar" }, val: 3) |
71 |
| - metric_store2.set(labels: { foo: "baz" }, val: 2) |
72 |
| - metric_store2.set(labels: { foo: "zzz" }, val: 1) |
73 |
| - |
74 |
| - expect(metric_store2.all_values).to eq( |
75 |
| - { foo: "bar" } => 4.0, |
76 |
| - { foo: "baz" } => 9.0, |
77 |
| - { foo: "yyy" } => 3.0, |
78 |
| - { foo: "zzz" } => 1.0, |
79 |
| - ) |
80 |
| - |
81 |
| - # Both processes should return the same value |
82 |
| - expect(metric_store1.all_values).to eq(metric_store2.all_values) |
| 61 | + context "for a non-gauge metric" do |
| 62 | + it "sums values from different processes by default" do |
| 63 | + allow(Process).to receive(:pid).and_return(12345) |
| 64 | + metric_store1 = subject.for_metric(:metric_name, metric_type: :counter) |
| 65 | + metric_store1.set(labels: { foo: "bar" }, val: 1) |
| 66 | + metric_store1.set(labels: { foo: "baz" }, val: 7) |
| 67 | + metric_store1.set(labels: { foo: "yyy" }, val: 3) |
| 68 | + |
| 69 | + allow(Process).to receive(:pid).and_return(23456) |
| 70 | + metric_store2 = subject.for_metric(:metric_name, metric_type: :counter) |
| 71 | + metric_store2.set(labels: { foo: "bar" }, val: 3) |
| 72 | + metric_store2.set(labels: { foo: "baz" }, val: 2) |
| 73 | + metric_store2.set(labels: { foo: "zzz" }, val: 1) |
| 74 | + |
| 75 | + expect(metric_store2.all_values).to eq( |
| 76 | + { foo: "bar" } => 4.0, |
| 77 | + { foo: "baz" } => 9.0, |
| 78 | + { foo: "yyy" } => 3.0, |
| 79 | + { foo: "zzz" } => 1.0, |
| 80 | + ) |
| 81 | + |
| 82 | + # Both processes should return the same value |
| 83 | + expect(metric_store1.all_values).to eq(metric_store2.all_values) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + context "for a gauge metric" do |
| 88 | + it "exposes each process's individual value by default" do |
| 89 | + allow(Process).to receive(:pid).and_return(12345) |
| 90 | + metric_store1 = subject.for_metric( |
| 91 | + :metric_name, |
| 92 | + metric_type: :gauge, |
| 93 | + ) |
| 94 | + metric_store1.set(labels: { foo: "bar" }, val: 1) |
| 95 | + metric_store1.set(labels: { foo: "baz" }, val: 7) |
| 96 | + metric_store1.set(labels: { foo: "yyy" }, val: 3) |
| 97 | + |
| 98 | + allow(Process).to receive(:pid).and_return(23456) |
| 99 | + metric_store2 = subject.for_metric( |
| 100 | + :metric_name, |
| 101 | + metric_type: :gauge, |
| 102 | + ) |
| 103 | + metric_store2.set(labels: { foo: "bar" }, val: 3) |
| 104 | + metric_store2.set(labels: { foo: "baz" }, val: 2) |
| 105 | + metric_store2.set(labels: { foo: "zzz" }, val: 1) |
| 106 | + |
| 107 | + expect(metric_store1.all_values).to eq( |
| 108 | + { foo: "bar", pid: "12345" } => 1.0, |
| 109 | + { foo: "bar", pid: "23456" } => 3.0, |
| 110 | + { foo: "baz", pid: "12345" } => 7.0, |
| 111 | + { foo: "baz", pid: "23456" } => 2.0, |
| 112 | + { foo: "yyy", pid: "12345" } => 3.0, |
| 113 | + { foo: "zzz", pid: "23456" } => 1.0, |
| 114 | + ) |
| 115 | + |
| 116 | + # Both processes should return the same value |
| 117 | + expect(metric_store1.all_values).to eq(metric_store2.all_values) |
| 118 | + end |
83 | 119 | end
|
84 | 120 |
|
85 | 121 | context "with a metric that takes MAX instead of SUM" do
|
|
155 | 191 | allow(Process).to receive(:pid).and_return(12345)
|
156 | 192 | metric_store1 = subject.for_metric(
|
157 | 193 | :metric_name,
|
158 |
| - metric_type: :gauge, |
| 194 | + metric_type: :counter, |
159 | 195 | metric_settings: { aggregation: :all }
|
160 | 196 | )
|
161 | 197 | metric_store1.set(labels: { foo: "bar" }, val: 1)
|
|
165 | 201 | allow(Process).to receive(:pid).and_return(23456)
|
166 | 202 | metric_store2 = subject.for_metric(
|
167 | 203 | :metric_name,
|
168 |
| - metric_type: :gauge, |
| 204 | + metric_type: :counter, |
169 | 205 | metric_settings: { aggregation: :all }
|
170 | 206 | )
|
171 | 207 | metric_store2.set(labels: { foo: "bar" }, val: 3)
|
|
0 commit comments