questdb / c-questdb-client

Rust, C and C++ client for QuestDB InfluxDB Line Protocol
Apache License 2.0
48 stars 13 forks source link

BREAKING CHANGE: Create a `Sender` or `SenderBuilder` from configuration or env var (#54) #54

Closed amunra closed 8 months ago

amunra commented 9 months ago

Overview

The aim here is to support the new ILP config string format as documented in https://docs.google.com/document/d/1EQZjYrJO_Ll8RrSIZpbr15Ul3N-xAtTxvrunI-TpOR8 and now also supported by the Java client and soon other clients too.

Changes

This introduces a new "configuration string" format that is being supported across all ILP clients.

The parser was already implemented as https://github.com/questdb/questdb-confstr-rs/.

The format is: protocol::addr=host:port;key1=value1;key2=value2;...;.

The protocols supported are:

The Rust SenderBuilder, and the C and C++ opts object methods have been aligned to the new configuration format.

For example in C++,

// OLD API
line_sender_builder opts{"localhost", 9009};
opts.auth("u", "t", "x", "y"); 

has been refactored to:

// NEW API
line_sender_builder opts{protocol::tcp, "localhost", 9009};
opts.username("u");
opts.token("t");
opts.token_x("x");
opts.token_y("y");

and is now equivalent to the conf string

tcp::addr=localhost:9009;username=u;token=t;token_x=x;token_y=y

and can now support building directly without the opts object:

auto sender = line_sender::from_conf(
    "tcp::addr=localhost:9009;username=u;token=t;token_x=x;token_y=y");

The config string can also be read from an environment variable:

export QDB_CONF_STR="tcp::addr=localhost:9009;username=u;token=t;token_x=x;token_y=y"
auto sender = line_sender::from_env();

HTTP

The config string can also be used to configure HTTP.

This is what creating a Rust client with HTTP+TLS looks like:

let sender = Sender::from_conf("https::addr=localhost:9000;username=admin;password=quest;");

For HTTP authentication you can also use a token:

let sender = Sender::from_conf("https::addr=localhost:9000;token=abc;");

Progress