forked from scylladb/scylla-cluster-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_decode_backtrace.py
195 lines (154 loc) · 7.35 KB
/
test_decode_backtrace.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright (c) 2020 ScyllaDB
import os
import json
from multiprocessing import Queue
import unittest
from functools import cached_property
from sdcm.cluster import TestConfig
from sdcm.db_log_reader import DbLogReader
from sdcm.sct_events.database import SYSTEM_ERROR_EVENTS_PATTERNS
from unit_tests.dummy_remote import DummyRemote
from unit_tests.test_utils_common import DummyNode
from unit_tests.lib.events_utils import EventsUtilsMixin
class DecodeDummyNode(DummyNode): # pylint: disable=abstract-method
def copy_scylla_debug_info(self, node_name, debug_file):
return "scylla_debug_info_file"
class DummyDbLogReader(DbLogReader):
def get_scylla_debuginfo_file(self):
return "scylla_debug_info_file"
class TestDecodeBactraces(unittest.TestCase, EventsUtilsMixin):
@classmethod
def setUpClass(cls):
cls.setup_events_processes(events_device=True, events_main_device=False, registry_patcher=True)
@classmethod
def tearDownClass(cls):
cls.teardown_events_processes()
@cached_property
def test_config(self):
result = TestConfig()
result.set_decoding_queue()
return result
@cached_property
def node(self):
dummy_node = DecodeDummyNode(
name='test_node',
parent_cluster=None,
base_logdir=self.temp_dir,
ssh_login_info=dict(key_file='~/.ssh/scylla-test'),
)
dummy_node.remoter = DummyRemote()
return dummy_node
@cached_property
def monitor_node(self):
dummy_monitor = DecodeDummyNode(
name='test_monitor_node',
parent_cluster=None,
base_logdir=self.temp_dir,
ssh_login_info=dict(key_file='~/.ssh/scylla-test'),
)
dummy_monitor.remoter = DummyRemote()
return dummy_monitor
@cached_property
def _db_log_reader(self):
return DummyDbLogReader(
system_log=self.node.system_log,
node_name=str(self),
remoter=self.node.remoter,
decoding_queue=self.test_config.DECODING_QUEUE,
system_event_patterns=SYSTEM_ERROR_EVENTS_PATTERNS,
log_lines=True,
)
@cached_property
def _db_log_reader_no_decoding(self):
return DummyDbLogReader(
system_log=self.node.system_log,
node_name=str(self),
remoter=self.node.remoter,
decoding_queue=None,
system_event_patterns=SYSTEM_ERROR_EVENTS_PATTERNS,
log_lines=False,
)
def _read_and_publish_events(self):
self._db_log_reader._read_and_publish_events() # pylint: disable=protected-access
def _read_and_publish_events_no_decoding(self):
self._db_log_reader_no_decoding._read_and_publish_events() # pylint: disable=protected-access
def setUp(self):
self.node.system_log = os.path.join(os.path.dirname(__file__), 'test_data', 'system.log')
def test_01_reactor_stall_is_not_decoded_if_disabled(self):
self.monitor_node.start_decode_on_monitor_node_thread()
self._read_and_publish_events_no_decoding() # pylint: disable=protected-access
self.monitor_node.termination_event.set()
self.monitor_node.stop_task_threads()
self.monitor_node.wait_till_tasks_threads_are_stopped()
events = []
with self.get_raw_events_log().open() as events_file:
for line in events_file.readlines():
events.append(json.loads(line))
assert any(event.get('raw_backtrace') for event in events), "should have at least one backtrace"
for event in events:
if event.get('raw_backtrace'):
self.assertIsNone(event['backtrace'])
def test_02_reactor_stalls_is_decoded_if_enabled(self):
self.test_config.BACKTRACE_DECODING = True
self.test_config.DECODING_QUEUE = Queue()
self.monitor_node.start_decode_on_monitor_node_thread()
self._read_and_publish_events()
self.monitor_node.termination_event.set()
self.monitor_node.stop_task_threads()
self.monitor_node.wait_till_tasks_threads_are_stopped()
events = []
with self.get_raw_events_log().open() as events_file:
for line in events_file.readlines():
events.append(json.loads(line))
assert any(event.get('raw_backtrace') for event in events), "should have at least one backtrace"
for event in events:
if event.get('backtrace') and event.get('raw_backtrace'):
self.assertEqual(event['backtrace'].strip(),
"addr2line -Cpife scylla_debug_info_file {}".format(' '.join(event['raw_backtrace'].split("\n"))))
def test_03_decode_interlace_reactor_stall(self): # pylint: disable=invalid-name
self.test_config.DECODING_QUEUE = Queue()
self.test_config.BACKTRACE_DECODING = True
self.monitor_node.start_decode_on_monitor_node_thread()
self.node.system_log = os.path.join(os.path.dirname(__file__), 'test_data', 'system_interlace_stall.log')
self._read_and_publish_events() # pylint: disable=protected-access
self.monitor_node.termination_event.set()
self.monitor_node.stop_task_threads()
self.monitor_node.wait_till_tasks_threads_are_stopped()
events = []
with self.get_raw_events_log().open() as events_file:
for line in events_file.readlines():
events.append(json.loads(line))
assert any(event.get('raw_backtrace') for event in events), "should have at least one backtrace"
for event in events:
if event.get('backtrace') and event.get('raw_backtrace'):
self.assertEqual(event['backtrace'].strip(),
"addr2line -Cpife scylla_debug_info_file {}".format(' '.join(event['raw_backtrace'].split("\n"))))
def test_04_decode_backtraces_core(self):
self.test_config.DECODING_QUEUE = Queue()
self.test_config.BACKTRACE_DECODING = True
self.monitor_node.start_decode_on_monitor_node_thread()
self.node.system_log = os.path.join(os.path.dirname(__file__), 'test_data', 'system_core.log')
self._read_and_publish_events()
self.monitor_node.termination_event.set()
self.monitor_node.stop_task_threads()
self.monitor_node.wait_till_tasks_threads_are_stopped()
events = []
with self.get_raw_events_log().open() as events_file:
for line in events_file.readlines():
events.append(json.loads(line))
assert any(event.get('raw_backtrace') for event in events), "should have at least one backtrace"
for event in events:
if event.get('backtrace') and event.get('raw_backtrace'):
self.assertEqual(event['backtrace'].strip(),
"addr2line -Cpife scylla_debug_info_file {}".format(' '.join(event['raw_backtrace'].split("\n"))))