From 6c2e2a92c5fe3290aaf055fba239ba52318e3f2d Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Thu, 11 Jun 2026 11:28:56 +0900 Subject: [PATCH 1/2] Replace yajl-ruby with the json gem for JSON handling Since the yajl-ruby gem depends on a deprecated Ruby C API, it cannot be installed with Ruby 4.1. Signed-off-by: Shizuo Fujita --- lib/fluent/plugin/in_cloudwatch_logs.rb | 9 +++------ lib/fluent/plugin/out_cloudwatch_logs.rb | 7 ++----- test/plugin/test_in_cloudwatch_logs.rb | 2 +- test/plugin/test_out_cloudwatch_logs.rb | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/fluent/plugin/in_cloudwatch_logs.rb b/lib/fluent/plugin/in_cloudwatch_logs.rb index 11d334b..5faa289 100644 --- a/lib/fluent/plugin/in_cloudwatch_logs.rb +++ b/lib/fluent/plugin/in_cloudwatch_logs.rb @@ -2,7 +2,6 @@ require 'time' require 'fluent/plugin/input' require 'fluent/plugin/parser' -require 'yajl' module Fluent::Plugin class CloudwatchLogsInput < Input @@ -36,7 +35,7 @@ class CloudwatchLogsInput < Input deprecated: "Use instead." config_param :fetch_interval, :time, default: 60 config_param :http_proxy, :string, default: nil - config_param :json_handler, :enum, list: [:yajl, :json], default: :yajl + config_param :json_handler, :enum, list: [:yajl, :json], default: :json # NOTE: Contains yajl for backward compatibility config_param :use_todays_log_stream, :bool, default: false config_param :use_aws_timestamp, :bool, default: false config_param :start_time, :string, default: nil @@ -132,9 +131,7 @@ def start thread_create(:in_cloudwatch_logs_runner, &method(:run)) @json_handler = case @json_handler - when :yajl - Yajl - when :json + when :yajl, :json JSON end end @@ -264,7 +261,7 @@ def emit(group, stream, event, metadata) record.merge!("metadata" => metadata) end router.emit(@tag, time, record) - rescue JSON::ParserError, Yajl::ParseError => error # Catch parser errors + rescue JSON::ParserError => error # Catch parser errors log.error "Invalid JSON encountered while parsing event.message" router.emit_error_event(@tag, time, { message: event.message }, error) end diff --git a/lib/fluent/plugin/out_cloudwatch_logs.rb b/lib/fluent/plugin/out_cloudwatch_logs.rb index 5ec6ceb..4fd8081 100644 --- a/lib/fluent/plugin/out_cloudwatch_logs.rb +++ b/lib/fluent/plugin/out_cloudwatch_logs.rb @@ -1,7 +1,6 @@ require 'fluent/plugin/output' require 'fluent/msgpack_factory' require 'thread' -require 'yajl' module Fluent::Plugin class CloudwatchLogsOutput < Output @@ -50,7 +49,7 @@ class TooLargeEventError < Fluent::UnrecoverableError; end config_param :retention_in_days, :integer, default: nil config_param :retention_in_days_key, :string, default: nil config_param :remove_retention_in_days_key, :bool, default: false - config_param :json_handler, :enum, list: [:yajl, :json], :default => :yajl + config_param :json_handler, :enum, list: [:yajl, :json], :default => :json config_param :log_rejected_request, :bool, :default => false config_section :web_identity_credentials, multi: false do config_param :role_arn, :string @@ -168,9 +167,7 @@ def start log.debug "Aws::CloudWatchLogs::Client initialized: log.level #{log.level} => #{options[:log_level]}" @json_handler = case @json_handler - when :yajl - Yajl - when :json + when :yajl, :json JSON end end diff --git a/test/plugin/test_in_cloudwatch_logs.rb b/test/plugin/test_in_cloudwatch_logs.rb index 7a04f38..5a77749 100644 --- a/test/plugin/test_in_cloudwatch_logs.rb +++ b/test/plugin/test_in_cloudwatch_logs.rb @@ -40,7 +40,7 @@ def test_configure assert_equal('stream', d.instance.log_stream_name) assert_equal(true, d.instance.use_log_stream_name_prefix) assert_equal('/tmp/state', d.instance.state_file) - assert_equal(:yajl, d.instance.json_handler) + assert_equal(:json, d.instance.json_handler) assert_equal(true, d.instance.use_aws_timestamp) assert_equal(1560816000000, d.instance.start_time) assert_equal(1579305600000, d.instance.end_time) diff --git a/test/plugin/test_out_cloudwatch_logs.rb b/test/plugin/test_out_cloudwatch_logs.rb index 6c0aa56..8dfdc94 100644 --- a/test/plugin/test_out_cloudwatch_logs.rb +++ b/test/plugin/test_out_cloudwatch_logs.rb @@ -37,7 +37,7 @@ def test_configure assert_equal("tagvalue", d.instance.log_group_aws_tags.fetch("tagkey")) assert_equal("tagvalue_2", d.instance.log_group_aws_tags.fetch("tagkey_2")) assert_equal(5, d.instance.retention_in_days) - assert_equal(:yajl, d.instance.json_handler) + assert_equal(:json, d.instance.json_handler) assert_equal(["fluentd","aws","cloudwatch"], d.instance.message_keys) end end From 8cbcb988cdd26c0ddb2144b030f2ff7748b07ab3 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Thu, 11 Jun 2026 14:03:20 +0900 Subject: [PATCH 2/2] Add deprecation warning for yajl json_handler Signed-off-by: Shizuo Fujita --- lib/fluent/plugin/in_cloudwatch_logs.rb | 5 ++++- lib/fluent/plugin/out_cloudwatch_logs.rb | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/in_cloudwatch_logs.rb b/lib/fluent/plugin/in_cloudwatch_logs.rb index 5faa289..edba583 100644 --- a/lib/fluent/plugin/in_cloudwatch_logs.rb +++ b/lib/fluent/plugin/in_cloudwatch_logs.rb @@ -131,7 +131,10 @@ def start thread_create(:in_cloudwatch_logs_runner, &method(:run)) @json_handler = case @json_handler - when :yajl, :json + when :yajl + log.info "json_handler 'yajl' is deprecated. Please use 'json' instead." + JSON + when :json JSON end end diff --git a/lib/fluent/plugin/out_cloudwatch_logs.rb b/lib/fluent/plugin/out_cloudwatch_logs.rb index 4fd8081..8565a8f 100644 --- a/lib/fluent/plugin/out_cloudwatch_logs.rb +++ b/lib/fluent/plugin/out_cloudwatch_logs.rb @@ -167,7 +167,10 @@ def start log.debug "Aws::CloudWatchLogs::Client initialized: log.level #{log.level} => #{options[:log_level]}" @json_handler = case @json_handler - when :yajl, :json + when :yajl + log.info "json_handler 'yajl' is deprecated. Please use 'json' instead." + JSON + when :json JSON end end