helix

ClickHouse

The clickhouse integration provides an opinionated way to interact with ClickHouse as OLAP database for helix services.

Trace attributes

The clickhouse integration sets the following trace attributes:

  • clickhouse.database
  • span.kind

When applicable, these attributes can be set as well:

  • clickhouse.async_insert.wait
  • clickhouse.query

Example:

clickhouse.database: "my_db"
clickhouse.query: "SELECT id, username FROM users;"
span.kind: "server"

Usage

The integration uses the official Go library maintained by the ClickHouse team.

Install the Go module with:

$ go get go.nunchi.studio/helix/integration/clickhouse

Simple example on how to import, configure, and use the integration:

import (
  "context"

  "go.nunchi.studio/helix/integration/clickhouse"
  "go.nunchi.studio/helix/service"
)

func main() {
  cfg := clickhouse.Config{
    Addresses: []string{"127.0.0.1:8123"},
    Database:  "default",
  }

  db, err := clickhouse.Connect(cfg)
  if err != nil {
    return err
  }

  ctx := context.Background()
  rows, err := db.Query(ctx, "QUERY", args...)
  if err != nil {
    // ...
  }

  defer rows.Close()
  for rows.Next() {
    // ...
  }

  if err := service.Start(); err != nil {
    panic(err)
  }

  if err := service.Close(); err != nil {
    panic(err)
  }
}

Is something missing?

Built by
Nunchi