-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server timestamps in logs received from server #434
base: master
Are you sure you want to change the base?
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@korowa I guess it is not a draft anymore?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
flake8
and fix issues.pytest
no 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_level
setting 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).