Show More
@@ -22,6 +22,11 b' The record is a JSON-line file located i' | |||
|
22 | 22 | Log write failures are not considered fatal: log writes may be skipped for any |
|
23 | 23 | reason such as insufficient storage or a timeout. |
|
24 | 24 | |
|
25 | Some basic log file rotation can be enabled by setting 'rotate-size' to a value | |
|
26 | greater than 0. This causes the current log file to be moved to | |
|
27 | .hg/pull_log.jsonl.rotated when this threshold is met, discarding any | |
|
28 | previously rotated log file. | |
|
29 | ||
|
25 | 30 | The timeouts of the exclusive lock used when writing to the lock file can be |
|
26 | 31 | configured through the 'timeout.lock' and 'timeout.warn' options of this |
|
27 | 32 | plugin. Those are not expected to be held for a significant time in practice.:: |
@@ -29,8 +34,7 b' plugin. Those are not expected to be hel' | |||
|
29 | 34 | [pull-logger] |
|
30 | 35 | timeout.lock = 300 |
|
31 | 36 | timeout.warn = 100 |
|
32 | ||
|
33 | Note: there is no automatic log rotation and the size of the log is not capped. | |
|
37 | rotate-size = 1kb | |
|
34 | 38 | ''' |
|
35 | 39 | |
|
36 | 40 | |
@@ -51,12 +55,14 b" EXT_NAME = b'pull-logger'" | |||
|
51 | 55 | EXT_VERSION_CODE = 0 |
|
52 | 56 | |
|
53 | 57 | LOG_FILE = b'pull_log.jsonl' |
|
58 | OLD_LOG_FILE = LOG_FILE + b'.rotated' | |
|
54 | 59 | LOCK_NAME = LOG_FILE + b'.lock' |
|
55 | 60 | |
|
56 | 61 | configtable = {} |
|
57 | 62 | configitem = registrar.configitem(configtable) |
|
58 | 63 | configitem(EXT_NAME, b'timeout.lock', default=600) |
|
59 | 64 | configitem(EXT_NAME, b'timeout.warn', default=120) |
|
65 | configitem(EXT_NAME, b'rotate-size', default=b'100MB') | |
|
60 | 66 | |
|
61 | 67 | |
|
62 | 68 | def wrap_getbundle(orig, repo, proto, others, *args, **kwargs): |
@@ -92,6 +98,7 b' def extract_pull_heads(bundle_args):' | |||
|
92 | 98 | def write_to_log(repo, entry): |
|
93 | 99 | locktimeout = repo.ui.configint(EXT_NAME, b'timeout.lock') |
|
94 | 100 | lockwarntimeout = repo.ui.configint(EXT_NAME, b'timeout.warn') |
|
101 | rotatesize = repo.ui.configbytes(EXT_NAME, b'rotate-size') | |
|
95 | 102 | |
|
96 | 103 | with lock.trylock( |
|
97 | 104 | ui=repo.ui, |
@@ -100,6 +107,10 b' def write_to_log(repo, entry):' | |||
|
100 | 107 | timeout=locktimeout, |
|
101 | 108 | warntimeout=lockwarntimeout, |
|
102 | 109 | ): |
|
110 | if rotatesize > 0 and repo.vfs.exists(LOG_FILE): | |
|
111 | if repo.vfs.stat(LOG_FILE).st_size >= rotatesize: | |
|
112 | repo.vfs.rename(LOG_FILE, OLD_LOG_FILE) | |
|
113 | ||
|
103 | 114 | with repo.vfs.open(LOG_FILE, b'a+') as logfile: |
|
104 | 115 | serialised = json.dumps(entry, sort_keys=True) |
|
105 | 116 | logfile.write(serialised.encode('utf-8')) |
@@ -110,6 +121,7 b' def write_to_log(repo, entry):' | |||
|
110 | 121 | def reposetup(ui, repo): |
|
111 | 122 | if repo.local(): |
|
112 | 123 | repo._wlockfreeprefix.add(LOG_FILE) |
|
124 | repo._wlockfreeprefix.add(OLD_LOG_FILE) | |
|
113 | 125 | |
|
114 | 126 | |
|
115 | 127 | def uisetup(ui): |
@@ -59,3 +59,20 b' clients at the same time' | |||
|
59 | 59 | $ wait |
|
60 | 60 | $ wc -l server/.hg/pull_log.jsonl |
|
61 | 61 | \s*64 .* (re) |
|
62 | ||
|
63 | ||
|
64 | Test log rotation when reaching some size threshold | |
|
65 | ||
|
66 | $ cat >> $HGRCPATH << EOF | |
|
67 | > [pull-logger] | |
|
68 | > rotate-size = 1kb | |
|
69 | > EOF | |
|
70 | ||
|
71 | $ rm -f server/.hg/pull_log.jsonl | |
|
72 | $ for i in $($TESTDIR/seq.py 10); do | |
|
73 | > hg -R client pull --rev 1 | |
|
74 | > done > /dev/null | |
|
75 | $ wc -l server/.hg/pull_log.jsonl | |
|
76 | \s*3 .* (re) | |
|
77 | $ wc -l server/.hg/pull_log.jsonl.rotated | |
|
78 | \s*7 .* (re) |
General Comments 0
You need to be logged in to leave comments.
Login now