Skip to content

Add tid and logTrace function#15803

Merged
alexey-milovidov merged 5 commits intoClickHouse:masterfrom
ucasfl:tid-function
Oct 10, 2020
Merged

Add tid and logTrace function#15803
alexey-milovidov merged 5 commits intoClickHouse:masterfrom
ucasfl:tid-function

Conversation

@ucasfl
Copy link
Copy Markdown
Collaborator

@ucasfl ucasfl commented Oct 10, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add tid and logTrace function. This closes #9434.

Detailed description / Documentation draft:

...

By adding documentation, you'll allow users to try your new feature immediately, not when someone else will have time to document it later. Documentation is necessary for all features that affect user experience in any way. You can add brief documentation draft above, or add documentation right into your patch as Markdown files in docs folder.

If you are doing this for the first time, it's recommended to read the lightweight Contributing to ClickHouse Documentation guide first.

Information about CI checks: https://clickhouse.tech/docs/en/development/continuous-integration/

@robot-clickhouse robot-clickhouse added doc-alert pr-feature Pull request with new product feature labels Oct 10, 2020
@alexey-milovidov alexey-milovidov self-assigned this Oct 10, 2020
@@ -0,0 +1 @@
SELECT logTrace('message')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to test: we can do SYSTEM FLUSH LOGS and find this message in system.text_log.


void executeImpl(Block & block, const ColumnNumbers &, size_t result, size_t) const override
{
UInt64 current_tid = std::hash<std::thread::id>{}(std::this_thread::get_id());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean base/common/getThreadId.h - it returns OS thread id similar to pid.

{
UInt64 current_tid = std::hash<std::thread::id>{}(std::this_thread::get_id());

block.getByPosition(result).column = DataTypeUInt64().createColumnConst(1, current_tid);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it shouldn't be of size 1... It should be of size input_rows_count.

static auto * log = &Poco::Logger::get("logTrace");
LOG_TRACE(log, message);

block.getByPosition(result).column = DataTypeUInt8().createColumnConst(1, 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it shouldn't have size 1.

throw Exception(
"First argument for function " + getName() + " must be Constant string", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);

static auto * log = &Poco::Logger::get("logTrace");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name logger "FunctionLogTrace", so the users will know that the message is emitted from here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Also you can just set CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL before loading shell_config.

fix

fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add logTrace and tid function.

3 participants