Class: ClickHouse::Client::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/click_house/client/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



58
59
60
61
62
63
64
# File 'lib/click_house/client/configuration.rb', line 58

def initialize
  @databases = {}
  @http_post_proc = nil
  @json_parser = JSON
  @logger = ::Logger.new($stdout)
  @log_proc = ->(query) { query.to_sql }
end

Instance Attribute Details

#databasesObject (readonly)

Returns the value of attribute databases.



56
57
58
# File 'lib/click_house/client/configuration.rb', line 56

def databases
  @databases
end

#http_post_procObject

Configuration options:

register_database (method): registers a database, the following arguments are required:

- database: database name
- url: URL and port to the HTTP interface
- username
- password
- variables (optional): configuration for the client

http_post_proc: A callable object for invoking the HTTP request.

The object must handle the following parameters: url, headers, body
and return a ClickHouse::Client::Response object.

json_parser: object for parsing JSON strings, it should respond to the “parse” method

logger: object for receiving logger commands. Default ‘$stdout` log_proc: any output (e.g. structure) to wrap around the query for every statement

Example:

ClickHouse::Client.configure do |c|

c.register_database(:main,
  database: 'gitlab_clickhouse_test',
  url: 'http://localhost:8123',
  username: 'default',
  password: 'clickhouse',
  variables: {
    join_use_nulls: 1 # treat JOINs as per SQL standard
  }
)

c.logger = MyLogger.new
c.log_proc = ->(query) do
  { query_body: query.to_redacted_sql }
end

c.http_post_proc = lambda do |url, headers, body|
  options = {
    headers: headers,
    body: body,
    allow_local_requests: false
  }

  response = Gitlab::HTTP.post(url, options)
  ClickHouse::Client::Response.new(response.body, response.code)
end

c.json_parser = JSON

end



55
56
57
# File 'lib/click_house/client/configuration.rb', line 55

def http_post_proc
  @http_post_proc
end

#json_parserObject

Configuration options:

register_database (method): registers a database, the following arguments are required:

- database: database name
- url: URL and port to the HTTP interface
- username
- password
- variables (optional): configuration for the client

http_post_proc: A callable object for invoking the HTTP request.

The object must handle the following parameters: url, headers, body
and return a ClickHouse::Client::Response object.

json_parser: object for parsing JSON strings, it should respond to the “parse” method

logger: object for receiving logger commands. Default ‘$stdout` log_proc: any output (e.g. structure) to wrap around the query for every statement

Example:

ClickHouse::Client.configure do |c|

c.register_database(:main,
  database: 'gitlab_clickhouse_test',
  url: 'http://localhost:8123',
  username: 'default',
  password: 'clickhouse',
  variables: {
    join_use_nulls: 1 # treat JOINs as per SQL standard
  }
)

c.logger = MyLogger.new
c.log_proc = ->(query) do
  { query_body: query.to_redacted_sql }
end

c.http_post_proc = lambda do |url, headers, body|
  options = {
    headers: headers,
    body: body,
    allow_local_requests: false
  }

  response = Gitlab::HTTP.post(url, options)
  ClickHouse::Client::Response.new(response.body, response.code)
end

c.json_parser = JSON

end



55
56
57
# File 'lib/click_house/client/configuration.rb', line 55

def json_parser
  @json_parser
end

#log_procObject

Configuration options:

register_database (method): registers a database, the following arguments are required:

- database: database name
- url: URL and port to the HTTP interface
- username
- password
- variables (optional): configuration for the client

http_post_proc: A callable object for invoking the HTTP request.

The object must handle the following parameters: url, headers, body
and return a ClickHouse::Client::Response object.

json_parser: object for parsing JSON strings, it should respond to the “parse” method

logger: object for receiving logger commands. Default ‘$stdout` log_proc: any output (e.g. structure) to wrap around the query for every statement

Example:

ClickHouse::Client.configure do |c|

c.register_database(:main,
  database: 'gitlab_clickhouse_test',
  url: 'http://localhost:8123',
  username: 'default',
  password: 'clickhouse',
  variables: {
    join_use_nulls: 1 # treat JOINs as per SQL standard
  }
)

c.logger = MyLogger.new
c.log_proc = ->(query) do
  { query_body: query.to_redacted_sql }
end

c.http_post_proc = lambda do |url, headers, body|
  options = {
    headers: headers,
    body: body,
    allow_local_requests: false
  }

  response = Gitlab::HTTP.post(url, options)
  ClickHouse::Client::Response.new(response.body, response.code)
end

c.json_parser = JSON

end



55
56
57
# File 'lib/click_house/client/configuration.rb', line 55

def log_proc
  @log_proc
end

#loggerObject

Configuration options:

register_database (method): registers a database, the following arguments are required:

- database: database name
- url: URL and port to the HTTP interface
- username
- password
- variables (optional): configuration for the client

http_post_proc: A callable object for invoking the HTTP request.

The object must handle the following parameters: url, headers, body
and return a ClickHouse::Client::Response object.

json_parser: object for parsing JSON strings, it should respond to the “parse” method

logger: object for receiving logger commands. Default ‘$stdout` log_proc: any output (e.g. structure) to wrap around the query for every statement

Example:

ClickHouse::Client.configure do |c|

c.register_database(:main,
  database: 'gitlab_clickhouse_test',
  url: 'http://localhost:8123',
  username: 'default',
  password: 'clickhouse',
  variables: {
    join_use_nulls: 1 # treat JOINs as per SQL standard
  }
)

c.logger = MyLogger.new
c.log_proc = ->(query) do
  { query_body: query.to_redacted_sql }
end

c.http_post_proc = lambda do |url, headers, body|
  options = {
    headers: headers,
    body: body,
    allow_local_requests: false
  }

  response = Gitlab::HTTP.post(url, options)
  ClickHouse::Client::Response.new(response.body, response.code)
end

c.json_parser = JSON

end



55
56
57
# File 'lib/click_house/client/configuration.rb', line 55

def logger
  @logger
end

Instance Method Details

#register_database(name, **args) ⇒ Object

Raises:



66
67
68
69
70
# File 'lib/click_house/client/configuration.rb', line 66

def register_database(name, **args)
  raise ConfigurationError, "The database '#{name}' is already registered" if @databases.key?(name)

  @databases[name] = Database.new(**args)
end

#validate!Object

Raises:



72
73
74
75
# File 'lib/click_house/client/configuration.rb', line 72

def validate!
  raise ConfigurationError, "The 'http_post_proc' option is not configured" unless @http_post_proc
  raise ConfigurationError, "The 'json_parser' option is not configured" unless @json_parser
end