2016-10-24 21:40:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-08 00:09:15 +00:00
|
|
|
#include <Core/UUID.h>
|
2016-10-24 21:40:39 +00:00
|
|
|
#include <Poco/Net/SocketAddress.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2020-11-18 17:43:18 +00:00
|
|
|
#include <Common/OpenTelemetryTraceContext.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-09-21 22:12:55 +00:00
|
|
|
GRPC = 3,
|
2020-11-26 08:28:25 +00:00
|
|
|
MYSQL = 4,
|
|
|
|
POSTGRESQL = 5,
|
2021-08-18 13:50:15 +00:00
|
|
|
LOCAL = 6,
|
|
|
|
TCP_INTERSERVER = 7,
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
2020-01-03 14:44:29 +00:00
|
|
|
enum class HTTPMethod : uint8_t
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
UNKNOWN = 0,
|
2021-09-18 09:36:02 +00:00
|
|
|
GET = 1,
|
|
|
|
POST = 2,
|
|
|
|
OPTIONS = 3
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
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;
|
2021-05-20 13:21:42 +00:00
|
|
|
time_t initial_query_start_time{};
|
|
|
|
Decimal64 initial_query_start_time_microseconds{};
|
2020-08-28 19:02:50 +00:00
|
|
|
|
2022-08-24 08:41:40 +00:00
|
|
|
/// OpenTelemetry trace context we received from client, or which we are going to send to server.
|
2022-08-25 12:20:13 +00:00
|
|
|
OpenTelemetry::TracingContext client_trace_context;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// All below are parameters related to initial query.
|
|
|
|
|
|
|
|
Interface interface = Interface::TCP;
|
2022-03-28 06:31:10 +00:00
|
|
|
bool is_secure = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// 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;
|
2020-09-17 12:15:05 +00:00
|
|
|
unsigned client_tcp_protocol_version = 0;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-10-04 14:27:44 +00:00
|
|
|
/// In case of distributed query, client info for query is actually a client info of client.
|
|
|
|
/// In order to get a version of server-initiator, use connection_ values.
|
|
|
|
/// Also for tcp only.
|
|
|
|
UInt64 connection_client_version_major = 0;
|
|
|
|
UInt64 connection_client_version_minor = 0;
|
|
|
|
UInt64 connection_client_version_patch = 0;
|
|
|
|
unsigned connection_tcp_protocol_version = 0;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// For http
|
|
|
|
HTTPMethod http_method = HTTPMethod::UNKNOWN;
|
|
|
|
String http_user_agent;
|
2021-01-21 22:55:45 +00:00
|
|
|
String http_referer;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2022-04-27 10:28:09 +00:00
|
|
|
/// For mysql and postgresql
|
2021-03-02 10:53:06 +00:00
|
|
|
UInt64 connection_id = 0;
|
|
|
|
|
2020-12-01 21:07:20 +00:00
|
|
|
/// Comma separated list of forwarded IP addresses (from X-Forwarded-For for HTTP interface).
|
|
|
|
/// It's expected that proxy appends the forwarded address to the end of the list.
|
|
|
|
/// The element can be trusted only if you trust the corresponding proxy.
|
|
|
|
/// NOTE This field can also be reused in future for TCP interface with PROXY v1/v2 protocols.
|
|
|
|
String forwarded_for;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Common
|
|
|
|
String quota_key;
|
|
|
|
|
2021-03-20 12:10:22 +00:00
|
|
|
UInt64 distributed_depth = 0;
|
|
|
|
|
2021-07-30 16:34:18 +00:00
|
|
|
bool is_replicated_database_internal = false;
|
|
|
|
|
2021-12-09 10:39:28 +00:00
|
|
|
/// For parallel processing on replicas
|
|
|
|
bool collaborate_with_initiator{false};
|
|
|
|
UInt64 count_participating_replicas{0};
|
|
|
|
UInt64 number_of_current_replica{0};
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
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.
|
|
|
|
*/
|
2022-03-13 11:59:20 +00:00
|
|
|
void write(WriteBuffer & out, UInt64 server_protocol_revision) const;
|
|
|
|
void read(ReadBuffer & in, UInt64 client_protocol_revision);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-15 01:58:10 +00:00
|
|
|
/// Initialize parameters on client initiating query.
|
|
|
|
void setInitialQuery();
|
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
void fillOSUserHostNameAndVersionInfo();
|
2016-10-24 21:40:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|