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

in_http: add add_tag_prefix configuration option #4655

Merged
merged 1 commit into from
Oct 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/fluent/plugin/in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class HttpInput < Input
config_param :dump_error_log, :bool, default: true
desc 'Add QUERY_ prefix query params to record'
config_param :add_query_params, :bool, default: false
desc "Add prefix to incoming tag"
config_param :add_tag_prefix, :string, default: nil

config_section :parse do
config_set_default :@type, 'in_http'
Expand Down Expand Up @@ -120,6 +122,8 @@ def configure(conf)
end
end

raise Fluent::ConfigError, "'add_tag_prefix' parameter must not be empty" if @add_tag_prefix && @add_tag_prefix.empty?

m = if @parser_configs.first['@type'] == 'in_http'
@parser_msgpack = parser_create(usage: 'parser_in_http_msgpack', type: 'msgpack')
@parser_msgpack.time_key = nil
Expand Down Expand Up @@ -203,6 +207,7 @@ def on_request(path_info, params)
begin
path = path_info[1..-1] # remove /
tag = path.split('/').join('.')
tag = "#{@add_tag_prefix}.#{tag}" if @add_tag_prefix

mes = Fluent::MultiEventStream.new
parse_params(params) do |record_time, record|
Expand Down
23 changes: 23 additions & 0 deletions test/plugin/test_in_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,29 @@ def test_add_query_params
assert_equal events, d.events
end

def test_add_tag_prefix
d = create_driver(config + "add_tag_prefix test")
assert_equal "test", d.instance.add_tag_prefix

time = event_time("2011-01-02 13:14:15.123 UTC")
float_time = time.to_f

events = [
["tag1", time, {"a"=>1}],
]
res_codes = []

d.run(expect_records: 1) do
events.each do |tag, t, record|
res = post("/#{tag}", {"json"=>record.to_json, "time"=>float_time.to_s})
res_codes << res.code
end
end

assert_equal ["200"], res_codes
assert_equal [["test.tag1", time, {"a"=>1}]], d.events
end

$test_in_http_connection_object_ids = []
$test_in_http_content_types = []
$test_in_http_content_types_flag = false
Expand Down
Loading