Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: 6deb00cfd2
...
compare: fd446afdfd
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 6 files changed
  • 0 commit comments
  • 2 contributors
View
7 debian/changelog
@@ -1,3 +1,10 @@
+frontik (2.14.0) unstable; urgency=low
+
+ [ Andrey Sumin ]
+ * HH-28791 display version info and cur req in debug log
+
+ -- Vasily Katraev (hh.ru) <v.katraev@hh.ru> Thu, 04 Oct 2012 16:28:52 +0400
+
frontik (2.13.3) unstable; urgency=low
[ Andrey Sumin ]
View
60 frontik/app.py
@@ -1,9 +1,10 @@
import imp
import logging
-import os.path
import sys
import re
import time
+import functools
+import urlparse
import lxml.etree as etree
import tornado.autoreload
@@ -11,42 +12,41 @@
import tornado.ioloop
from tornado.options import options
+import frontik.handler as handler
import frontik.magic_imp
import frontik.doc
-from frontik import __version__
-from frontik import etree
-from tornado.httpserver import HTTPRequest
-import urlparse
log = logging.getLogger('frontik.server')
-import frontik.handler as handler
-import functools
+def __get_apps_versions():
+ app_versions = etree.Element('applications')
-class VersionHandler(tornado.web.RequestHandler):
- def get(self):
- self.set_header('Content-Type', 'text/xml')
- versions = etree.Element("versions")
+ for path, app in options.urls:
+ app_info = etree.Element('application', name=repr(app), path=path)
+ try:
+ application = app.ph_globals.config.version
+ app_info.extend(list(application))
+ except:
+ etree.SubElement(app_info, 'version').text = 'app doesn''t support version'
- from version import version
- etree.SubElement(versions, "frontik").text = version
+ etree.SubElement(app_info, 'initialized_wo_error').text = str(app.initialized_wo_error)
+ app_versions.append(app_info)
- import frontik.options
- application_versions = etree.Element("applications")
+ return app_versions
- for path, app in options.urls:
- app_info = etree.Element("application", name=repr(app), path = path)
- try:
- application = app.ph_globals.config.version
- app_info.extend(list(application))
- except:
- etree.SubElement(app_info, "version").text = "app doesn't support version"
- etree.SubElement(app_info, "initialized_wo_error").text = str(app.initialized_wo_error)
- application_versions.append(app_info)
-
- versions.append(application_versions)
- self.write(frontik.doc.etree_to_xml(versions))
+def get_frontik_and_apps_versions():
+ from version import version
+ versions = etree.Element('versions')
+ etree.SubElement(versions, 'frontik').text = version
+ versions.append(__get_apps_versions())
+ return versions
+
+
+class VersionHandler(tornado.web.RequestHandler):
+ def get(self):
+ self.set_header('Content-Type', 'text/xml')
+ self.write(frontik.doc.etree_to_xml(get_frontik_and_apps_versions()))
class StatusHandler(tornado.web.RequestHandler):
@@ -57,11 +57,11 @@ def get(self):
self.write('http reqs got: %s bytes\n' % (handler.stats.http_reqs_size_sum,))
cur_uptime = time.time() - handler.stats.start_time
if cur_uptime < 60:
- res = 'uptime for : %d seconds\n' % ((cur_uptime),)
+ res = 'uptime for : %d seconds\n' % cur_uptime
elif cur_uptime < 3600:
res = 'uptime for : %d minutes\n' % ((cur_uptime/60),)
else:
- res = 'uptime for : %d hours and %d minutes \n' % ((cur_uptime/3600), (cur_uptime % 3600)/60)
+ res = 'uptime for : %d hours and %d minutes \n' % (cur_uptime/3600, (cur_uptime % 3600)/60)
self.write(res)
@@ -131,7 +131,7 @@ def augment_request(request, match, parse):
request.arguments.setdefault(name, []).extend(parse(value))
def dispatcher(cls):
- 'makes on demand initializing class'
+ """makes on demand initializing class"""
old_init = cls.__init__
def __init__(self, *args, **kwargs):
self._init_partial = functools.partial(old_init, self, *args, **kwargs)
View
34 frontik/debug.xsl
@@ -12,7 +12,7 @@
</xsl:if>
</xsl:variable>
- <xsl:template match="/log">
+ <xsl:template match="log">
<html>
<head>
<title>Status
@@ -29,6 +29,9 @@
bytes received: <xsl:value-of select="sum(entry/response/size)"/>,
bytes produced: <xsl:value-of select="@response-size"/>
</div>
+
+ <xsl:apply-templates select="." mode="versions-info"/>
+ <xsl:apply-templates select="." mode="general-info"/>
<xsl:apply-templates select="entry"/>
</body>
</html>
@@ -36,6 +39,35 @@
<xsl:template match="entry[contains(@msg, 'finish group') and /log/@mode != 'full']"/>
+ <xsl:template match="log" mode="versions-info">
+ <div class="textentry m-textentry__expandable">
+ <div onclick="toggle(this.parentNode)" class="textentry__head textentry__switcher">
+ <span class="textentry__head__expandtext">
+ Version info
+ </span>
+ </div>
+ <div class="details">
+ <xsl:apply-templates select="versions/node()" mode="color-xml"/>
+ </div>
+ </div>
+ </xsl:template>
+
+ <xsl:template match="log" mode="general-info">
+ <div class="textentry m-textentry__expandable">
+ <div onclick="toggle(this.parentNode)" class="textentry__head textentry__switcher">
+ <span class="textentry__head__expandtext">
+ General request/response info
+ </span>
+ </div>
+ <div class="details">
+ <xsl:apply-templates select="request/params"/>
+ <xsl:apply-templates select="request/headers"/>
+ <xsl:apply-templates select="request/cookies"/>
+ <xsl:apply-templates select="response/headers"/>
+ </div>
+ </div>
+ </xsl:template>
+
<xsl:template match="entry">
<xsl:variable name="highlight">
View
10 frontik/handler.py
@@ -164,7 +164,7 @@ def require_debug_access(self, login = None, passwd = None):
def get_error_html(self, status_code, **kwargs):
if self._prepared and self.debug.debug_mode_logging:
- return self.debug.get_debug_page(status_code, **kwargs)
+ return self.debug.get_debug_page(status_code, self._headers, **kwargs)
else:
#if not prepared (for example, working handlers count limit) or not in
#debug mode use default tornado error page
@@ -233,20 +233,22 @@ def finish(self, chunk = None):
self._response_size += len(chunk) if chunk is not None else 0
if self.debug.debug_return_response:
- headers = {'Content-Length': str(self._response_size)}
+ original_headers = {'Content-Length': str(self._response_size)}
+ response_headers = dict(self._headers, **original_headers)
original_response = {
'buffer': ''.join(self._write_buffer) + (chunk if chunk is not None else ''),
- 'headers': dict(self._headers, **headers),
+ 'headers': response_headers,
'code': self._status_code
}
self.set_header(self.INHERIT_DEBUG_HEADER_NAME, True)
else:
+ response_headers = self._headers
original_response = None
self.set_header('Content-Type', 'text/html')
self._status_code = 200
- res = self.debug.get_debug_page(self._status_code, original_response)
+ res = self.debug.get_debug_page(self._status_code, response_headers, original_response)
else:
res = chunk
View
78 frontik/handler_xml_debug.py
@@ -1,17 +1,14 @@
# -*- coding: utf-8 -*-
import Cookie
-import inspect
import logging
-import os.path
-import time
import traceback
import urlparse
import weakref
-import xml.sax.saxutils
import json
import copy
from datetime import datetime
+import frontik.app
import frontik.handler
import frontik.util
import frontik.xml_util
@@ -24,7 +21,6 @@
log = logging.getLogger('XML_debug')
def response_to_xml(response):
- headers = etree.Element("headers")
time_info = etree.Element("time_info")
content_type = response.headers.get('Content-Type','')
@@ -46,9 +42,6 @@ def response_to_xml(response):
except Exception as e:
body = 'Cant show response body, ' + str(e)
- for name, value in response.headers.iteritems():
- headers.append(E.header(value, name = name))
-
for name, value in response.time_info.iteritems():
time_info.append(E.time(str(value), name = name))
@@ -60,32 +53,12 @@ def response_to_xml(response):
E.error(str(response.error)),
E.size(str(len(response.body)) if response.body is not None else '0'),
E.request_time(str(int(response.request_time * 1000))),
- headers,
+ _headers_to_xml(response.headers),
time_info,
)
)
-
def request_to_xml(request):
- headers = etree.Element("headers")
-
- for name, value in request.headers.iteritems():
- if name != "Cookie":
- headers.append(E.header(str(value), name = name))
-
-
- cookies = etree.Element("cookies")
- if "Cookie" in request.headers:
- _cookies = Cookie.SimpleCookie(request.headers["Cookie"])
- for cookie in _cookies:
- cookies.append(E.cookie(_cookies[cookie].value, name = cookie))
-
- params = etree.Element("params")
- query = get_query_parameters(request.url)
- for name, values in query.iteritems():
- for value in values:
- params.append(E.param(unicode(value, "utf-8"), name = name))
-
content_type = request.headers.get('Content-Type','')
body = etree.Element("body", content_type = content_type)
@@ -111,13 +84,36 @@ def request_to_xml(request):
E.max_redirects(str(request.max_redirects)),
E.method(request.method),
E.request_timeout(str(request.request_timeout)),
- params,
+ _params_to_xml(request.url),
E.url(request.url),
- headers,
- cookies
+ _headers_to_xml(request.headers),
+ _cookies_to_xml(request.headers)
)
)
+def _params_to_xml(url):
+ params = etree.Element('params')
+ query = get_query_parameters(url)
+ for name, values in query.iteritems():
+ for value in values:
+ params.append(E.param(unicode(value, 'utf-8'), name = name))
+ return params
+
+def _headers_to_xml(request_or_response_headers):
+ headers = etree.Element('headers')
+ for name, value in request_or_response_headers.iteritems():
+ if name != 'Cookie':
+ headers.append(E.header(str(value), name = name))
+ return headers
+
+def _cookies_to_xml(request_headers):
+ cookies = etree.Element('cookies')
+ if 'Cookie' in request_headers:
+ _cookies = Cookie.SimpleCookie(request_headers['Cookie'])
+ for cookie in _cookies:
+ cookies.append(E.cookie(_cookies[cookie].value, name = cookie))
+ return cookies
+
class DebugPageHandler(logging.Handler):
def __init__(self):
@@ -133,7 +129,9 @@ def __init__(self):
self.log_data = etree.Element("log")
- FIELDS = ['created', 'filename', 'funcName', 'levelname', 'levelno', 'lineno', 'module', 'msecs', 'name', 'pathname', 'process', 'processName', 'relativeCreated', 'threadName']
+ FIELDS = ['created', 'filename', 'funcName', 'levelname', 'levelno', 'lineno', 'module', 'msecs',
+ 'name', 'pathname', 'process', 'processName', 'relativeCreated', 'threadName']
+
def handle(self, record):
entry_attrs = {}
for field in self.FIELDS:
@@ -202,10 +200,16 @@ def __init__(self, handler):
if self.debug_return_response:
self.handler.log.debug('debug mode will be passed to all frontik apps requested (debug=pass)')
- def get_debug_page(self, status_code, original_response=None, **kwargs):
- self.debug_log_handler.log_data.set("code", str(status_code))
- self.debug_log_handler.log_data.set("mode", self.handler.get_argument('debug', 'text'))
- self.debug_log_handler.log_data.set("request-id", str(self.handler.request_id))
+ def get_debug_page(self, status_code, response_headers, original_response=None, **kwargs):
+ self.debug_log_handler.log_data.set('code', str(status_code))
+ self.debug_log_handler.log_data.set('mode', self.handler.get_argument('debug', 'text'))
+ self.debug_log_handler.log_data.set('request-id', str(self.handler.request_id))
+ self.debug_log_handler.log_data.append(frontik.app.get_frontik_and_apps_versions())
+ self.debug_log_handler.log_data.append(E.request(
+ _params_to_xml(self.handler.request.uri),
+ _headers_to_xml(self.handler.request.headers),
+ _cookies_to_xml(self.handler.request.headers)))
+ self.debug_log_handler.log_data.append(E.response(_headers_to_xml(response_headers)))
if getattr(self.handler, "_response_size", None) is not None:
self.debug_log_handler.log_data.set("response-size", str(self.handler._response_size))
View
13 frontik/version.py
@@ -1,11 +1,10 @@
+import os
import re
+
try:
- ver_path = __file__.rsplit("/", 2)[0]
- deb_path = ver_path + "/debian/changelog"
- changelog = open(deb_path, "r")
- regmatch = re.match("frontik \((.*)\).*", changelog.readline())
- version = regmatch.groups()[0]
- changelog.close()
+ deb_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'debian/changelog')
+ with open(deb_path, 'r') as changelog:
+ regmatch = re.match(r'frontik \((.*)\).*', changelog.readline())
+ version = regmatch.groups()[0]
except:
version = 'DEVELOPMENT'
-

No commit comments for this range

Something went wrong with that request. Please try again.