Skip to content

Clickhouse TLS cleanup #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions cmd/collect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ var cliFlags = []cli.Flag{
&cli.StringFlag{
Name: "clickhouse-dsn",
EnvVars: []string{"CLICKHOUSE_DSN"},
Usage: "ClickHouse server DSN (e.g., clickhouse://user:password@localhost:9000/dbname)",
Category: "Collector Configuration",
},
&cli.BoolFlag{
Name: "clickhouse-disable-tls",
EnvVars: []string{"CLICKHOUSE_DISABLE_TLS"},
Usage: "Allow insecure (non-TLS) connections to ClickHouse",
Usage: "ClickHouse server DSN (e.g. clickhouse://user:password@host:9440/dbname?secure=true or clickhouse://default:password@clickhouse:9000/default)",
Category: "Collector Configuration",
},

Expand Down Expand Up @@ -150,7 +144,6 @@ func runCollector(cCtx *cli.Context) error {
metricsListenAddr = cCtx.String("metrics-listen-addr")
enablePprof = cCtx.Bool("pprof")
clickhouseDSN = cCtx.String("clickhouse-dsn")
clickhouseDisableTLS = cCtx.Bool("clickhouse-disable-tls")
)

// Logger setup
Expand Down Expand Up @@ -180,7 +173,6 @@ func runCollector(cCtx *cli.Context) error {
OutDir: outDir,
CheckNodeURI: checkNodeURI,
ClickhouseDSN: clickhouseDSN,
ClickhouseDisableTLS: clickhouseDisableTLS,
Nodes: nodeURIs,
BloxrouteAuth: blxAuth,
EdenAuth: edenAuth,
Expand Down
22 changes: 4 additions & 18 deletions collector/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package collector

import (
"context"
"crypto/tls"
"fmt"
"slices"
"time"
Expand All @@ -18,9 +17,7 @@ var ErrNoDSN = fmt.Errorf("Clickhouse DSN is required")

type ClickhouseOpts struct {
Log *zap.SugaredLogger

DSN string
DisableTLS bool // if true, disables TLS verification for Clickhouse connections
DSN string
}

type SourceLogEntry struct {
Expand Down Expand Up @@ -71,22 +68,11 @@ func (ch *Clickhouse) connect() error {
return fmt.Errorf("failed to parse Clickhouse DSN: %w", err)
}

var chTLS *tls.Config
enableTLS := !ch.opts.DisableTLS
if enableTLS {
chTLS = &tls.Config{
InsecureSkipVerify: true, //nolint:gosec
}
options.Debugf = func(format string, v ...interface{}) {
ch.log.Infof("Clickhouse debug: "+format, v...)
}

ch.conn, err = clickhouse.Open(&clickhouse.Options{
Addr: options.Addr,
Auth: options.Auth,
TLS: chTLS,
Debugf: func(format string, v ...interface{}) {
ch.log.Infof("Clickhouse debug: "+format, v...)
},
})
ch.conn, err = clickhouse.Open(options)
if err != nil {
return err
}
Expand Down
6 changes: 2 additions & 4 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ type CollectorOpts struct {
Nodes []string
OutDir string

CheckNodeURI string
ClickhouseDSN string
ClickhouseDisableTLS bool // if true, disables TLS verification for Clickhouse connections
CheckNodeURI string
ClickhouseDSN string

BloxrouteAuth []string
EdenAuth []string
Expand Down Expand Up @@ -92,7 +91,6 @@ func Start(opts *CollectorOpts) {
OutDir: opts.OutDir,
CheckNodeURI: opts.CheckNodeURI,
ClickhouseDSN: opts.ClickhouseDSN,
ClickhouseDisableTLS: opts.ClickhouseDisableTLS,
HTTPReceivers: opts.Receivers,
ReceiversAllowedSources: opts.ReceiversAllowedSources,
})
Expand Down
12 changes: 4 additions & 8 deletions collector/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type TxProcessorOpts struct {
Location string // location of the collector, will be stored in sourcelogs
CheckNodeURI string
ClickhouseDSN string
ClickhouseDisableTLS bool
HTTPReceivers []string
ReceiversAllowedSources []string
}
Expand Down Expand Up @@ -66,9 +65,8 @@ type TxProcessor struct {

lastHealthCheckCall time.Time

clickhouseDSN string
clickhouseConn *Clickhouse
clickhouseDisableTLS bool
clickhouseDSN string
clickhouseConn *Clickhouse
}

type OutFiles struct {
Expand Down Expand Up @@ -101,7 +99,6 @@ func NewTxProcessor(opts TxProcessorOpts) *TxProcessor {
receivers: receivers,
receiversAllowedSources: opts.ReceiversAllowedSources,
clickhouseDSN: opts.ClickhouseDSN,
clickhouseDisableTLS: opts.ClickhouseDisableTLS,
}
}

Expand All @@ -112,9 +109,8 @@ func (p *TxProcessor) Start() {
if p.clickhouseDSN != "" {
p.log.Info("Connecting to Clickhouse...")
p.clickhouseConn, err = NewClickhouse(ClickhouseOpts{
Log: p.log,
DSN: p.clickhouseDSN,
DisableTLS: p.clickhouseDisableTLS,
Log: p.log,
DSN: p.clickhouseDSN,
})
if err != nil {
p.log.Fatalw("failed to connect to Clickhouse", "error", err)
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
services:
collector:
image: mempool-dumpster
build:
context: .
dockerfile: Dockerfile
container_name: mempool-dumpster
command: /app/mempool-dumpster collect
depends_on:
Expand All @@ -27,7 +30,6 @@ services:
LOCATION: local-eu
CLICKHOUSE_DSN: "clickhouse://default:password@clickhouse:9000/default"
CLICKHOUSE_BATCH_SIZE: 300
CLICKHOUSE_DISABLE_TLS: "1"

clickhouse:
image: clickhouse/clickhouse-server:25.3
Expand Down
Loading