Skip to content

Commit

Permalink
Added the prefix tag func
Browse files Browse the repository at this point in the history
Signed-off-by: Athish Pranav D <athishanna@gmail.com>
  • Loading branch information
Athishpranav2003 committed Oct 3, 2024
1 parent 7f13c7a commit 95aa28a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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

0 comments on commit 95aa28a

Please sign in to comment.