apiVersion: v1
kind: ConfigMap
metadata:
  name: clickhouse-operator-config
  namespace: "{{ .Release.Namespace }}"
data:
  config.yaml: |-
    default_clickhouse_image: "registry.sensetime.com/diamond/service-providers/clickhouse-server:v20.8.9.6"
    default_clickhouse_init_image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
    default_config:
      - /etc/clickhouse-operator/01-clickhouse-listen.xml
      - /etc/clickhouse-operator/02-clickhouse-logger.xml
      - /etc/clickhouse-operator/03-clickhouse-others.xml
      - /etc/clickhouse-operator/04-clickhouse-prometheus.xml
    default_shard_count: 1
    default_replicas_count: 1
    default_data_capacity: 10Gi
#    default_zookeeper:
#      nodes:
#        - host: zookeeper.{{ .Release.Namespace }}
#          port: 2181
#      session_timeout_ms: 30000
#      operation_timeout_ms: 10000
#      root: /clickhouse/tables
#      identity: user:password
  01-clickhouse-listen.xml: |-
    <yandex>
        <!-- Listen wildcard address to allow accepting connections from other containers and host network. -->
        <listen_host>0.0.0.0</listen_host>
        <listen_try>1</listen_try>
    </yandex>
  02-clickhouse-logger.xml: |-
    <yandex>
        <logger>
            <!-- Possible levels: https://github.com/pocoproject/poco/blob/develop/Foundation/include/Poco/Logger.h#L105 -->
            <level>information</level>
            <log>/var/log/clickhouse-server/clickhouse-server.log</log>
            <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
            <size>2048M</size>
            <count>20</count>
            <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->
            <console>1</console>
        </logger>
    </yandex>
  03-clickhouse-others.xml: |-
    <yandex>
        <timezone>Asia/Shanghai</timezone>
        <keep_alive_timeout>10</keep_alive_timeout>

        <mark_cache_size>10737418240</mark_cache_size>
        <uncompressed_cache_size>8589934592</uncompressed_cache_size>

        <max_concurrent_queries>2000</max_concurrent_queries>
        <max_connections>32768</max_connections>
        <max_open_files>1048576</max_open_files>

        <max_table_size_to_drop>0</max_table_size_to_drop>
        <merge_tree>
           <max_suspicious_broken_parts>5</max_suspicious_broken_parts>
        </merge_tree>
        <dictionaries_lazy_load>true</dictionaries_lazy_load>
        <part_log>
            <database>system</database>
            <table>part_log</table>
            <partition_by>toYYYYMM(event_date)</partition_by>
            <flush_interval_milliseconds>10000</flush_interval_milliseconds>
        </part_log>
        <use_minimalistic_part_header_in_zookeeper>1</use_minimalistic_part_header_in_zookeeper>
        <disable_internal_dns_cache>1</disable_internal_dns_cache>
    </yandex>
  04-clickhouse-prometheus.xml: |-
    <yandex>
      <prometheus>
        <endpoint>/metrics</endpoint>
        <port>9363</port>

        <metrics>true</metrics>
        <events>true</events>
        <asynchronous_metrics>true</asynchronous_metrics>
        <status_info>true</status_info>
      </prometheus>
    </yandex>