def setUp(self, trace_all = True, flushcount = 0, enable_logging = False, use_parent_tracer = False, *args, **kwargs): self.enable_logging = enable_logging or os.environ.get("PYCBC_ENABLE_LOGGING") self.use_parent_tracer = use_parent_tracer self.using_jaeger =(os.environ.get("PYCBC_USE_JAEGER") == "TRUE") self.flushdict = {k: v for k, v in zip(map(str, range(1, 100)), map(str, range(1, 100)))} self.trace_all = os.environ.get("PYCBC_TRACE_ALL") or trace_all self.flushcount = flushcount if self.using_jaeger and self.flushcount>5: raise SkipTest("too slow when using jaeger") enable_logging |= bool(self.trace_all) if enable_logging: couchbase.enable_logging() if self.use_parent_tracer: kwargs['init_tracer'] =self.init_tracer kwargs['enable_tracing']="true" super(TracedCase, self).setUp(**kwargs) if self.trace_all: self.cb.tracing_orphaned_queue_flush_interval = 0.0001 self.cb.tracing_orphaned_queue_size =10 self.cb.tracing_threshold_queue_flush_interval = 0.00001 self.cb.tracing_threshold_queue_size = 10 self.cb.tracing_threshold_kv = 0.00001 self.cb.tracing_threshold_n1ql= 0.00001 self.cb.tracing_threshold_view =0.00001 self.cb.tracing_threshold_fts =0.00001 self.cb.tracing_threshold_analytics =0.00001
def test_timeout(self): raise SkipTest("To be fixed") if sys.platform == 'win32': raise SkipTest("To be fixed on Windows") if sys.version_info >= (3, 6) and sys.platform.startswith( 'linux') and os.environ.get("VALGRIND_REPORT_DIR"): raise SkipTest("To be fixed on Linux 3.6/Valgrind") couchbase.enable_logging() bucket = self.coll bucket.upsert("key", "value") self.timeout = timedelta(seconds=9e-6) bucket.tracing_orphaned_queue_flush_interval = timedelta(seconds=1) bucket.tracing_orphaned_queue_size = 10 bucket.tracing_threshold_queue_flush_interval = timedelta(seconds=5) bucket.tracing_threshold_queue_size = 10 bucket.tracing_threshold_kv = timedelta(seconds=1000) bucket.tracing_threshold_n1ql = timedelta(seconds=1000) bucket.tracing_threshold_view = timedelta(seconds=1000) bucket.tracing_threshold_fts = timedelta(seconds=1000) bucket.tracing_threshold_analytics = timedelta(seconds=1000) self.verify_tracer(bucket, r'.*Operations over threshold:.*', rep_factor=100)
def test_redaction(self): all_tags = r'|'.join( re.escape(v) for k, v in _LCB.__dict__.items() if re.match(r'.*LCB_LOG_(SD|MD|UD)_[OC]TAG.*', k)) enable_logging() try: contains_no_tags = r'^(.(?!<' + all_tags + r'))*$' contains_tags = r'^.*(' + all_tags + r').*$' expected = { 0: { logging.DEBUG: { 'text': 'off', 'pattern': contains_no_tags } }, 1: { logging.DEBUG: { 'text': 'on', 'pattern': contains_tags } } } for num, entry in reversed(list(expected.items())): for level, val in entry.items(): optype = 'connstr' with self.assertLogs(level=level, recursive_check=True) as cm: curbc = self.make_connection(log_redaction=val['text']) self.assertEqual(num != 0, curbc.redaction != 0) result_str = ''.join(cm.output) logging.info( 'checking {pattern} matches {optype} addition {text} result:{result_str}' .format(optype=optype, result_str=result_str, **val)) self.assertRegex(result_str, val['pattern']) opposite = 1 - num opposite_val = expected[opposite][level] optype = 'cntl' with self.assertLogs(level=level) as cm: curbc.redaction = opposite curbc.upsert(key='test', value='value') self.assertEqual(opposite != 0, curbc.redaction != 0) result_str = ''.join(cm.output) logging.info( 'checking {pattern} matches {optype} addition {text} result:{result_str}' .format(optype=optype, result_str=result_str, **val)) self.assertRegex(''.join(cm.output), opposite_val['pattern']) finally: couchbase.disable_logging()
def setUp(self, *args, **kwargs): if not couchbase._libcouchbase.PYCBC_TRACING: raise SkipTest("Tracing feature not compiled into Python Client") kwargs = {} couchbase.enable_logging() kwargs['enable_tracing'] = "true" #super(TimeoutTest, self).setUp(**kwargs) super(TimeoutTest, self).setUp(trace_all=True, enable_logging=True, use_parent_tracer=False, flushcount=0) self.repetitions = 100 logging.info("starting TimeoutTest")
def setUp(self, *args, **kwargs): kwargs = {} couchbase.enable_logging() kwargs['enable_tracing'] = "true" #super(TimeoutTest, self).setUp(**kwargs) super(TimeoutTest, self).setUp(trace_all=True, enable_logging=True, use_parent_tracer=True, flushcount=0) self.repetitions = 1 logging.info("starting TimeoutTest")
def test_logging(self): # Assume we don't have logging here.. import couchbase._libcouchbase as lcb self.assertFalse(lcb.lcb_logging()) logfn = lambda x: x lcb.lcb_logging(logfn) self.assertEqual(logfn, lcb.lcb_logging()) couchbase.enable_logging() self.assertTrue(lcb.lcb_logging()) couchbase.disable_logging() self.assertFalse(lcb.lcb_logging())
def setUp(self, trace_all=True, flushcount=0, enable_logging=False, use_parent_tracer=False, *args, **kwargs): self.timeout = None # self.enable_logging = enable_logging or os.environ.get("PYCBC_ENABLE_LOGGING") self.use_parent_tracer = use_parent_tracer self.using_jaeger = (os.environ.get("PYCBC_USE_JAEGER") == "TRUE") self.flushdict = { k: v for k, v in zip(map(str, range(1, 100)), map(str, range(1, 100))) } self.trace_all = os.environ.get("PYCBC_TRACE_ALL") or trace_all self.flushcount = flushcount if self.using_jaeger and self.flushcount > 5: raise SkipTest("too slow when using jaeger") enable_logging |= bool(self.trace_all) if enable_logging: couchbase.enable_logging() if self.use_parent_tracer: kwargs['init_tracer'] = self.init_tracer kwargs['enable_tracing'] = "true" if self.trace_all: tracing_options = ClusterTracingOptions( tracing_orphaned_queue_flush_interval=timedelta( milliseconds=1), tracing_orphaned_queue_size=9, tracing_threshold_queue_flush_interval=timedelta( milliseconds=1), tracing_threshold_queue_size=9, tracing_threshold_kv=timedelta(milliseconds=1), #tracing_threshold_query=timedelta(milliseconds=1), tracing_threshold_view=timedelta(milliseconds=1), tracing_threshold_search=timedelta(milliseconds=1), tracing_threshold_analytics=timedelta(milliseconds=1)) dummy_auth = PasswordAuthenticator("default", "password") # the dummy_auth isn't really used, the base class decides between classic # and password dependng on mock or not. opts = ClusterOptions(authenticator=dummy_auth, tracing_options=tracing_options) kwargs["cluster_options"] = opts super(TracedCase, self).setUp(**kwargs)
def test_redaction(self): all_tags = r'|'.join(re.escape(v) for k, v in _LCB.__dict__.items() if re.match(r'.*LCB_LOG_(SD|MD|UD)_[OC]TAG.*', k)) enable_logging() try: contains_no_tags = r'^(.(?!<' + all_tags + r'))*$' contains_tags = r'^.*(' + all_tags + r').*$' expected = {0: {logging.DEBUG: {'text': 'off', 'pattern': contains_no_tags}}, 1: {logging.DEBUG: {'text': 'on', 'pattern': contains_tags}}} for num, entry in reversed(list(expected.items())): for level, val in entry.items(): optype='connstr' with self.assertLogs(level=level, recursive_check=True) as cm: curbc = self.make_connection(log_redaction=val['text']) self.assertEqual(num != 0, curbc.redaction != 0) result_str=''.join(cm.output) logging.info( 'checking {pattern} matches {optype} addition {text} result:{result_str}'.format(optype=optype, result_str=result_str, **val)) self.assertRegex(result_str, val['pattern']) opposite = 1 - num opposite_val = expected[opposite][level] optype='cntl' with self.assertLogs(level=level) as cm: curbc.redaction = opposite curbc.upsert(key='test', value='value') self.assertEqual(opposite != 0, curbc.redaction != 0) result_str=''.join(cm.output) logging.info( 'checking {pattern} matches {optype} addition {text} result:{result_str}'.format(optype=optype, result_str=result_str, **val)) self.assertRegex(''.join(cm.output), opposite_val['pattern']) finally: couchbase.disable_logging()
def test_timeout(self): if sys.platform == 'win32': raise SkipTest("To be fixed on Windows") if sys.version_info >= (3,6) and sys.platform.startswith('linux') and os.environ.get("VALGRIND_REPORT_DIR"): raise SkipTest("To be fixed on Linux 3.6/Valgrind") couchbase.enable_logging() bucket = self.cb bucket.upsert("key", "value") bucket.timeout = 9e-6 bucket.tracing_orphaned_queue_flush_interval = 1 bucket.tracing_orphaned_queue_size = 10 bucket.tracing_threshold_queue_flush_interval = 5 bucket.tracing_threshold_queue_size = 10 bucket.tracing_threshold_kv = 0.00001 bucket.tracing_threshold_n1ql = 0.00001 bucket.tracing_threshold_view = 0.00001 bucket.tracing_threshold_fts = 0.00001 bucket.tracing_threshold_analytics = 0.00001 self.verify_tracer(bucket, r'.*Operations over threshold:.*', rep_factor=100)
from datetime import timedelta import logging import sys from couchbase.cluster import Cluster, ClusterOptions, ClusterTracingOptions from couchbase.auth import PasswordAuthenticator from couchbase import enable_logging # NOTE: for simple test to see output, drop the threshold # ex: tracing_threshold_kv=timedelta(microseconds=1) # tag::threshold_logging_config[] # configure logging logging.basicConfig(stream=sys.stderr, level=logging.INFO) # setup couchbase logging enable_logging() tracing_opts = ClusterTracingOptions( tracing_threshold_queue_size=10, tracing_threshold_kv=timedelta(milliseconds=500)) cluster_opts = ClusterOptions(authenticator=PasswordAuthenticator( "Administrator", "password"), tracing_options=tracing_opts) cluster = Cluster( "couchbase://localhost", options=cluster_opts ) # end::threshold_logging_config[]
from couchbase.bucket import Bucket import logging import os import couchbase couchbase.enable_logging() logging.basicConfig(level=logging.INFO) match_history = Bucket('couchbase://{}/{}'.format( os.environ.get('DB_HOST', 'localhost'), os.environ.get('DB_BUCKET_MATCH_HISTORY', 'match_history')))
from couchbase.cluster import Cluster from couchbase.cluster import PasswordAuthenticator from couchbase.n1ql import N1QLQuery, N1QLError import couchbase.exceptions as CBErr import json from time import sleep, time import couchbase, logging couchbase.enable_logging( ) # allows us to see warnings for slow/orphaned operations # set logging to WARNING level so we can see warnings ch = logging.StreamHandler() ch.setLevel(logging.WARNING) logging.getLogger().addHandler(ch) CONN_STR = 'couchbase://10.143.191.101,10.143.191.102,10.143.191.103' cluster = Cluster(CONN_STR) authenticator = PasswordAuthenticator('Danzibob', 'C0uchbase123') cluster.authenticate(authenticator) bucket = cluster.open_bucket('travel-sample') print("Connected.") # Threshold logging bucket.tracing_threshold_queue_flush_interval = 300000 # 5 minutes bucket.tracing_threshold_queue_size = 5 bucket.tracing_threshold_kv = 5000 # 5 ms def getHint(err): return str(err).split(", ")[1]
from couchbase.bucket import Bucket import logging import os import couchbase couchbase.enable_logging() logging.basicConfig(level=logging.INFO) match_history = Bucket('couchbase://{}/{}'.format( os.environ.get('DB_HOST', 'localhost'), os.environ.get('DB_BUCKET_MATCH_HISTORY', 'match_history') ))