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

fluentd exporter: Disconnect and retry DNS lookup on socket failure #469

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct FluentdExporterOptions {
TransportFormat format = TransportFormat::kForward;
std::string tag = "tag.service";
size_t retry_count = 2; // number of retries before drop
uint32_t retry_delay_ms = 1000;
std::string endpoint;
bool convert_event_to_trace =
false; // convert events to trace. Not used for Logs.
Expand Down
10 changes: 10 additions & 0 deletions exporters/fluentd/src/log/fluentd_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ sdk::common::ExportResult FluentdExporter::Export(
*/
bool FluentdExporter::Send(std::vector<uint8_t> &packet) {
size_t retryCount = options_.retry_count;
auto retrySleepMs = std::chrono::milliseconds(options_.retry_delay_ms);
while (retryCount--) {
int error_code = 0;
// Check if socket is Okay
Expand All @@ -135,8 +136,12 @@ bool FluentdExporter::Send(std::vector<uint8_t> &packet) {
}
// Reconnect if not Okay
if (!connected_) {
Initialize(); // try a DNS lookup, etc
// Establishing socket connection may take time
if (!Connect()) {
if (retryCount) {
std::this_thread::sleep_for(retrySleepMs);
}
continue;
}
LOG_DEBUG("socket connected");
Expand All @@ -152,10 +157,15 @@ bool FluentdExporter::Send(std::vector<uint8_t> &packet) {
}

LOG_WARN("send failed, retrying %lu ...", retryCount);
Disconnect();
// Retry to connect and/or send
if (retryCount) {
std::this_thread::sleep_for(retrySleepMs);
}
}

LOG_ERROR("send failed!");
Disconnect();
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions exporters/fluentd/src/trace/fluentd_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ bool FluentdExporter::Connect() {
*/
bool FluentdExporter::Send(std::vector<uint8_t> &packet) {
size_t retryCount = options_.retry_count;
auto retrySleepMs = std::chrono::milliseconds(options_.retry_delay_ms);
while (retryCount--) {
int error_code = 0;
// Check if socket is Okay
Expand All @@ -238,8 +239,12 @@ bool FluentdExporter::Send(std::vector<uint8_t> &packet) {
}
// Reconnect if not Okay
if (!connected_) {
Initialize(); // try a DNS lookup, etc
// Establishing socket connection may take time
if (!Connect()) {
if (retryCount) {
std::this_thread::sleep_for(retrySleepMs);
}
continue;
}
LOG_DEBUG("socket connected");
Expand All @@ -255,10 +260,15 @@ bool FluentdExporter::Send(std::vector<uint8_t> &packet) {
}

LOG_WARN("send failed, retrying %u ...", (unsigned int)retryCount);
Disconnect();
// Retry to connect and/or send
if (retryCount) {
std::this_thread::sleep_for(retrySleepMs);
}
}

LOG_ERROR("send failed!");
Disconnect();
return false;
}

Expand Down