databricks-cli/libs/cmdio
Denis Bilenko 5c146ca57a
Synchronize logging in cmdio ()
## Changes
Add mutex synchronization in cmdio logger Log() method.

## Why

Since we issue multiple calls to underlying writer, we should lock the
whole method, otherwise we can get broken messages. One that can be
easily reproduced today is

```
 hyperfine -m 100 --show-output 'go test ./acceptance -run ^TestAccept$/^bundle$/^artifacts$/^whl_multiple$ -count=1'
...
            -Uploading my_test_code-0.0.1-py3-none-any.whl...
            -Uploading my_test_code_2-0.0.1-py3-none-any.whl...
            +Uploading my_test_code-0.0.1-py3-none-any.whl...Uploading my_test_code_2-0.0.1-py3-none-any.whl...

Error: Command terminated with non-zero exit code 1 in benchmark iteration 54. Use the '-i'/'--ignore-failure' option if you want to ignore this. Alternatively, use the '--show-output' option to debug what went wrong.
```

An alternative could be to prepare a message fully in a local buffer and
write it in one call (I’m assuming underlying writer is still
synchronized). However, that’s more complicated and unclear if it’s
worth it, perf-wise.

## Tests
With this change I’m running the same hyperfine command with 1000
iterations with no failures.
2025-03-03 13:42:43 +00:00
..
context.go Add bundle destroy command () 2023-04-06 12:54:58 +02:00
error_event.go Enable perfsprint linter and apply autofix () 2025-01-07 10:49:23 +00:00
event.go Move state to event for whether they support inplace progress logging () 2023-04-18 14:20:35 +02:00
io.go Refactor `bundle init` () 2025-01-20 12:09:28 +00:00
io_test.go Do not allow input prompts in Git Bash terminal () 2023-12-18 15:01:59 +00:00
logger.go Synchronize logging in cmdio () 2025-03-03 13:42:43 +00:00
logger_test.go Add support for multiline descriptions when using template enums () 2023-10-25 09:37:25 +00:00
message_event.go Log mutator messages using progress logger () 2023-04-18 16:55:06 +02:00
render.go Enable intrange linter and apply autofix () 2025-01-03 09:25:07 +00:00
render_test.go Enable linter 'mirror' and autofix existing issues () 2025-01-03 10:13:12 +00:00
testing.go Prompt once for a client profile () 2023-09-11 15:32:24 +00:00