Skip to content

Commit ad16d62

Browse files
myronmarstonclaude
andauthored
Fix LoggerPatch CI failure; bump aws_lambda_ric to 3.2.0 (#1133)
GHA runner image ubuntu24/20260413.86 (kernel 6.17.0-1010-azure) causes IO.new(fd, 'wb') to raise Errno::EBADF in forked subprocesses. TelemetryLogger#initialize silently rescues this and skips applying LoggerPatch, failing our compatibility assertion. Rework install_aws_lambda_runtime_monkey_patches to use the 3.2.0 API: - TelemetryLogger.from_env applies LoggerPatch without any IO - Set up telemetry sink on $stdout manually - Apply mutate_kernel_puts via allocate.send (bypasses constructor) - Assert both mutations applied; verify Logger+LoggerPatch compatibility Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 17d0db3 commit ad16d62

4 files changed

Lines changed: 35 additions & 15 deletions

File tree

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ source "https://rubygems.org"
1010

1111
# Gems needed by the test suite and other CI checks.
1212
group :development do
13-
gem "aws_lambda_ric", "~> 3.1", ">= 3.1.3"
13+
gem "aws_lambda_ric", "~> 3.2"
1414
# graphql-c_parser is no longer a hard dependency, but we include it here for faster CI tests
1515
gem "graphql-c_parser", "~> 1.1", ">= 1.1.3", platforms: :ruby
1616
gem "benchmark-ips", "~> 2.14"

Gemfile.lock

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ GEM
285285
aws-sigv4 (~> 1.5)
286286
aws-sigv4 (1.12.1)
287287
aws-eventstream (~> 1, >= 1.0.2)
288-
aws_lambda_ric (3.1.3)
288+
aws_lambda_ric (3.2.0)
289+
logger (>= 1.4, < 2.0)
289290
base64 (0.3.0)
290291
benchmark (0.5.0)
291292
benchmark-ips (2.14.0)
@@ -682,7 +683,7 @@ PLATFORMS
682683
x86_64-linux-android
683684

684685
DEPENDENCIES
685-
aws_lambda_ric (~> 3.1, >= 3.1.3)
686+
aws_lambda_ric (~> 3.2)
686687
benchmark-ips (~> 2.14)
687688
coderay (~> 1.1, >= 1.1.3)
688689
elasticgraph (= 1.1.1.pre)!
@@ -758,7 +759,7 @@ CHECKSUMS
758759
aws-sdk-s3 (1.219.0) sha256=6a755d7377978525758b3c29185ca6a10128ce2b07555ca37c4549de10c2f1c7
759760
aws-sdk-sqs (1.112.0) sha256=272a2d919fd3daa1c4a8ed0f9a3b765fbb84cce27aaf3b08e6d97edd171bbdae
760761
aws-sigv4 (1.12.1) sha256=6973ff95cb0fd0dc58ba26e90e9510a2219525d07620c8babeb70ef831826c00
761-
aws_lambda_ric (3.1.3) sha256=7d7551c91d2070bb1427cd05d7b0b94076d42084f743b117522659a76935dfbc
762+
aws_lambda_ric (3.2.0) sha256=fdab2c637bf0aa47b1de795d6fe7244572e9f743ac74eb47e1386e3c4c17c269
762763
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
763764
benchmark (0.5.0) sha256=465df122341aedcb81a2a24b4d3bd19b6c67c1530713fd533f3ff034e419236c
764765
benchmark-ips (2.14.0) sha256=b72bc8a65d525d5906f8cd94270dccf73452ee3257a32b89fbd6684d3e8a9b1d

elasticgraph-warehouse_lambda/elasticgraph-warehouse_lambda.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
4646
spec.add_dependency "elasticgraph-lambda_support", ElasticGraph::VERSION
4747
spec.add_dependency "aws-sdk-s3", "~> 1.219"
4848

49-
spec.add_development_dependency "aws_lambda_ric", "~> 3.1", ">= 3.1.3"
49+
spec.add_development_dependency "aws_lambda_ric", "~> 3.2"
5050
spec.add_development_dependency "elasticgraph-elasticsearch", ElasticGraph::VERSION
5151
spec.add_development_dependency "elasticgraph-opensearch", ElasticGraph::VERSION
5252
end

spec_support/lib/elastic_graph/spec_support/lambda_function.rb

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,41 @@ def install_aws_lambda_runtime_monkey_patches
9494
require "aws_lambda_ric/logger_patch"
9595
require "aws_lambda_ric"
9696

97-
# The monkey patches are triggered by the act of instantiating this class:
98-
# https://github.com/aws/aws-lambda-ruby-runtime-interface-client/blob/3.0.0/lib/aws_lambda_ric.rb#L141-L152
99-
AwsLambdaRIC::TelemetryLogger.new("1") # File descriptor is required but not used in test env
100-
101-
# Here we verify that the Logger monkey patch was indeed installed. The installation of the monkey patch
102-
# gets bypassed when certain errors are encountered (which are silently swallowed), so the mere act of
103-
# instantiating the class above doesn't guarantee the monkey patches are active.
104-
#
105-
# Plus, new versions of the `aws_lambda_ric` may change how the monkey patches are installed.
97+
# In production, Bootstrap#start calls TelemetryLogger.from_env, which:
98+
# 1. Applies LoggerPatch via mutate_std_logger (no IO involved)
99+
# 2. Creates a TelemetryLogger instance if _LAMBDA_TELEMETRY_LOG_FD is set,
100+
# which sets up the telemetry sink and calls mutate_kernel_puts
101+
# https://github.com/aws/aws-lambda-ruby-runtime-interface-client/blob/f11c2c7/lib/aws_lambda_ric.rb#L164-L175
106102
#
107-
# https://github.com/aws/aws-lambda-ruby-runtime-interface-client/blob/3.0.0/lib/aws_lambda_ric.rb#L150-L152
103+
# We don't set _LAMBDA_TELEMETRY_LOG_FD, so from_env applies LoggerPatch but returns
104+
# before creating a TelemetryLogger instance (which would call IO.new(fd, 'wb') —
105+
# that raises Errno::EBADF in some CI forked-subprocess environments).
106+
AwsLambdaRIC::TelemetryLogger.from_env
107+
108108
expect(::Logger.ancestors).to include(::LoggerPatch)
109109

110+
# Set up telemetry sink wrapping $stdout, like TelemetryLogger#initialize would have
111+
# done with fd 1. This ensures mutated kernel puts output still reaches stdout so that
112+
# the caller's `to_stdout_from_any_process` matchers continue to work.
113+
AwsLambdaRIC::TelemetryLogger.telemetry_log_fd_file = $stdout
114+
AwsLambdaRIC::TelemetryLogger.telemetry_log_sink = TelemetryLogSink.new(file: $stdout)
115+
116+
# mutate_kernel_puts is normally called by TelemetryLogger#initialize, but we skipped
117+
# the constructor (see above). Apply it via send (private) using allocate to bypass it.
118+
# https://github.com/aws/aws-lambda-ruby-runtime-interface-client/blob/f11c2c7/lib/aws_lambda_ric.rb#L179-L190
119+
expect(kernel_puts_monkey_patched?).to be false
120+
AwsLambdaRIC::TelemetryLogger.allocate.send(:mutate_kernel_puts)
121+
expect(kernel_puts_monkey_patched?).to be true
122+
110123
expect {
111124
# Log a message to stdout--this is what triggered a `NoMethodError` when logger 1.6.0 is used.
112125
::Logger.new($stdout).error("test log message")
113126
}.to output(a_string_including("test log message")).to_stdout_from_any_process
114127
end
128+
129+
def kernel_puts_monkey_patched?
130+
# The original Kernel#puts is implemented in C (source_location returns nil).
131+
# After aws_lambda_ric's mutate_kernel_puts, the source file points into the gem.
132+
Kernel.instance_method(:puts).source_location&.first.to_s.include?("aws_lambda_ric")
133+
end
115134
end

0 commit comments

Comments
 (0)