Show More
@@ -22,6 +22,11 b' The record is a JSON-line file located i' | |||||
22 | Log write failures are not considered fatal: log writes may be skipped for any |
|
22 | Log write failures are not considered fatal: log writes may be skipped for any | |
23 | reason such as insufficient storage or a timeout. |
|
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 | The timeouts of the exclusive lock used when writing to the lock file can be |
|
30 | The timeouts of the exclusive lock used when writing to the lock file can be | |
26 | configured through the 'timeout.lock' and 'timeout.warn' options of this |
|
31 | configured through the 'timeout.lock' and 'timeout.warn' options of this | |
27 | plugin. Those are not expected to be held for a significant time in practice.:: |
|
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 | [pull-logger] |
|
34 | [pull-logger] | |
30 | timeout.lock = 300 |
|
35 | timeout.lock = 300 | |
31 | timeout.warn = 100 |
|
36 | timeout.warn = 100 | |
32 |
|
37 | rotate-size = 1kb | ||
33 | Note: there is no automatic log rotation and the size of the log is not capped. |
|
|||
34 | ''' |
|
38 | ''' | |
35 |
|
39 | |||
36 |
|
40 | |||
@@ -51,12 +55,14 b" EXT_NAME = b'pull-logger'" | |||||
51 | EXT_VERSION_CODE = 0 |
|
55 | EXT_VERSION_CODE = 0 | |
52 |
|
56 | |||
53 | LOG_FILE = b'pull_log.jsonl' |
|
57 | LOG_FILE = b'pull_log.jsonl' | |
|
58 | OLD_LOG_FILE = LOG_FILE + b'.rotated' | |||
54 | LOCK_NAME = LOG_FILE + b'.lock' |
|
59 | LOCK_NAME = LOG_FILE + b'.lock' | |
55 |
|
60 | |||
56 | configtable = {} |
|
61 | configtable = {} | |
57 | configitem = registrar.configitem(configtable) |
|
62 | configitem = registrar.configitem(configtable) | |
58 | configitem(EXT_NAME, b'timeout.lock', default=600) |
|
63 | configitem(EXT_NAME, b'timeout.lock', default=600) | |
59 | configitem(EXT_NAME, b'timeout.warn', default=120) |
|
64 | configitem(EXT_NAME, b'timeout.warn', default=120) | |
|
65 | configitem(EXT_NAME, b'rotate-size', default=b'100MB') | |||
60 |
|
66 | |||
61 |
|
67 | |||
62 | def wrap_getbundle(orig, repo, proto, others, *args, **kwargs): |
|
68 | def wrap_getbundle(orig, repo, proto, others, *args, **kwargs): | |
@@ -92,6 +98,7 b' def extract_pull_heads(bundle_args):' | |||||
92 | def write_to_log(repo, entry): |
|
98 | def write_to_log(repo, entry): | |
93 | locktimeout = repo.ui.configint(EXT_NAME, b'timeout.lock') |
|
99 | locktimeout = repo.ui.configint(EXT_NAME, b'timeout.lock') | |
94 | lockwarntimeout = repo.ui.configint(EXT_NAME, b'timeout.warn') |
|
100 | lockwarntimeout = repo.ui.configint(EXT_NAME, b'timeout.warn') | |
|
101 | rotatesize = repo.ui.configbytes(EXT_NAME, b'rotate-size') | |||
95 |
|
102 | |||
96 | with lock.trylock( |
|
103 | with lock.trylock( | |
97 | ui=repo.ui, |
|
104 | ui=repo.ui, | |
@@ -100,6 +107,10 b' def write_to_log(repo, entry):' | |||||
100 | timeout=locktimeout, |
|
107 | timeout=locktimeout, | |
101 | warntimeout=lockwarntimeout, |
|
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 | with repo.vfs.open(LOG_FILE, b'a+') as logfile: |
|
114 | with repo.vfs.open(LOG_FILE, b'a+') as logfile: | |
104 | serialised = json.dumps(entry, sort_keys=True) |
|
115 | serialised = json.dumps(entry, sort_keys=True) | |
105 | logfile.write(serialised.encode('utf-8')) |
|
116 | logfile.write(serialised.encode('utf-8')) | |
@@ -110,6 +121,7 b' def write_to_log(repo, entry):' | |||||
110 | def reposetup(ui, repo): |
|
121 | def reposetup(ui, repo): | |
111 | if repo.local(): |
|
122 | if repo.local(): | |
112 | repo._wlockfreeprefix.add(LOG_FILE) |
|
123 | repo._wlockfreeprefix.add(LOG_FILE) | |
|
124 | repo._wlockfreeprefix.add(OLD_LOG_FILE) | |||
113 |
|
125 | |||
114 |
|
126 | |||
115 | def uisetup(ui): |
|
127 | def uisetup(ui): |
@@ -59,3 +59,20 b' clients at the same time' | |||||
59 | $ wait |
|
59 | $ wait | |
60 | $ wc -l server/.hg/pull_log.jsonl |
|
60 | $ wc -l server/.hg/pull_log.jsonl | |
61 | \s*64 .* (re) |
|
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