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

Allow table and database config options in Clickhouse sink to be templatable #16329

Closed
Fritzss opened this issue Feb 7, 2023 · 2 comments · Fixed by #18005
Closed

Allow table and database config options in Clickhouse sink to be templatable #16329

Fritzss opened this issue Feb 7, 2023 · 2 comments · Fixed by #18005
Labels
sink: clickhouse Anything `clickhouse` sink related type: feature A value-adding code addition that introduce new functionality.

Comments

@Fritzss
Copy link

Fritzss commented Feb 7, 2023

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Use Cases

scenario:
server A sends data to a vector on server B
server B receives and sends to clickhouse
(server A -> n, there can be many)
################
src svc_logs_server cat /etc/vector/logs.toml

data_dir = "/var/lib/vector"

[acknowledgements]
enabled = true

[sources.logs_svc]
type = "file"
file_key = "file"
glob_minimum_cooldown_ms = 1_000
host_key = "host"
ignore_older_secs = 600
include = [
            "/var/log/svc/*.log"
          ]

max_line_bytes = 1024000
max_read_bytes = 1048576
read_from = "beginning"
data_dir = "/var/lib/vector"

[transforms.json_svc]
type = "remap"
inputs = ["logs_svc"]
source = """
        . = merge(object!(parse_json!(.message, max_depth: 1)), . )
        .table = del(.message)
        .table = "svc_logs"
         """
[sinks.vector_ch]
  type = "vector"
  inputs = [ "json_svc" ]
  address = "10.0.0.123:6000"
  compression = true
  buffer.type = "memory"
  buffer.max_events = 5000
  buffer.when_full = "block"
  batch.max_events = 1000
  batch.timeout_secs = 60
  request.concurrency = "adaptive"

dst_server clickhouse + vector cat /etc/vector/vector.toml

data_dir = "/var/lib/vector"


[acknowledgements]
enabled = true


# Random Syslog-formatted logs
[sources.vector]
  type = "vector"
  version = "2"
  address = "0.0.0.0:6000"


# Print parsed logs to stdout
#[sinks.print]
# type = "console"
# inputs = ["vector"]
# encoding.codec = "json"

[sinks.clickhouse_vault]
  type = "clickhouse"
  inputs = [ "vector" ]
  endpoint = "http://127.0.0.1:8123"
  database = "logs"
  table = {{ .table }}
  encoding.timestamp_format = "unix"
  buffer.type = "memory"
  buffer.max_events = 5000
  buffer.when_full = "block"
  batch.max_events = 1000
  batch.timeout_secs = 20
  skip_unknown_fields = true
  request.concurrency = "adaptive"

Attempted Solutions

there is not enough possibility to declare a global variable in the config
GLOBAL_VAR in config.toml

Proposal

No response

References

Version

vector 0.26.0

@Fritzss Fritzss added the type: feature A value-adding code addition that introduce new functionality. label Feb 7, 2023
@StephenWakely StephenWakely changed the title How to use fields in clickhouse sincs (table, database ?) Allow table and database config options in Clickhouse sink to be templatable Feb 22, 2023
@jszwedko jszwedko added the sink: clickhouse Anything `clickhouse` sink related label Apr 10, 2023
@r3code
Copy link

r3code commented May 4, 2023

I'm trying the same. I want to make the sink cobfig dynamic. Based on message fields select clickhouse database and table. I planned to add a transform before clickhouse sink which adds internal fields like ._clickhouse_db and ._clickhouse_table, then use it in sink as a templates value.

@r3code
Copy link

r3code commented May 4, 2023

Why we need this? This allows us to build vector config once and not adding new transforms for new services every time we need to enable logs for a new service.
All that I need is to have my clickhouse tables created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sink: clickhouse Anything `clickhouse` sink related type: feature A value-adding code addition that introduce new functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants