Przeglądaj źródła

HUE-8936 [tracing] Adding ini configuration

Romain 6 lat temu
rodzic
commit
affecc1a44

+ 10 - 0
desktop/conf.dist/hue.ini

@@ -789,6 +789,16 @@
    ## collection_interval=30000
 
 
+  # Configuration options for the request Tracing
+  # ------------------------------------------------------------------------
+  [[tracing]]
+  ## If tracing is enabled.
+  # enabled=false
+
+  ## Trace all the requests instead of a few specific ones like the SQL Editor. Much noisiers.
+  # trace_all=false
+
+
   # Configuration options for the Task Server
   # ------------------------------------------------------------------------
   [[task_server]]

+ 10 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -791,6 +791,16 @@
    ## collection_interval=30000
 
 
+  # Configuration options for the request Tracing
+  # ------------------------------------------------------------------------
+  [[tracing]]
+  ## If tracing is enabled.
+  # enabled=false
+
+  ## Trace all the requests instead of a few specific ones like the SQL Editor. Much noisiers.
+  # trace_all=false
+
+
   # Configuration options for the Task Server
   # ------------------------------------------------------------------------
   [[task_server]]

+ 19 - 0
desktop/core/src/desktop/conf.py

@@ -1664,6 +1664,25 @@ ENABLE_PROMETHEUS = Config(
 )
 
 
+TRACING = ConfigSection(
+  key="tracing",
+  help=_("Tracing configuration."),
+  members=dict(
+    ENABLED= Config(
+      key='enabled',
+      default=False,
+      type=coerce_bool,
+      help=_('If tracing is enabled.')
+    ),
+    TRACE_ALL = Config(
+      key='trace_all',
+      default=False,
+      type=coerce_bool,
+      help=_('Trace all the requests instead of a few specific ones like the SQL Editor. Much noisiers.')
+    ),
+))
+
+
 def task_server_default_result_directory():
   """Local directory to store task results."""
   return 'file://%s' % get_run_root('logs')

+ 25 - 36
desktop/core/src/desktop/settings.py

@@ -29,9 +29,10 @@ import os
 import pkg_resources
 import sys
 
-from guppy import hpy
+import django_opentracing
 
 from django.utils.translation import ugettext_lazy as _
+from guppy import hpy
 
 import desktop.redaction
 from desktop.lib.paths import get_desktop_root
@@ -713,40 +714,28 @@ if desktop.conf.ENABLE_PROMETHEUS.get():
     val['BACKEND'] = val['BACKEND'].replace('django.core.cache.backends', 'django_prometheus.cache.backends')
 
 
-
+################################################################
 # OpenTracing settings
+################################################################
 
-import django_opentracing
-
-# ./build/env/bin/pip install jaeger-client
-# ./build/env/bin/pip install django_opentracing
-
-# if not included, defaults to True.
-# has to come before OPENTRACING_TRACING setting because python...
-OPENTRACING_TRACE_ALL = True
-
-# Callable that returns an `opentracing.Tracer` implementation.
-# OPENTRACING_TRACER_CALLABLE = 'opentracing.Tracer'
-OPENTRACING_TRACER_CALLABLE = __name__ + '.tracer'
-
-def tracer():
-    from jaeger_client import Config
-    config = Config(
-        config={
-            'sampler': {
-                'type': 'const',
-                'param': 1,
-            },
-            'logging': False,
-        },
-        # metrics_factory=PrometheusMetricsFactory(namespace='hue-api'),
-        service_name='hue-api'
-    )
-    return config.initialize_tracer()
-
-# default is []
-# only valid if OPENTRACING_TRACE_ALL == True
-OPENTRACING_TRACED_ATTRIBUTES = ['META']
-
-
-MIDDLEWARE_CLASSES.insert(0, 'django_opentracing.OpenTracingMiddleware')
+if desktop.conf.TRACING.ENABLED.get():
+  OPENTRACING_TRACE_ALL = desktop.conf.TRACING.TRACE_ALL.get()
+  OPENTRACING_TRACER_CALLABLE = __name__ + '.tracer'
+
+  def tracer():
+      from jaeger_client import Config
+      config = Config(
+          config={
+              'sampler': {
+                  'type': 'const',
+                  'param': 1,
+              },
+              'logging': False,
+          },
+          # metrics_factory=PrometheusMetricsFactory(namespace='hue-api'),
+          service_name='hue-api'
+      )
+      return config.initialize_tracer()
+
+  OPENTRACING_TRACED_ATTRIBUTES = ['META'] # Only valid if OPENTRACING_TRACE_ALL == True
+  MIDDLEWARE_CLASSES.insert(0, 'django_opentracing.OpenTracingMiddleware')