Changeset 507:396ca91c04a9
- Timestamp:
- 10/15/08 12:35:49
(3 months ago)
- Author:
- Brian Warner <warner@allmydata.com>
- branch:
- default
- Message:
flogtool classify-incident: add --verbose, to show the trigger event for unclassifable incidents, helpful when developing classification functions
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r506 |
r507 |
|
| 1 | 1 | 2008-10-15 Brian Warner <warner@allmydata.com> |
|---|
| | 2 | |
|---|
| | 3 | * foolscap/logging/incident.py (IncidentClassifier): add --verbose |
|---|
| | 4 | option to 'flogtool classify-incident' to show the trigger |
|---|
| | 5 | dictionary for any unclassifiable incidents. This is useful when |
|---|
| | 6 | developing classification functions. |
|---|
| | 7 | * foolscap/test/test_logging.py (Incidents.test_classify): test it |
|---|
| 2 | 8 | |
|---|
| 3 | 9 | * Makefile (test-figleaf): oops, fix the test-figleaf-poll target, |
|---|
| r499 |
r507 |
|
| 1 | 1 | |
|---|
| 2 | 2 | import sys, os.path, time, pickle, bz2 |
|---|
| | 3 | from pprint import pprint |
|---|
| 3 | 4 | from zope.interface import implements |
|---|
| 4 | 5 | from twisted.python import usage |
|---|
| … | … | |
| 174 | 175 | synopsis = "Usage: flogtool classify-incident [options] INCIDENTFILE.." |
|---|
| 175 | 176 | |
|---|
| | 177 | optFlags = [ |
|---|
| | 178 | ("verbose", "v", "show trigger details for unclassifiable incidents"), |
|---|
| | 179 | ] |
|---|
| 176 | 180 | optParameters = [ |
|---|
| 177 | 181 | ("classifier-directory", "c", ".", |
|---|
| … | … | |
| 239 | 243 | categories = self.classify_incident(incident) |
|---|
| 240 | 244 | print >>out, "%s: %s" % (f, ",".join(sorted(categories))) |
|---|
| 241 | | |
|---|
| | 245 | if list(categories) == ["unknown"] and options["verbose"]: |
|---|
| | 246 | (header, events) = incident |
|---|
| | 247 | trigger = header["trigger"] |
|---|
| | 248 | from foolscap.logging.log import format_message |
|---|
| | 249 | print >>out, format_message(trigger) |
|---|
| | 250 | pprint(trigger, stream=out) |
|---|
| | 251 | if 'failure' in trigger: |
|---|
| | 252 | print >>out," FAILURE:" |
|---|
| | 253 | lines = str(trigger['failure']).split("\n") |
|---|
| | 254 | for line in lines: |
|---|
| | 255 | print >>out, " %s" % (line,) |
|---|
| | 256 | print >>out, "" |
|---|
| | 257 | |
|---|
| r495 |
r507 |
|
| 357 | 357 | l.setLogDir("logging/Incidents/classify") |
|---|
| 358 | 358 | got_logdir = l.logdir |
|---|
| 359 | | l.msg("foom", level=log.BAD) |
|---|
| | 359 | l.msg("foom", level=log.BAD, failure=failure.Failure(RuntimeError())) |
|---|
| 360 | 360 | d = fireEventually() |
|---|
| 361 | 361 | def _check(res): |
|---|
| … | … | |
| 374 | 374 | out = options.stdout.getvalue() |
|---|
| 375 | 375 | self.failUnless(out.strip().endswith(": foom"), out) |
|---|
| | 376 | |
|---|
| | 377 | ic2 = incident.IncidentClassifier() |
|---|
| | 378 | options = incident.ClassifyOptions() |
|---|
| | 379 | options.parseOptions(["--verbose"] + |
|---|
| | 380 | [os.path.join(got_logdir, fn) for fn in files]) |
|---|
| | 381 | options.stdout = StringIO() |
|---|
| | 382 | ic2.run(options) |
|---|
| | 383 | out = options.stdout.getvalue() |
|---|
| | 384 | self.failUnless(".flog.bz2: unknown\n" in out, out) |
|---|
| | 385 | # this should have a pprinted trigger dictionary |
|---|
| | 386 | self.failUnless("'message': 'foom'," in out, out) |
|---|
| | 387 | self.failUnless("'num': 0," in out, out) |
|---|
| | 388 | self.failUnless("RuntimeError" in out, out) |
|---|
| | 389 | |
|---|
| 376 | 390 | d.addCallback(_check) |
|---|
| 377 | 391 | return d |
|---|