chore: add clickhouse as db for logs on agent and search
ci-agent / build (push) Failing after 22s

This commit is contained in:
d3m0k1d
2026-04-03 23:23:43 +03:00
parent 27e82f80f1
commit d96f952d73
9 changed files with 595 additions and 0 deletions
+46
View File
@@ -1 +1,47 @@
package storage
import (
"context"
"fmt"
"github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
)
type ClickHouseConfig struct {
Host string
User string
Password string
Database string
}
func OpenClickHouse(cfg ClickHouseConfig) (driver.Conn, error) {
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{cfg.Host},
Auth: clickhouse.Auth{
Database: cfg.Database,
Username: cfg.User,
Password: cfg.Password,
},
Settings: clickhouse.Settings{
"max_execution_time": 60,
},
Compression: &clickhouse.Compression{
Method: clickhouse.CompressionLZ4,
},
DialTimeout: 30,
MaxOpenConns: 10,
MaxIdleConns: 5,
ConnMaxLifetime: 3600,
ConnOpenStrategy: clickhouse.ConnOpenInOrder,
})
if err != nil {
return nil, fmt.Errorf("clickhouse connect: %w", err)
}
if err := conn.Ping(context.Background()); err != nil {
return nil, fmt.Errorf("clickhouse ping: %w", err)
}
return conn, nil
}