MCPcopy
hub / github.com/benoitc/gunicorn / test_instrument

Function test_instrument

tests/test_statsd.py:89–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87
88
89def test_instrument():
90 logger = Statsd(Config())
91 # Capture logged messages
92 sio = io.StringIO()
93 logger.error_log.addHandler(logging.StreamHandler(sio))
94 logger.sock = MockSocket(False)
95
96 # Regular message
97 logger.info("Blah", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
98 assert logger.sock.msgs[0] == b"gunicorn.test:666|g"
99 assert sio.getvalue() == "Blah\n"
100 logger.sock.reset()
101
102 # Only metrics, no logging
103 logger.info("", extra={"mtype": "gauge", "metric": "gunicorn.test", "value": 666})
104 assert logger.sock.msgs[0] == b"gunicorn.test:666|g"
105 assert sio.getvalue() == "Blah\n" # log is unchanged
106 logger.sock.reset()
107
108 # Debug logging also supports metrics
109 logger.debug("", extra={"mtype": "gauge", "metric": "gunicorn.debug", "value": 667})
110 assert logger.sock.msgs[0] == b"gunicorn.debug:667|g"
111 assert sio.getvalue() == "Blah\n" # log is unchanged
112 logger.sock.reset()
113
114 logger.critical("Boom")
115 assert logger.sock.msgs[0] == b"gunicorn.log.critical:1|c|@1.0"
116 logger.sock.reset()
117
118 logger.access(SimpleNamespace(status="200 OK"), None, {}, timedelta(seconds=7))
119 assert logger.sock.msgs[0] == b"gunicorn.request.duration:7000.0|ms"
120 assert logger.sock.msgs[1] == b"gunicorn.requests:1|c|@1.0"
121 assert logger.sock.msgs[2] == b"gunicorn.request.status.200:1|c|@1.0"
122
123
124def test_prefix():

Callers

nothing calls this directly

Calls 8

infoMethod · 0.95
debugMethod · 0.95
criticalMethod · 0.95
accessMethod · 0.95
StatsdClass · 0.90
ConfigClass · 0.90
MockSocketClass · 0.70
resetMethod · 0.45

Tested by

no test coverage detected