Allow the remote write configuration have multiple destinations (#11005)

This commit is contained in:
Vladimir Kobal 2021-04-21 19:02:32 +03:00 committed by GitHub
parent a1ce482f3e
commit 0d5781ed7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 4 deletions

View File

@ -98,9 +98,13 @@ struct simple_connector_buffer {
struct simple_connector_buffer *next;
};
#define CONNECTED_TO_MAX 1024
struct simple_connector_data {
void *connector_specific_data;
char connected_to[CONNECTED_TO_MAX];
size_t total_buffered_metrics;
BUFFER *header;

View File

@ -31,7 +31,7 @@ void prometheus_remote_write_prepare_header(struct instance *instance)
"Content-Length: %zu\r\n"
"\r\n",
connector_specific_config->remote_write_path,
instance->config.destination,
simple_connector_data->connected_to,
buffer_strlen(simple_connector_data->last_buffer->buffer));
}

View File

@ -314,7 +314,12 @@ void simple_connector_worker(void *instance_p)
size_t reconnects = 0;
sock = connect_to_one_of(
instance->config.destination, connector_specific_config->default_port, &timeout, &reconnects, NULL, 0);
instance->config.destination,
connector_specific_config->default_port,
&timeout,
&reconnects,
connector_specific_data->connected_to,
CONNECTED_TO_MAX);
#ifdef ENABLE_HTTPS
if (exporting_tls_is_enabled(instance->config.type, options) && sock != -1) {
if (netdata_exporting_ctx) {

View File

@ -618,6 +618,7 @@ static void test_simple_connector_worker(void **state)
simple_connector_data->buffer = buffer_create(0);
simple_connector_data->last_buffer->header = buffer_create(0);
simple_connector_data->last_buffer->buffer = buffer_create(0);
strcpy(simple_connector_data->connected_to, "localhost");
buffer_sprintf(simple_connector_data->last_buffer->header, "test header");
buffer_sprintf(simple_connector_data->last_buffer->buffer, "test buffer");
@ -626,8 +627,8 @@ static void test_simple_connector_worker(void **state)
expect_string(__wrap_connect_to_one_of, destination, "localhost");
expect_value(__wrap_connect_to_one_of, default_port, 2003);
expect_not_value(__wrap_connect_to_one_of, reconnects_counter, 0);
expect_value(__wrap_connect_to_one_of, connected_to, 0);
expect_value(__wrap_connect_to_one_of, connected_to_size, 0);
expect_string(__wrap_connect_to_one_of, connected_to, "localhost");
expect_value(__wrap_connect_to_one_of, connected_to_size, CONNECTED_TO_MAX);
will_return(__wrap_connect_to_one_of, 2);
expect_function_call(__wrap_send);
@ -1170,6 +1171,7 @@ static void test_prometheus_remote_write_prepare_header(void **state)
simple_connector_data->last_buffer = callocz(1, sizeof(struct simple_connector_buffer));
simple_connector_data->last_buffer->header = buffer_create(0);
simple_connector_data->last_buffer->buffer = buffer_create(0);
strcpy(simple_connector_data->connected_to, "localhost");
buffer_sprintf(simple_connector_data->last_buffer->buffer, "test buffer");