2016-10-24 21:40:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/Net/SocketAddress.h>
|
2020-08-27 18:44:20 +00:00
|
|
|
#include <Common/UInt128.h>
|
2020-09-15 09:55:57 +00:00
|
|
|
#include <common/types.h>
|
2016-10-24 21:40:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class WriteBuffer;
|
|
|
|
class ReadBuffer;
|
|
|
|
|
|
|
|
|
|
|
|
/** Information about client for query.
|
|
|
|
* Some fields are passed explicitly from client and some are calculated automatically.
|
|
|
|
*
|
|
|
|
* Contains info about initial query source, for tracing distributed queries
|
|
|
|
* (where one query initiates many other queries).
|
|
|
|
*/
|
|
|
|
class ClientInfo
|
|
|
|
{
|
|
|
|
public:
|
2020-01-03 14:44:29 +00:00
|
|
|
enum class Interface : uint8_t
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
TCP = 1,
|
|
|
|
HTTP = 2,
|
|
|
|
};
|
|
|
|
|
2020-01-03 14:44:29 +00:00
|
|
|
enum class HTTPMethod : uint8_t
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
UNKNOWN = 0,
|
|
|
|
GET = 1,
|
|
|
|
POST = 2,
|
|
|
|
};
|
|
|
|
|
2020-01-03 14:44:29 +00:00
|
|
|
enum class QueryKind : uint8_t
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
NO_QUERY = 0, /// Uninitialized object.
|
|
|
|
INITIAL_QUERY = 1,
|
2019-04-12 11:06:05 +00:00
|
|
|
SECONDARY_QUERY = 2, /// Query that was initiated by another query for distributed or ON CLUSTER query execution.
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QueryKind query_kind = QueryKind::NO_QUERY;
|
|
|
|
|
|
|
|
/// Current values are not serialized, because it is passed separately.
|
|
|
|
String current_user;
|
|
|
|
String current_query_id;
|
|
|
|
Poco::Net::SocketAddress current_address;
|
2020-06-15 02:17:08 +00:00
|
|
|
|
2020-07-30 21:55:25 +00:00
|
|
|
#if defined(ARCADIA_BUILD)
|
2020-06-15 02:17:08 +00:00
|
|
|
/// This field is only used in foreign "Arcadia" build.
|
2020-06-15 02:13:41 +00:00
|
|
|
String current_password;
|
2020-07-30 21:55:25 +00:00
|
|
|
#endif
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// When query_kind == INITIAL_QUERY, these values are equal to current.
|
|
|
|
String initial_user;
|
|
|
|
String initial_query_id;
|
|
|
|
Poco::Net::SocketAddress initial_address;
|
2020-08-28 19:02:50 +00:00
|
|
|
|
2020-08-28 01:21:08 +00:00
|
|
|
// OpenTelemetry things
|
|
|
|
__uint128_t opentelemetry_trace_id = 0;
|
|
|
|
// Span ID is not strictly the client info, but convenient to keep here.
|
|
|
|
// The span id we get the in the incoming client info becomes our parent span
|
|
|
|
// id, and the span id we send becomes downstream parent span id.
|
|
|
|
UInt64 opentelemetry_span_id = 0;
|
|
|
|
UInt64 opentelemetry_parent_span_id = 0;
|
|
|
|
// the incoming tracestate header, we just pass it downstream.
|
|
|
|
// https://www.w3.org/TR/trace-context/
|
|
|
|
String opentelemetry_tracestate;
|
2020-09-08 13:19:27 +00:00
|
|
|
UInt8 opentelemetry_trace_flags = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// All below are parameters related to initial query.
|
|
|
|
|
|
|
|
Interface interface = Interface::TCP;
|
|
|
|
|
|
|
|
/// For tcp
|
|
|
|
String os_user;
|
|
|
|
String client_hostname;
|
|
|
|
String client_name;
|
|
|
|
UInt64 client_version_major = 0;
|
|
|
|
UInt64 client_version_minor = 0;
|
2018-07-31 21:36:18 +00:00
|
|
|
UInt64 client_version_patch = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
unsigned client_revision = 0;
|
|
|
|
|
|
|
|
/// For http
|
|
|
|
HTTPMethod http_method = HTTPMethod::UNKNOWN;
|
|
|
|
String http_user_agent;
|
|
|
|
|
|
|
|
/// Common
|
|
|
|
String quota_key;
|
|
|
|
|
|
|
|
bool empty() const { return query_kind == QueryKind::NO_QUERY; }
|
|
|
|
|
|
|
|
/** Serialization and deserialization.
|
|
|
|
* Only values that are not calculated automatically or passed separately are serialized.
|
|
|
|
* Revisions are passed to use format that server will understand or client was used.
|
|
|
|
*/
|
|
|
|
void write(WriteBuffer & out, const UInt64 server_protocol_revision) const;
|
|
|
|
void read(ReadBuffer & in, const UInt64 client_protocol_revision);
|
|
|
|
|
2020-04-15 01:58:10 +00:00
|
|
|
/// Initialize parameters on client initiating query.
|
|
|
|
void setInitialQuery();
|
|
|
|
|
2020-08-28 01:21:08 +00:00
|
|
|
bool setOpenTelemetryTraceparent(const std::string & traceparent, std::string & error);
|
|
|
|
std::string getOpenTelemetryTraceparentForChild() const;
|
|
|
|
|
2020-04-15 01:58:10 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void fillOSUserHostNameAndVersionInfo();
|
2016-10-24 21:40:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|