Skip to content

Commit

Permalink
LOG-4811: Fluentd is unable to forward logs to external ipv6 elastics…
Browse files Browse the repository at this point in the history
…earch instance
  • Loading branch information
Clee2691 committed Nov 14, 2023
1 parent b58a4e0 commit 133b03b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fluentd/Dockerfile
Expand Up @@ -30,7 +30,9 @@ RUN mv /usr/share/gems/aws-sdk-core.source0001.patch /usr/share/gems/gems/aws-s
cd /usr/share/gems/gems/aws-sdk-core-*/ && patch -p1 < aws-sdk-core.source0001.patch && \
cd /usr/share/gems && \
mv /usr/share/gems/fluent-plugin-detect-exceptions.source0001.patch /usr/share/gems/gems/fluent-plugin-detect-exceptions-*/ && \
cd /usr/share/gems/gems/fluent-plugin-detect-exceptions-*/ && patch -p1 < fluent-plugin-detect-exceptions.source0001.patch
cd /usr/share/gems/gems/fluent-plugin-detect-exceptions-*/ && patch -p1 < fluent-plugin-detect-exceptions.source0001.patch && \
mv /usr/share/gems/fluent-plugin-elasticsearch.source0001.patch /usr/share/gems/gems/fluent-plugin-elasticsearch-*/ && \
cd /usr/share/gems/gems/fluent-plugin-elasticsearch-*/ && patch -p1 < fluent-plugin-elasticsearch.source0001.patch

FROM registry.access.redhat.com/ubi9/ubi-minimal AS runtime

Expand Down
41 changes: 41 additions & 0 deletions fluentd/fluent-plugin-elasticsearch.source0001.patch
@@ -0,0 +1,41 @@
diff --git a/lib/fluent/plugin/out_elasticsearch.rb b/lib/fluent/plugin/out_elasticsearch.rb
index 8780f0aef..e881a3f03 100644
--- a/lib/fluent/plugin/out_elasticsearch.rb
+++ b/lib/fluent/plugin/out_elasticsearch.rb
@@ -651,6 +651,14 @@ EOC
end
end

+ def is_ipv6_host(host_str)
+ begin
+ IPAddr.new(host_str).ipv6?
+ rescue IPAddr::InvalidAddressError
+ return false
+ end
+ end
+
def get_connection_options(con_host=nil)

hosts = if con_host || @hosts
@@ -662,6 +670,21 @@ EOC
port: (host_str.split(':')[1] || @port).to_i,
scheme: @scheme.to_s
}
+ # Support ipv6 for host/host placeholders
+ elsif is_ipv6_host(host_str)
+ if Resolv::IPv6::Regex.match(host_str)
+ {
+ host: "[#{host_str}]",
+ port: @port.to_i,
+ scheme: @scheme.to_s
+ }
+ else
+ {
+ host: host_str,
+ port: @port.to_i,
+ scheme: @scheme.to_s
+ }
+ end
else
# New hosts format expects URLs such as http://logs.foo.com,https://john:pass@logs2.foo.com/elastic
uri = URI(get_escaped_userinfo(host_str))

0 comments on commit 133b03b

Please sign in to comment.