|
15 | 15 | let(:span) { exporter.finished_spans.first } |
16 | 16 | let(:host) { ENV.fetch('TEST_MEMCACHED_HOST', '127.0.0.1') } |
17 | 17 | let(:port) { ENV.fetch('TEST_MEMCACHED_PORT', 11_211).to_i } |
18 | | - let(:dalli) { Dalli::Client.new("#{host}:#{port}", {}) } |
19 | 18 |
|
20 | 19 | before do |
21 | 20 | exporter.reset |
|
26 | 25 | instrumentation.instance_variable_set(:@installed, false) |
27 | 26 | end |
28 | 27 |
|
29 | | - describe 'tracing' do |
30 | | - before do |
31 | | - instrumentation.install(db_statement: :include) |
32 | | - end |
33 | | - |
34 | | - it 'accepts peer service name from config' do |
35 | | - instrumentation.instance_variable_set(:@installed, false) |
36 | | - instrumentation.install(peer_service: 'readonly:memcached') |
37 | | - dalli.set('foo', 'bar') |
38 | | - |
39 | | - _(span.attributes['peer.service']).must_equal 'readonly:memcached' |
40 | | - end |
| 28 | + [ |
| 29 | + ['binary protocol', { protocol: :binary }], |
| 30 | + ['meta protocol', { protocol: :meta }] |
| 31 | + ].each do |name, protocol| |
| 32 | + describe "tracing with #{name}" do |
| 33 | + let(:dalli) { Dalli::Client.new("#{host}:#{port}", protocol) } |
41 | 34 |
|
42 | | - it 'before request' do |
43 | | - _(exporter.finished_spans.size).must_equal 0 |
44 | | - end |
| 35 | + before do |
| 36 | + instrumentation.install(db_statement: :include) |
| 37 | + end |
45 | 38 |
|
46 | | - it 'after dalli#set' do |
47 | | - dalli.set('foo', 'bar') |
| 39 | + it 'accepts peer service name from config' do |
| 40 | + instrumentation.instance_variable_set(:@installed, false) |
| 41 | + instrumentation.install(peer_service: 'readonly:memcached') |
| 42 | + dalli.set('foo', 'bar') |
48 | 43 |
|
49 | | - _(exporter.finished_spans.size).must_equal 1 |
50 | | - _(span.name).must_equal 'set' |
51 | | - _(span.attributes['db.system']).must_equal 'memcached' |
52 | | - _(span.attributes['db.statement']).must_equal 'set foo bar 0 0' |
53 | | - _(span.attributes['db.operation']).must_equal 'set' |
54 | | - _(span.attributes['net.peer.name']).must_equal host |
55 | | - _(span.attributes['net.peer.port']).must_equal port |
56 | | - end |
| 44 | + _(span.attributes['peer.service']).must_equal 'readonly:memcached' |
| 45 | + end |
57 | 46 |
|
58 | | - it 'after dalli#set' do |
59 | | - dalli.get('foo') |
| 47 | + it 'before request' do |
| 48 | + _(exporter.finished_spans.size).must_equal 0 |
| 49 | + end |
60 | 50 |
|
61 | | - _(exporter.finished_spans.size).must_equal 1 |
62 | | - _(span.name).must_equal 'get' |
63 | | - _(span.attributes['db.system']).must_equal 'memcached' |
64 | | - _(span.attributes['db.statement']).must_equal 'get foo' |
65 | | - _(span.attributes['db.operation']).must_equal 'get' |
66 | | - _(span.attributes['net.peer.name']).must_equal host |
67 | | - _(span.attributes['net.peer.port']).must_equal port |
68 | | - end |
| 51 | + it 'after dalli#set' do |
| 52 | + dalli.set('foo', 'bar') |
69 | 53 |
|
70 | | - it 'after dalli#get_multi' do |
71 | | - dalli.get_multi('foo', 'bar') |
| 54 | + _(exporter.finished_spans.size).must_equal 1 |
| 55 | + _(span.name).must_equal 'set' |
| 56 | + _(span.attributes['db.system']).must_equal 'memcached' |
| 57 | + _(span.attributes['db.statement']).must_equal 'set foo bar 0 0' |
| 58 | + _(span.attributes['db.operation']).must_equal 'set' |
| 59 | + _(span.attributes['net.peer.name']).must_equal host |
| 60 | + _(span.attributes['net.peer.port']).must_equal port |
| 61 | + end |
72 | 62 |
|
73 | | - _(exporter.finished_spans.size).must_equal 1 |
74 | | - _(span.name).must_equal 'getkq' |
75 | | - _(span.attributes['db.system']).must_equal 'memcached' |
76 | | - _(span.attributes['db.statement']).must_equal 'getkq foo bar' |
77 | | - _(span.attributes['db.operation']).must_equal 'getkq' |
78 | | - _(span.attributes['net.peer.name']).must_equal host |
79 | | - _(span.attributes['net.peer.port']).must_equal port |
80 | | - end |
| 63 | + it 'after dalli#get' do |
| 64 | + dalli.get('foo') |
81 | 65 |
|
82 | | - it 'after error' do |
83 | | - dalli.set('foo', 'bar') |
84 | | - exporter.reset |
| 66 | + _(exporter.finished_spans.size).must_equal 1 |
| 67 | + _(span.name).must_equal 'get' |
| 68 | + _(span.attributes['db.system']).must_equal 'memcached' |
| 69 | + _(span.attributes['db.statement']).must_equal 'get foo' |
| 70 | + _(span.attributes['db.operation']).must_equal 'get' |
| 71 | + _(span.attributes['net.peer.name']).must_equal host |
| 72 | + _(span.attributes['net.peer.port']).must_equal port |
| 73 | + end |
85 | 74 |
|
86 | | - dalli.instance_variable_get(:@ring).servers.first.stub(:write, ->(_bytes) { raise Dalli::NetworkError }) do |
| 75 | + it 'after dalli#get_multi' do |
87 | 76 | dalli.get_multi('foo', 'bar') |
88 | | - end |
89 | 77 |
|
90 | | - if supports_retry_on_network_errors? |
91 | | - _(exporter.finished_spans.size).must_equal 2 |
92 | | - else |
93 | 78 | _(exporter.finished_spans.size).must_equal 1 |
| 79 | + _(span.name).must_equal 'getkq' |
| 80 | + _(span.attributes['db.system']).must_equal 'memcached' |
| 81 | + _(span.attributes['db.statement']).must_equal 'getkq foo bar' |
| 82 | + _(span.attributes['db.operation']).must_equal 'getkq' |
| 83 | + _(span.attributes['net.peer.name']).must_equal host |
| 84 | + _(span.attributes['net.peer.port']).must_equal port |
94 | 85 | end |
95 | 86 |
|
96 | | - _(span.name).must_equal 'getkq' |
97 | | - _(span.attributes['db.system']).must_equal 'memcached' |
98 | | - _(span.attributes['db.statement']).must_equal 'getkq foo bar' |
99 | | - _(span.attributes['db.operation']).must_equal 'getkq' |
100 | | - _(span.attributes['net.peer.name']).must_equal host |
101 | | - _(span.attributes['net.peer.port']).must_equal port |
102 | | - |
103 | | - span_event = span.events.first |
104 | | - _(span_event.name).must_equal 'exception' |
105 | | - _(span_event.attributes['exception.type']).must_equal 'Dalli::NetworkError' |
106 | | - _(span_event.attributes['exception.message']).must_equal 'Dalli::NetworkError' |
107 | | - end |
| 87 | + it 'after error' do |
| 88 | + dalli.set('foo', 'bar') |
| 89 | + exporter.reset |
| 90 | + |
| 91 | + dalli.instance_variable_get(:@ring).servers.first.stub(:write, ->(_bytes) { raise Dalli::NetworkError }) do |
| 92 | + dalli.get_multi('foo', 'bar') |
| 93 | + end |
| 94 | + |
| 95 | + if supports_retry_on_network_errors? |
| 96 | + _(exporter.finished_spans.size).must_equal 2 |
| 97 | + else |
| 98 | + _(exporter.finished_spans.size).must_equal 1 |
| 99 | + end |
| 100 | + |
| 101 | + _(span.name).must_equal 'getkq' |
| 102 | + _(span.attributes['db.system']).must_equal 'memcached' |
| 103 | + _(span.attributes['db.statement']).must_equal 'getkq foo bar' |
| 104 | + _(span.attributes['db.operation']).must_equal 'getkq' |
| 105 | + _(span.attributes['net.peer.name']).must_equal host |
| 106 | + _(span.attributes['net.peer.port']).must_equal port |
| 107 | + |
| 108 | + span_event = span.events.first |
| 109 | + _(span_event.name).must_equal 'exception' |
| 110 | + _(span_event.attributes['exception.type']).must_equal 'Dalli::NetworkError' |
| 111 | + _(span_event.attributes['exception.message']).must_equal 'Dalli::NetworkError' |
| 112 | + end |
108 | 113 |
|
109 | | - it 'omits db.statement' do |
110 | | - instrumentation.instance_variable_set(:@installed, false) |
111 | | - instrumentation.install(db_statement: :omit) |
| 114 | + it 'omits db.statement' do |
| 115 | + instrumentation.instance_variable_set(:@installed, false) |
| 116 | + instrumentation.install(db_statement: :omit) |
112 | 117 |
|
113 | | - dalli.set('foo', 'bar') |
| 118 | + dalli.set('foo', 'bar') |
114 | 119 |
|
115 | | - _(exporter.finished_spans.size).must_equal 1 |
116 | | - _(span.name).must_equal 'set' |
117 | | - _(span.attributes).wont_include 'db.statement' |
118 | | - end |
| 120 | + _(exporter.finished_spans.size).must_equal 1 |
| 121 | + _(span.name).must_equal 'set' |
| 122 | + _(span.attributes).wont_include 'db.statement' |
| 123 | + end |
119 | 124 |
|
120 | | - it 'obfuscates db.statement' do |
121 | | - instrumentation.instance_variable_set(:@installed, false) |
122 | | - instrumentation.install(db_statement: :obfuscate) |
| 125 | + it 'obfuscates db.statement' do |
| 126 | + instrumentation.instance_variable_set(:@installed, false) |
| 127 | + instrumentation.install(db_statement: :obfuscate) |
123 | 128 |
|
124 | | - dalli.set('foo', 'bar') |
| 129 | + dalli.set('foo', 'bar') |
125 | 130 |
|
126 | | - _(exporter.finished_spans.size).must_equal 1 |
127 | | - _(span.name).must_equal 'set' |
128 | | - _(span.attributes['db.statement']).must_equal 'set ?' |
129 | | - end |
| 131 | + _(exporter.finished_spans.size).must_equal 1 |
| 132 | + _(span.name).must_equal 'set' |
| 133 | + _(span.attributes['db.statement']).must_equal 'set ?' |
| 134 | + end |
130 | 135 |
|
131 | | - it 'supports gat' do |
132 | | - skip unless dalli.respond_to?(:gat) |
| 136 | + it 'supports gat' do |
| 137 | + skip unless dalli.respond_to?(:gat) |
133 | 138 |
|
134 | | - dalli.gat('foo') |
| 139 | + dalli.gat('foo') |
135 | 140 |
|
136 | | - _(exporter.finished_spans.size).must_equal 1 |
137 | | - _(span.name).must_equal 'gat' |
138 | | - _(span.attributes['db.statement']).must_equal 'gat foo 0' |
| 141 | + _(exporter.finished_spans.size).must_equal 1 |
| 142 | + _(span.name).must_equal 'gat' |
| 143 | + _(span.attributes['db.statement']).must_equal 'gat foo 0' |
| 144 | + end |
139 | 145 | end |
140 | 146 | end |
141 | 147 |
|
|
0 commit comments