Skip to content
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

Add additional ClickHouse fields #1396

Merged
merged 4 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
59 changes: 51 additions & 8 deletions common/config/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package config

import (
"errors"
"net/url"
"strings"

"github.com/odigos-io/odigos/common"
)

const (
clickhouseEndpoint = "CLICKHOUSE_ENDPOINT"
clickhouseUsername = "CLICKHOUSE_USERNAME"
clickhousePassword = "CLICKHOUSE_PASSWORD"
clickhouseEndpoint = "CLICKHOUSE_ENDPOINT"
clickhouseUsername = "CLICKHOUSE_USERNAME"
clickhouseCreateSchema = "CLICKHOUSE_CREATE_SCHEME"
clickhouseDatabaseName = "CLICKHOUSE_DATABASE_NAME"
clickhouseTracesTable = "CLICKHOUSE_TRACES_TABLE"
clickhouseMetricsTable = "CLICKHOUSE_METRICS_TABLE"
clickhouseLogsTable = "CLICKHOUSE_LOGS_TABLE"
)

type Clickhouse struct{}
Expand All @@ -24,20 +30,57 @@ func (c *Clickhouse) ModifyConfig(dest ExporterConfigurer, currentConfig *Config
return errors.New("clickhouse endpoint not specified, gateway will not be configured for Clickhouse")
}

username, userExists := dest.GetConfig()[clickhouseUsername]
password, passExists := dest.GetConfig()[clickhousePassword]
if userExists != passExists {
return errors.New("clickhouse username and password must be both specified, or neither")
if !strings.Contains(endpoint, "://") {
endpoint = "tcp://" + endpoint
}

parsedUrl, err := url.Parse(endpoint)
if err != nil {
return errors.New("clickhouse endpoint is not a valid URL")
}

if parsedUrl.Port() == "" {
endpoint = strings.Replace(endpoint, parsedUrl.Host, parsedUrl.Host+":9000", 1)
}

username, userExists := dest.GetConfig()[clickhouseUsername]

exporterName := "clickhouse/clickhouse-" + dest.GetID()
exporterConfig := GenericMap{
"endpoint": endpoint,
}
if userExists {
exporterConfig["username"] = username
exporterConfig["password"] = password
exporterConfig["password"] = "${CLICKHOUSE_PASSWORD}"
}
edeNFed marked this conversation as resolved.
Show resolved Hide resolved

createSchema, exists := dest.GetConfig()[clickhouseCreateSchema]
createSchemaBoolValue := exists && strings.ToLower(createSchema) == "create"
exporterConfig["create_schema"] = createSchemaBoolValue

dbName, exists := dest.GetConfig()[clickhouseDatabaseName]
if !exists {
return errors.New("clickhouse database name not specified, gateway will not be configured for Clickhouse")
}
exporterConfig["database"] = dbName

tracesTable, exists := dest.GetConfig()[clickhouseTracesTable]
if !exists {
return errors.New("clickhouse traces table not specified, gateway will not be configured for Clickhouse")
edeNFed marked this conversation as resolved.
Show resolved Hide resolved
}
exporterConfig["traces_table_name"] = tracesTable

metricsTable, exists := dest.GetConfig()[clickhouseMetricsTable]
if !exists {
return errors.New("clickhouse metrics table not specified, gateway will not be configured for Clickhouse")
}
exporterConfig["metrics_table_name"] = metricsTable

logsTable, exists := dest.GetConfig()[clickhouseLogsTable]
if !exists {
return errors.New("clickhouse logs table not specified, gateway will not be configured for Clickhouse")
}
exporterConfig["logs_table_name"] = logsTable

currentConfig.Exporters[exporterName] = exporterConfig
if isTracingEnabled(dest) {
Expand Down
39 changes: 38 additions & 1 deletion destinations/data/clickhouse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,44 @@ spec:
- name: CLICKHOUSE_PASSWORD
displayName: Password
componentType: input
secret: true
componentProps:
type: password
required: false
secret: true
- name: CLICKHOUSE_CREATE_SCHEME
displayName: Create Scheme
componentType: dropdown
componentProps:
values:
- Create
- Skip
required: true
initialValue: Create
- name: CLICKHOUSE_DATABASE_NAME
displayName: Database Name
componentType: input
componentProps:
type: text
required: true
initialValue: otel
- name: CLICKHOUSE_TRACES_TABLE
displayName: Traces Table
componentType: input
componentProps:
type: text
required: true
initialValue: otel_traces
- name: CLICKHOUSE_METRICS_TABLE
displayName: Metrics Table
componentType: input
componentProps:
type: text
required: true
initialValue: otel_metrics
- name: CLICKHOUSE_LOGS_TABLE
displayName: Logs Table
componentType: input
componentProps:
type: text
required: true
initialValue: otel_logs
Loading