server timestamps in logs received from server#434
server timestamps in logs received from server#434korowa wants to merge 1 commit intomymarilyn:masterfrom
Conversation
f94628d to
3f539cd
Compare
71b0109 to
af09da7
Compare
|
@xzkostyan could you please take a look when you have time? |
|
Replacing client datetime with server datetime breaks user experience. Example: I'm digging into some application issue and grep-ing logs by date/datetime. If server has significant time drift from client there will be no logs in grep output in application logs. I'd suggest to add another timestamp into log for server timestamp. Result format will be: logger.info(
'[ %s ] [ %s ] [ %s ] {%s} <%s> %s: %s',
row['server_timestamp'],
row['host_name'],
thread_id,
row['query_id'],
priority,
row['source'],
row['text']
row['text']
)Result log will be What do you think? |
a332f0f to
e83c2da
Compare
clickhouse_driver/log.py
Outdated
| row['thread_id'] = row.get('thread_id') or row['thread_number'] | ||
|
|
||
| # put log block row into LogRecord extra | ||
| extra = {"server"+k: v for k, v in row.items()} |
There was a problem hiding this comment.
Maybe this will be better?
| extra = {"server"+k: v for k, v in row.items()} | |
| extra = {"clickhouse"+k: v for k, v in row.items()} |
Also I don't see how does _ added here, can you clarify?
There was a problem hiding this comment.
It wasn't -- all test failres has been caused by this.
Regarding attribute prefix -- "server" simply is shorter and doesn't conflict with any of LogRecord attributes, so it seemed to be sufficient, but I don't have any string preferences here.
be19911 to
bb16df5
Compare
bb16df5 to
2a17ea5
Compare
|
@xzkostyan I've added server timestamp to the log message as a default behaviour. In addition, now there is an ability to disable this concatenation, and set log format, using any of ClickHouse log row attributes, which are passed as |
| return True | ||
|
|
||
|
|
||
| def configure_logger(raw_log_record=False): |
There was a problem hiding this comment.
BTW defaults can be error prone, and in this particular case it could be avoided, the function is not very common. So, I would rather remove the default here
Checklist:
flake8and fix issues.pytestno tests failed. See https://clickhouse-driver.readthedocs.io/en/latest/development.html.Context:
For certain types of queries (e.g. backup/restore operations) ClickHouse server might trigger sending logs to the client with significant delay. In such cases, if client has
send_logs_levelsetting enabled, it might be helpful (or less confusing) to also have server event timestamp on client side.This PR adds server timestamp to log messages by default, and also adds an ability to disable log attributes concatenation to a single string message (which may be helpful in case of structured logging, to avoid parsing the string back to original attributes).