Merge pull request #5504 from spjmurray/fix/influxdb_timeouts_5460_5469

Fix TLS Race Connecting to InfluxDB
This commit is contained in:
Michael Friedrich 2017-08-17 18:25:17 +02:00 committed by GitHub
commit cb94b218a6
4 changed files with 4 additions and 17 deletions

View File

@ -926,7 +926,6 @@ Configuration Attributes:
enable_send_metadata | **Optional.** Whether to send check metadata e.g. states, execution time, latency etc. enable_send_metadata | **Optional.** Whether to send check metadata e.g. states, execution time, latency etc.
flush_interval | **Optional.** How long to buffer data points before transfering to InfluxDB. Defaults to `10s`. flush_interval | **Optional.** How long to buffer data points before transfering to InfluxDB. Defaults to `10s`.
flush_threshold | **Optional.** How many data points to buffer before forcing a transfer to InfluxDB. Defaults to `1024`. flush_threshold | **Optional.** How many data points to buffer before forcing a transfer to InfluxDB. Defaults to `1024`.
socket_timeout | **Optional.** How long to wait for InfluxDB to respond. Defaults to `5s`.
Note: If `flush_threshold` is set too low, this will always force the feature to flush all data Note: If `flush_threshold` is set too low, this will always force the feature to flush all data
to InfluxDB. Experiment with the setting, if you are processing more than 1024 metrics per second to InfluxDB. Experiment with the setting, if you are processing more than 1024 metrics per second

View File

@ -134,9 +134,9 @@ void InfluxdbWriter::ExceptionHandler(boost::exception_ptr exp)
//TODO: Close the connection, if we keep it open. //TODO: Close the connection, if we keep it open.
} }
Stream::Ptr InfluxdbWriter::Connect(TcpSocket::Ptr& socket) Stream::Ptr InfluxdbWriter::Connect()
{ {
socket = new TcpSocket(); TcpSocket::Ptr socket = new TcpSocket();
Log(LogNotice, "InfluxdbWriter") Log(LogNotice, "InfluxdbWriter")
<< "Reconnecting to InfluxDB on host '" << GetHost() << "' port '" << GetPort() << "'."; << "Reconnecting to InfluxDB on host '" << GetHost() << "' port '" << GetPort() << "'.";
@ -423,8 +423,7 @@ void InfluxdbWriter::Flush(void)
String body = boost::algorithm::join(m_DataBuffer, "\n"); String body = boost::algorithm::join(m_DataBuffer, "\n");
m_DataBuffer.clear(); m_DataBuffer.clear();
TcpSocket::Ptr socket; Stream::Ptr stream = Connect();
Stream::Ptr stream = Connect(socket);
if (!stream) if (!stream)
return; return;
@ -462,14 +461,6 @@ void InfluxdbWriter::Flush(void)
HttpResponse resp(stream, req); HttpResponse resp(stream, req);
StreamReadContext context; StreamReadContext context;
struct timeval timeout = { GetSocketTimeout(), 0 };
if (!socket->Poll(true, false, &timeout)) {
Log(LogWarning, "InfluxdbWriter")
<< "Response timeout of TCP socket from host '" << GetHost() << "' port '" << GetPort() << "'.";
return;
}
try { try {
resp.Parse(context, true); resp.Parse(context, true);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {

View File

@ -74,7 +74,7 @@ private:
static String EscapeKey(const String& str); static String EscapeKey(const String& str);
static String EscapeField(const String& str); static String EscapeField(const String& str);
Stream::Ptr Connect(TcpSocket::Ptr& socket); Stream::Ptr Connect();
void AssertOnWorkQueue(void); void AssertOnWorkQueue(void);

View File

@ -90,9 +90,6 @@ class InfluxdbWriter : ConfigObject
[config] int flush_threshold { [config] int flush_threshold {
default {{{ return 1024; }}} default {{{ return 1024; }}}
}; };
[config] int socket_timeout {
default {{{ return 5; }}}
};
}; };
validator InfluxdbWriter { validator InfluxdbWriter {