1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//! [`default_view_factory`] makes the default [`ViewFactory`], giving users access to view instances, grouped in sets.
//!
//! # View sets
//!
//! A ViewFactory defines the available view sets and can instanciate view instances.
//! All view instances in a set have the same schema.
//! Some view instances are global (their view_instance_id is 'global').
//! Global view instances are implicitly accessible to SQL queries.
//! Non-global view instances are accessible using the table function `view_instance`. See [ViewInstanceTableFunction](super::view_instance_table_function::ViewInstanceTableFunction).
//!
//! ## log_entries
//!
//! | field | type | description |
//! |------------- |-----------------------------|-----------------------------------------------------------|
//! |process_id |Utf8 | unique id of the process, references the processes table |
//! |exe |Utf8 | filename of the process |
//! |username |Utf8 | username of the process |
//! |computer |Utf8 | computer name of the process |
//! |time |UTC Timestamp (nanoseconds) | time of the log entry event |
//! |target |Utf8 | category or module name of the log entry |
//! |level |int32 | verbosity level (Fatal=1, Error=2, Warning=3, Info=4, Debug=5, Trace=6)| |
//! |msg |Utf8 | message |
//!
//! ### log_entries view instances
//!
//! The implicit use of the `log_entries` table corresponds to the 'global' instance, which contains the log entries of all the processes.
//!
//! Except the 'global' instance, the instance_id refers to any process_id. `view_instance('log_entries', process_id)` contains that process's log. Process-specific views are materialized just-in-time and can provide much better query performance compared to the 'global' instance.
//!
//! ## measures
//!
//! | field | type | description |
//! |------------- |-----------------------------|-----------------------------------------------------------|
//! |process_id |Utf8 | unique id of the process, references the processes table |
//! |exe |Utf8 | filename of the process |
//! |username |Utf8 | username of the process |
//! |computer |Utf8 | computer name of the process |
//! |time |UTC Timestamp (nanoseconds) | time of the measure event |
//! |target |Utf8 | category or module name of the measure |
//! |name |Utf8 | name of the measure |
//! |unit |Utf8 | unit of measure |
//! |value |Float64 | value measured |
//!
//!
//! ### measures view instances
//!
//! The implicit use of the `measures` table corresponds to the 'global' instance, which contains the metrics of all the processes.
//!
//! Except the 'global' instance, the instance_id refers to any process_id. `view_instance('measures', process_id)` contains that process's metrics. Process-specific views are materialized just-in-time and can provide much better query performance compared to the 'global' instance.
//!
//! ## thread_spans
//!
//! | field | type | description |
//! |------------- |-----------------------------|------------------------------------------------------------|
//! |id |Int64 | span id, unique within this thread |
//! |parent |Int64 | span id of the calling span |
//! |depth |UInt32 | call stack depth |
//! |hash |UInt32 | identifies a call site (name, filename, line) |
//! |begin |UTC Timestamp (nanoseconds) | when the span started its execution |
//! |end |UTC Timestamp (nanoseconds) | when the span finished its execution |
//! |duration |Int64 (nanoseconds) | end-begin |
//! |name |Utf8 | name of the span, usually a function name |
//! |target |Utf8 | category or module name |
//! |filename |Utf8 | name or path of the source file where the span is coded |
//! |line |UInt32 | line number in the file where the span can be found |
//!
//! ### thread_spans view instances
//!
//! There is no 'global' instance in the 'thread_spans' view set, there is therefore no implicit thread_spans table availble.
//! Users can call the table function `view_instance('thread_spans', stream_id)` to query the spans in the thread associated with the specified stream_id.
//!
//! ## async_events
//!
//! | field | type | description |
//! |------------- |-----------------------------|-----------------------------------------------------------|
//! |stream_id |Dictionary(Int16, Utf8) | identifier of the thread stream that emitted the event |
//! |block_id |Dictionary(Int16, Utf8) | unique identifier of the event block |
//! |time |UTC Timestamp (nanoseconds) | time when the async event occurred |
//! |event_type |Dictionary(Int16, Utf8) | type of event: "begin" or "end" |
//! |span_id |Int64 | unique async span identifier |
//! |parent_span_id|Int64 | span id of the parent async span |
//! |name |Dictionary(Int16, Utf8) | name of the async span, usually a function name |
//! |filename |Dictionary(Int16, Utf8) | name or path of the source file where the span is coded |
//! |target |Dictionary(Int16, Utf8) | category or module name |
//! |line |UInt32 | line number in the file where the span can be found |
//!
//! ### async_events view instances
//!
//! There is no 'global' instance in the 'async_events' view set, there is therefore no implicit async_events table available.
//! Users can call the table function `view_instance('async_events', process_id)` to query the async events in all thread streams associated with the specified process_id.
//! Process-specific views are materialized just-in-time and can provide good query performance.
//!
//! The schema is optimized for high-frequency data. Process information (exe, username, computer, etc.) can be joined when needed:
//! ```sql
//! SELECT ae.*, p.exe, p.username, p.computer
//! FROM view_instance('async_events', process_id) ae
//! JOIN streams s ON ae.stream_id = s.stream_id
//! JOIN processes p ON s.process_id = p.process_id
//! ```
//!
//! ## processes
//!
//! | field | type | description |
//! |------------- |-----------------------------|------------------------------------------------------------|
//! |process_id |Utf8 | process unique id |
//! |exe |Utf8 | filename of the process |
//! |username |Utf8 | username of the process |
//! |realname |Utf8 | real name of the user launching the process |
//! |computer |Utf8 | name of the computer or vm |
//! |distro |Utf8 | name of operating system |
//! |cpu_brand |Utf8 | identifies the cpu |
//! |tsc frequency |Int64 | number of ticks per second |
//! |start_time |UTC Timestamp (nanoseconds) | when the process started (as reported by the instrumented process) |
//! |start_ticks |Int64 | tick count associated with start_time |
//! |insert_time |UTC Timestamp (nanoseconds) | server-side timestamp when the process metedata was received |
//! |parent_process_id |Utf8 | unique id of the parent process |
//! |properties | Array of {key: utf8, value: utf8} | self-reported metadata by the process |
//!
//! There is only one instance in this view set and it is implicitly available.
//!
//! ## streams
//!
//! | field | type | description |
//! |------------- |-----------------------------|------------------------------------------------------------|
//! |stream_id |Utf8 | stream unique id |
//! |process_id |Utf8 | process unique id |
//! |dependencies_metadata|Binary | memory layout of the event dependencies |
//! |objects_metadata|Binary | memory layout of the events |
//! |tags | Array of utf8 | Purpose of the stream, can contain "log", "metrics" or "cpu" |
//! |properties | Array of {key: utf8, value: utf8} | self-reported stream metadata by the process |
//! |insert_time |UTC Timestamp (nanoseconds) | server-side timestamp when the stream metedata was received |
//!
//! There is only one instance in this view set and it is implicitly available.
//!
//! ## blocks
//!
//! | field | type | description |
//! |------------- |-----------------------------|------------------------------------------------------------|
//! |block_id |Utf8 | block unique id |
//! |stream_id |Utf8 | stream unique id |
//! |process_id |Utf8 | process unique id |
//! |begin_time |UTC Timestamp (nanoseconds) | system time marking the beginning of this event batch |
//! |begin_ticks |Int64 | tick count associated with begin_time |
//! |end_time |UTC Timestamp (nanoseconds) | system time marking the ending of this event batch |
//! |end_ticks |Int64 | tick count associated with end_time |
//! |nb_objects |Int32 | number of events in this batch |
//! |object_offset |Int64 | number of events preceding this batch |
//! |payload_size |Int64 | number of bytes of the binary payload |
//! |insert_time |UTC Timestamp (nanoseconds) | server-side timestamp when the block was received |
//! |streams.dependencies_metadata|Binary | memory layout of the event dependencies |
//! |streams.objects_metadata|Binary | memory layout of the events |
//! |streams.tags | Array of utf8 | Purpose of the stream, can contain "log", "metrics" or "cpu" |
//! |streams.properties | Array of {key: utf8, value: utf8} | self-reported stream metadata by the process |
//! |processes.start_time |UTC Timestamp (nanoseconds) | when the process started (as reported by the instrumented process) |
//! |processes.start_ticks |Int64 | tick count associated with start_time |
//! |processes.tsc frequency |Int64 | number of ticks per second |
//! |processes.exe |Utf8 | filename of the process |
//! |processes.username |Utf8 | username of the process |
//! |processes.realname |Utf8 | real name of the user launching the process |
//! |processes.computer |Utf8 | name of the computer or vm |
//! |processes.distro |Utf8 | name of operating system |
//! |processes.cpu_brand |Utf8 | identifies the cpu |
//!
//! There is only one instance in this view set and it is implicitly available.
//!
//!
//!
use BlocksView;
use make_log_stats_view;
use make_processes_view;
use make_streams_view;
use ;
use Result;
use Schema;
use RuntimeEnv;
use DataLakeConnection;
use Debug;
use ;
/// A trait for creating views.
/// A factory for creating and managing views.
/// Creates the default `ViewFactory` with all built-in views.
pub async