Skip to content

Commit

Permalink
Attempt to fix some more test issues.
Browse files Browse the repository at this point in the history
- Fix Fluent Bit HTTP proxy test.
- Attempt to fix differing behavior of invalid utf-8 handling in CI.
  • Loading branch information
GUI committed Feb 12, 2024
1 parent 29ea022 commit 34d34a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions templates/etc/fluent-bit/fluent-bit.yaml.etlua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ service:
# Determine how many MB of data can be read from disk in the event fluent-bit
# is restarted.
storage.backlog.mem_limit: <%- json_encode(config["fluent_bit"]["service"]["storage_backlog_mem_limit"]) %>
# Enable hot reloading for some testing scenarios.
hot_reload: on

pipeline:
inputs:
Expand Down
5 changes: 1 addition & 4 deletions templates/etc/perp/fluent-bit/rc.env.etlua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<% if config["http_proxy"] then %>
http_proxy=<%- config["http_proxy"] %>
<% end %>
<% if config["https_proxy"] then %>
https_proxy=<%- config["https_proxy"] %>
HTTP_PROXY=<%- config["http_proxy"] %>
<% end %>
17 changes: 12 additions & 5 deletions test/proxy/envoy/test_http_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,23 @@ def test_opensearch_requests_use_proxy
record = wait_for_log(response)[:hit_source]
assert_equal("/api/hello", record["request_path"])

log_output = log_tail.read_until(%r{"uri":"/_bulk"})
log = MultiJson.load(log_output.scan(%r{^.*"uri":"/_bulk".*$}).last)
assert_equal("/_bulk", log.fetch("uri"))
# Fluent Bit establishes a CONNECT tunnel for its proxying, so the only
# thing being logged in the HTTP access log is the initial CONNECT
# request. So we won't actually see the /_bulk requests being sent over
# this tunnel. Also send a SIGHUP to fluent-bit, since otherwise it seems
# like it can take a while for this CONNECT request to be flushed to the
# logs (probably since it's a persistent tunnel).
api_umbrella_process.perp_signal("fluent-bit", "hup")
log_output = log_tail.read_until(%r{"user_agent":"Fluent-Bit"})
log = MultiJson.load(log_output.scan(%r{^.*"user_agent":"Fluent-Bit".*$}).last)
assert_nil(log["uri"])
assert_equal("opensearch:9200", log.fetch("host"))
assert_equal("http", log.fetch("scheme"))
assert_equal("POST", log.fetch("method"))
assert_equal("CONNECT", log.fetch("method"))
assert_equal(200, log.fetch("status"))
assert_match(/\A[0-9a-f.:]+:9200\z/, log.fetch("up_addr"))
assert_nil(log["up_tls_ver"])
assert_nil(log["user_agent"])
assert_equal("Fluent-Bit", log.fetch("user_agent"))

response = Typhoeus.get("https://127.0.0.1:9081/admin/stats/logs.json", http_options.deep_merge(admin_session).deep_merge({
:params => {
Expand Down
22 changes: 20 additions & 2 deletions test/proxy/logging/test_special_chars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,32 @@ def test_invalid_utf8_encoding_in_url_path_url_params_headers
record = wait_for_log(response)[:hit_source]

log = log_tail.read.encode("UTF-8", invalid: :replace)
assert_match("invalid UTF-8 bytes found, skipping bytes", log)
# Fluent Bit's UTF-8 handling appears to be different on x86_64 versus
# ARM64. I believe related to this open issue:
# https://github.com/fluent/fluent-bit/issues/7995
#
# So on ARM64, it complains about UTF-8, which I think is more expected
# since we are sending in invalid encoded data. But on x86-64 systems, this
# doesn't appear to happen. I think we're okay with either behavior,
# really, we mainly just want to make sure things don't crash when
# encountering this type of weird input.
if RUBY_PLATFORM.start_with?("x86_64")
refute_match("invalid UTF-8 bytes found, skipping bytes", log)
else
assert_match("invalid UTF-8 bytes found, skipping bytes", log)
end

# Since the encoding of this string wasn't actually a valid UTF-8 string,
# we test situations where it's sent as the raw ISO-8859-1 value, as well
# as the UTF-8 replacement character.
expected_raw_in_url_path = url_encoded.downcase
expected_raw_in_url_query = url_encoded
expected_raw_in_header = ""
# See above for differences in platform.
if RUBY_PLATFORM.start_with?("x86_64")
expected_raw_in_header = "£"
else
expected_raw_in_header = ""
end
expected_raw_utf8_in_url_path = "%ef%bf%bd"
expected_raw_utf8_in_url_query = "%EF%BF%BD"
expected_raw_utf8_in_header = Base64.decode64("77+9").force_encoding("utf-8")
Expand Down

0 comments on commit 34d34a9

Please sign in to comment.