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

LOG-4811: Fluentd is unable to forward logs to external ipv6 elasticsearch instance #106

Merged
merged 1 commit into from Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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))