Skip to content

Commit 0a3945a

Browse files
committed
Print status to migration context logging after escaping % character
The string `status` has the character `%` after the progress percentage number. When printed once again using the `Infof` function, this `%` is read as a directive for formatting and ends up showing `MISSING` in the output as shown below: 2024-01-31 12:49:54 INFO Copy: 0/0 100.0%!;(MISSING) Applied: 0; Backlog: 0/1000; Time: 0s(total), 0s(copy); streamer: mysql_bin.000002:79674; Lag: 0.00s, HeartbeatLag: 0.02s, State: migrating; ETA: due Simply changing `Infof` to `Info` does not work here because `this.migrationContext.Log` is an object of the type `DefaultLogger` in this repository, which uses the library https://github.com/outbrain/golib/log. That library uses formatting __even__ when the `Info`function is called: https://github.com/outbrain/golib/blob/2531e5dbcc71b6f8a4ccf1205c209ae89b7529fc/log/log.go#L191-L193 If this patch is not acceptible, then I can also just remove this line. The migration context logger prints the messages which are already printed to STDOUT once again to STDERR with the current time as a prefix. This change was introduced in the commit https://github.com/github/gh-ost/blob/515aa72d3d9b756e454b0168b4e57bc599b45e36/go/logic/migrator.go#L1039, introduced in the PR github#1194.
1 parent 11d66d8 commit 0a3945a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

go/logic/migrator.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,14 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
10421042
)
10431043
w := io.MultiWriter(writers...)
10441044
fmt.Fprintln(w, status)
1045-
this.migrationContext.Log.Infof(status)
1045+
1046+
// This "hack" is required here because the underlying logging library
1047+
// github.com/outbrain/golib/log provides two functions Info and Infof; but the arguments of
1048+
// both these functions are eventually redirected to the same function, which internally calls
1049+
// fmt.Sprintf. So, the argument of every function called on the DefaultLogger object
1050+
// migrationContext.Log will eventually pass through fmt.Sprintf, and thus the '%' character
1051+
// needs to be escaped.
1052+
this.migrationContext.Log.Info(strings.Replace(status, "%", "%%", 1))
10461053

10471054
hooksStatusIntervalSec := this.migrationContext.HooksStatusIntervalSec
10481055
if hooksStatusIntervalSec > 0 && elapsedSeconds%hooksStatusIntervalSec == 0 {

0 commit comments

Comments
 (0)