Browse Source

Merge "Don't log health checks"

changes/24/638124/7
Zuul 2 months ago
parent
commit
0e76f1bd52
3 changed files with 18 additions and 2 deletions
  1. 2
    0
      armada/api/__init__.py
  2. 14
    0
      armada/api/middleware.py
  3. 2
    2
      armada/api/server.py

+ 2
- 0
armada/api/__init__.py View File

@@ -27,6 +27,8 @@ from armada.handlers.tiller import Tiller
27 27
 
28 28
 CONF = cfg.CONF
29 29
 
30
+HEALTH_PATH = 'health'
31
+
30 32
 
31 33
 class BaseResource(object):
32 34
 

+ 14
- 0
armada/api/middleware.py View File

@@ -14,6 +14,8 @@
14 14
 
15 15
 import re
16 16
 
17
+from armada.api import HEALTH_PATH
18
+
17 19
 from uuid import UUID
18 20
 
19 21
 from oslo_config import cfg
@@ -100,9 +102,18 @@ class LoggingMiddleware(object):
100 102
     # don't log any headers beginning with X-*
101 103
     hdr_exclude = re.compile('x-.*', re.IGNORECASE)
102 104
 
105
+    # don't log anything for health checks
106
+    path_exclude = re.compile('.*/{}$'.format(HEALTH_PATH))
107
+
108
+    def exclude_path(self, req):
109
+        return LoggingMiddleware.path_exclude.match(req.path)
110
+
103 111
     def process_request(self, req, resp):
104 112
         """ Set up values to be logged across the request
105 113
         """
114
+        if self.exclude_path(req):
115
+            return
116
+
106 117
         ctx = req.context
107 118
         extra = {
108 119
             'user': ctx.user,
@@ -115,6 +126,9 @@ class LoggingMiddleware(object):
115 126
     def process_response(self, req, resp, resource, req_succeeded):
116 127
         """ Log the response information
117 128
         """
129
+        if self.exclude_path(req):
130
+            return
131
+
118 132
         ctx = req.context
119 133
         extra = {
120 134
             'user': ctx.user,

+ 2
- 2
armada/api/server.py View File

@@ -18,7 +18,7 @@ from oslo_policy import policy
18 18
 from oslo_log import log as logging
19 19
 
20 20
 from armada import conf
21
-from armada.api import ArmadaRequest
21
+from armada.api import ArmadaRequest, HEALTH_PATH
22 22
 from armada.api.controller.armada import Apply
23 23
 from armada.api.middleware import AuthMiddleware
24 24
 from armada.api.middleware import ContextMiddleware
@@ -60,7 +60,7 @@ def create(enable_middleware=CONF.middleware):
60 60
 
61 61
     # Configure API routing
62 62
     url_routes_v1 = (
63
-        ('health', Health()),
63
+        (HEALTH_PATH, Health()),
64 64
         ('apply', Apply()),
65 65
         ('releases', Release()),
66 66
         ('rollback/{release}', Rollback()),

Loading…
Cancel
Save