mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Otherwise, the default is "false" for verify. This is a breaking change. Fix #2055.
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package clickhousedb
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ClickHouse/ch-go"
|
|
|
|
"akvorado/common/helpers"
|
|
)
|
|
|
|
// Configuration defines how we connect to a ClickHouse database
|
|
type Configuration struct {
|
|
// Servers define the list of clickhouse servers to connect to (with ports)
|
|
Servers []string `validate:"min=1,dive,listen"`
|
|
// Cluster defines the cluster to operate on. This should not change
|
|
// anything from a client point of view, but this switch some mode of
|
|
// operations.
|
|
Cluster string
|
|
// Database defines the database to use
|
|
Database string `validate:"required"`
|
|
// Username defines the username to use for authentication
|
|
Username string `validate:"required"`
|
|
// Password defines the password to use for authentication
|
|
Password string
|
|
// MaxOpenConns tells how many parallel connections to ClickHouse we want
|
|
MaxOpenConns int `validate:"min=1"`
|
|
// DialTimeout tells how much time to wait when connecting to ClickHouse
|
|
DialTimeout time.Duration `validate:"min=100ms"`
|
|
// TLS defines TLS connection parameters, if empty, plain TCP will be used.
|
|
TLS helpers.TLSConfiguration
|
|
}
|
|
|
|
// DefaultConfiguration represents the default configuration for connecting to ClickHouse
|
|
func DefaultConfiguration() Configuration {
|
|
return Configuration{
|
|
Servers: []string{"127.0.0.1:9000"},
|
|
Database: "default",
|
|
Username: "default",
|
|
MaxOpenConns: 10,
|
|
DialTimeout: 5 * time.Second,
|
|
}
|
|
}
|
|
|
|
// ClusterName returns the cluster we operate on.
|
|
func (c *Component) ClusterName() string {
|
|
return c.config.Cluster
|
|
}
|
|
|
|
// DatabaseName returns the database we operate on.
|
|
func (c *Component) DatabaseName() string {
|
|
return c.config.Database
|
|
}
|
|
|
|
// ChGoOptions returns options suitable to use with ch-go and the list of
|
|
// available servers.
|
|
func (c *Component) ChGoOptions() (ch.Options, []string) {
|
|
tlsConfig, _ := c.config.TLS.MakeTLSConfig()
|
|
return ch.Options{
|
|
Address: c.config.Servers[0],
|
|
Database: c.config.Database,
|
|
User: c.config.Username,
|
|
Password: c.config.Password,
|
|
Compression: ch.CompressionLZ4,
|
|
ClientName: "akvorado",
|
|
DialTimeout: c.config.DialTimeout,
|
|
TLS: tlsConfig,
|
|
}, c.config.Servers
|
|
}
|