def test_check(aggregator, gauges): for config in deepcopy(INSTANCES): check = CouchDb(common.CHECK_NAME, {}, [config]) check.check(config) _assert_check(aggregator, gauges)
def test_view_compaction_metrics(aggregator, gauges): class LoadGenerator(threading.Thread): STOP = 0 RUN = 1 def __init__(self, server, auth): self._server = server self._auth = auth self._status = self.RUN threading.Thread.__init__(self) def run(self): docs = [] count = 0 while self._status == self.RUN: count += 1 if count % 5 == 0: self.compact_views() theid = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) docs.append(self.post_doc(theid)) docs = list(map(lambda x: self.update_doc(x), docs)) self.generate_views() def generate_views(self): url = '{}/kennel/_design/dummy/_view/all'.format(self._server) try: r = requests.get(url, auth=self._auth, timeout=1) r.raise_for_status() except requests.exceptions.Timeout: None url = '{}/kennel/_design/dummy/_view/by_data'.format(self._server) try: r = requests.get(url, auth=self._auth, timeout=1) r.raise_for_status() except requests.exceptions.Timeout: None def update_doc(self, doc): body = {'data': str(random.randint(0, 1000000000)), '_rev': doc['rev']} url = '{}/kennel/{}'.format(self._server, doc['id']) r = requests.put(url, auth=self._auth, headers={'Content-Type': 'application/json'}, json=body) r.raise_for_status() return r.json() def post_doc(self, doc_id): body = {"_id": doc_id, "data": str(time.time())} url = '{}/kennel'.format(self._server) r = requests.post(url, auth=self._auth, headers={'Content-Type': 'application/json'}, json=body) r.raise_for_status() return r.json() def compact_views(self): url = '{}/kennel/_compact/dummy'.format(self._server) r = requests.post(url, auth=self._auth, headers={'Content-Type': 'application/json'}) r.raise_for_status() def stop(self): self._status = self.STOP threads = [] for _ in range(40): t = LoadGenerator(common.NODE1['server'], (common.NODE1['user'], common.NODE1['password'])) t.start() threads.append(t) tries = 0 try: metric_found = False while not metric_found and tries < 40: tries += 1 try: for config in [common.NODE1, common.NODE2, common.NODE3]: check = CouchDb(common.CHECK_NAME, {}, [config]) check.check(config) except Exception: time.sleep(1) continue for m_name in aggregator._metrics: if re.search(r'view_compaction\.progress', str(m_name)) is not None: metric_found = True for gauge in gauges["view_compaction_tasks_gauges"]: aggregator.assert_metric(gauge) break finally: for t in threads: t.stop() for t in threads: t.join() if tries >= 20: raise AssertionError('Could not find the view_compaction happening')