Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
626c2a3e
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
626c2a3e
编写于
9月 30, 2020
作者:
A
Alexander Kuzmenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
microsecond precision for start/finish time
上级
222b6555
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
30 deletion
+34
-30
programs/server/config.xml
programs/server/config.xml
+1
-1
src/Interpreters/ClientInfo.cpp
src/Interpreters/ClientInfo.cpp
+4
-2
src/Interpreters/OpenTelemetryLog.cpp
src/Interpreters/OpenTelemetryLog.cpp
+6
-5
src/Interpreters/OpenTelemetryLog.h
src/Interpreters/OpenTelemetryLog.h
+6
-2
src/Interpreters/executeQuery.cpp
src/Interpreters/executeQuery.cpp
+17
-20
未找到文件。
programs/server/config.xml
浏览文件 @
626c2a3e
...
...
@@ -611,7 +611,7 @@
<engine>
engine MergeTree
partition by toYYYYMM(finish_date)
order by (finish_date, finish_time, trace_id)
order by (finish_date, finish_time
_us
, trace_id)
</engine>
<database>
system
</database>
<table>
opentelemetry_log
</table>
...
...
src/Interpreters/ClientInfo.cpp
浏览文件 @
626c2a3e
...
...
@@ -62,11 +62,12 @@ void ClientInfo::write(WriteBuffer & out, const UInt64 server_protocol_revision)
if
(
server_protocol_revision
>=
DBMS_MIN_REVISION_WITH_OPENTELEMETRY
)
{
// No point writing these numbers with variable length, because they
// are random and will probably require the full length anyway.
if
(
opentelemetry_trace_id
)
{
// Have OpenTelemetry header.
writeBinary
(
uint8_t
(
1
),
out
);
// No point writing these numbers with variable length, because they
// are random and will probably require the full length anyway.
writeBinary
(
opentelemetry_trace_id
,
out
);
writeBinary
(
opentelemetry_span_id
,
out
);
writeBinary
(
opentelemetry_parent_span_id
,
out
);
...
...
@@ -75,6 +76,7 @@ void ClientInfo::write(WriteBuffer & out, const UInt64 server_protocol_revision)
}
else
{
// Don't have OpenTelemetry header.
writeBinary
(
uint8_t
(
0
),
out
);
}
}
...
...
src/Interpreters/OpenTelemetryLog.cpp
浏览文件 @
626c2a3e
...
...
@@ -3,6 +3,7 @@
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeUUID.h>
...
...
@@ -17,8 +18,8 @@ Block OpenTelemetrySpanLogElement::createBlock()
{
std
::
make_shared
<
DataTypeUInt64
>
(),
"span_id"
},
{
std
::
make_shared
<
DataTypeUInt64
>
(),
"parent_span_id"
},
{
std
::
make_shared
<
DataTypeString
>
(),
"operation_name"
},
{
std
::
make_shared
<
DataTypeDateTime
>
(),
"start_time
"
},
{
std
::
make_shared
<
DataTypeDateTime
>
(),
"finish_time
"
},
{
std
::
make_shared
<
DataTypeDateTime
64
>
(
6
),
"start_time_us
"
},
{
std
::
make_shared
<
DataTypeDateTime
64
>
(
6
),
"finish_time_us
"
},
{
std
::
make_shared
<
DataTypeDate
>
(),
"finish_date"
},
{
std
::
make_shared
<
DataTypeArray
>
(
std
::
make_shared
<
DataTypeString
>
()),
"attribute.names"
},
...
...
@@ -35,9 +36,9 @@ void OpenTelemetrySpanLogElement::appendToBlock(MutableColumns & columns) const
columns
[
i
++
]
->
insert
(
span_id
);
columns
[
i
++
]
->
insert
(
parent_span_id
);
columns
[
i
++
]
->
insert
(
operation_name
);
columns
[
i
++
]
->
insert
(
start_time
);
columns
[
i
++
]
->
insert
(
finish_time
);
columns
[
i
++
]
->
insert
(
DateLUT
::
instance
().
toDayNum
(
finish_time
));
columns
[
i
++
]
->
insert
(
start_time
_us
);
columns
[
i
++
]
->
insert
(
finish_time
_us
);
columns
[
i
++
]
->
insert
(
DateLUT
::
instance
().
toDayNum
(
finish_time
_us
/
1000000
));
columns
[
i
++
]
->
insert
(
attribute_names
);
columns
[
i
++
]
->
insert
(
attribute_values
);
}
...
...
src/Interpreters/OpenTelemetryLog.h
浏览文件 @
626c2a3e
...
...
@@ -15,6 +15,10 @@ struct OpenTelemetrySpanContext
};
*/
// using TimeMicroseconds = std::chrono::time_point<
// std::chrono::local_t,
// std::chrono::duration<UInt64, std::micro>>;
// TODO figure out precisely which part of this is run time, and which part we
// must log.
struct
OpenTelemetrySpan
...
...
@@ -23,8 +27,8 @@ struct OpenTelemetrySpan
UInt64
span_id
;
UInt64
parent_span_id
;
std
::
string
operation_name
;
time_t
start_time
;
time_t
finish_time
;
UInt64
start_time_us
;
UInt64
finish_time_us
;
UInt64
duration_ns
;
Array
attribute_names
;
Array
attribute_values
;
...
...
src/Interpreters/executeQuery.cpp
浏览文件 @
626c2a3e
...
...
@@ -205,7 +205,7 @@ inline UInt64 time_in_seconds(std::chrono::time_point<std::chrono::system_clock>
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
timepoint
.
time_since_epoch
()).
count
();
}
static
void
onExceptionBeforeStart
(
const
String
&
query_for_logging
,
Context
&
context
,
time_t
current_time
,
UInt64
current_time_microsecond
s
,
ASTPtr
ast
)
static
void
onExceptionBeforeStart
(
const
String
&
query_for_logging
,
Context
&
context
,
UInt64
current_time_u
s
,
ASTPtr
ast
)
{
/// Exception before the query execution.
if
(
auto
quota
=
context
.
getQuota
())
...
...
@@ -221,9 +221,9 @@ static void onExceptionBeforeStart(const String & query_for_logging, Context & c
// all callers to onExceptionBeforeStart upstream construct the timespec for event_time and
// event_time_microseconds from the same timespec. So it can be assumed that both of these
// times are equal upto the precision of a second.
elem
.
event_time
=
current_time
;
elem
.
query_start_time
=
current_time
;
elem
.
query_start_time_microseconds
=
current_time_
microsecond
s
;
elem
.
event_time
=
current_time
_us
/
1000000
;
elem
.
query_start_time
=
current_time
_us
/
1000000
;
elem
.
query_start_time_microseconds
=
current_time_
u
s
;
elem
.
current_database
=
context
.
getCurrentDatabase
();
elem
.
query
=
query_for_logging
;
...
...
@@ -252,8 +252,8 @@ static void onExceptionBeforeStart(const String & query_for_logging, Context & c
span
.
span_id
=
context
.
getClientInfo
().
opentelemetry_span_id
;
span
.
parent_span_id
=
context
.
getClientInfo
().
opentelemetry_parent_span_id
;
span
.
operation_name
=
"query"
;
span
.
start_time
=
current_time
;
span
.
finish_time
=
current_time
;
span
.
start_time
_us
=
current_time_us
;
span
.
finish_time
_us
=
current_time_us
;
span
.
duration_ns
=
0
;
// keep values synchonized to type enum in QueryLogElement::createBlock
...
...
@@ -309,12 +309,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
bool
has_query_tail
,
ReadBuffer
*
istr
)
{
// current_time and current_time_microseconds are both constructed from the same time point
// to ensure that both the times are equal upto the precision of a second.
const
auto
now
=
std
::
chrono
::
system_clock
::
now
();
auto
current_time
=
time_in_seconds
(
now
);
auto
current_time_microseconds
=
time_in_microseconds
(
now
);
const
auto
current_time
=
std
::
chrono
::
system_clock
::
now
();
/// If we already executing query and it requires to execute internal query, than
/// don't replace thread context with given (it can be temporary). Otherwise, attach context to thread.
...
...
@@ -364,7 +359,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
logQuery
(
query_for_logging
,
context
,
internal
);
if
(
!
internal
)
onExceptionBeforeStart
(
query_for_logging
,
context
,
current_time
,
current_time_microseconds
,
ast
);
onExceptionBeforeStart
(
query_for_logging
,
context
,
time_in_microseconds
(
current_time
)
,
ast
);
throw
;
}
...
...
@@ -528,9 +523,9 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
elem
.
type
=
QueryLogElementType
::
QUERY_START
;
elem
.
event_time
=
current_time
;
elem
.
query_start_time
=
current_time
;
elem
.
query_start_time_microseconds
=
current_time_microseconds
;
elem
.
event_time
=
time_in_seconds
(
current_time
)
;
elem
.
query_start_time
=
time_in_seconds
(
current_time
)
;
elem
.
query_start_time_microseconds
=
time_in_microseconds
(
current_time
)
;
elem
.
current_database
=
context
.
getCurrentDatabase
();
elem
.
query
=
query_for_logging
;
...
...
@@ -599,7 +594,9 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
elem
.
type
=
QueryLogElementType
::
QUERY_FINISH
;
elem
.
event_time
=
time
(
nullptr
);
const
auto
current_time
=
std
::
chrono
::
system_clock
::
now
();
elem
.
event_time
=
time_in_seconds
(
current_time
);
status_info_to_query_log
(
elem
,
info
,
ast
);
...
...
@@ -660,8 +657,8 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
span
.
span_id
=
context
.
getClientInfo
().
opentelemetry_span_id
;
span
.
parent_span_id
=
context
.
getClientInfo
().
opentelemetry_parent_span_id
;
span
.
operation_name
=
"query"
;
span
.
start_time
=
elem
.
query_start_time
;
span
.
finish_time
=
elem
.
event_time
;
span
.
start_time
_us
=
elem
.
query_start_time_microseconds
;
span
.
finish_time
_us
=
time_in_microseconds
(
current_time
)
;
span
.
duration_ns
=
elapsed_seconds
*
1000000000
;
// keep values synchonized to type enum in QueryLogElement::createBlock
...
...
@@ -751,7 +748,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
if
(
query_for_logging
.
empty
())
query_for_logging
=
prepareQueryForLogging
(
query
,
context
);
onExceptionBeforeStart
(
query_for_logging
,
context
,
current_time
,
current_time_microseconds
,
ast
);
onExceptionBeforeStart
(
query_for_logging
,
context
,
time_in_microseconds
(
current_time
)
,
ast
);
}
throw
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录