Skip to content

cloudwatch metrics can be turned off #38

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ config.lambdakiq
- `max_retries=` - Retries for all jobs. Default is the Lambdakiq maximum of `12`.
- `metrics_namespace=` - The CloudWatch Embedded Metrics namespace. Default is `Lambdakiq`.
- `metrics_logger=` - Set to the Rails logger which is STDOUT via Lamby/Lambda.
- `send_cloud_watch_metrics` - Set to `true` to enable CloudWatch metrics. Default is `true`.

### ActiveJob Configs

Expand Down
1 change: 1 addition & 0 deletions lib/lambdakiq/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize(event)

def log
return unless lambdakiq?
return unless Lambdakiq.config.send_cloud_watch_metrics
logger.info JSON.dump(message)
end

Expand Down
1 change: 1 addition & 0 deletions lib/lambdakiq/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Railtie < ::Rails::Railtie
config.lambdakiq = ActiveSupport::OrderedOptions.new
config.lambdakiq.max_retries = 12
config.lambdakiq.metrics_namespace = 'Lambdakiq'
config.lambdakiq.send_cloud_watch_metrics = true

config.after_initialize do
config.active_job.logger = Rails.logger
Expand Down
9 changes: 9 additions & 0 deletions test/cases/job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class JobTest < LambdakiqSpec
expect(metric['JobArg1']).must_equal 'test'
end

it 'does not log cloudwatch embedded metrics when disabled' do
Lambdakiq.config.send_cloud_watch_metrics = false
response = Lambdakiq::Job.handler(event_basic(messageId: message_id))
assert_response response, failures: false
metric = logged_metric('perform.active_job')
expect(metric).must_be_nil
Lambdakiq.config.send_cloud_watch_metrics = true
end

it 'must change message visibility to next value for failed jobs' do
event = event_basic attributes: { ApproximateReceiveCount: '7' }, job_class: 'TestHelper::Jobs::ErrorJob', messageId: message_id
response = Lambdakiq::Job.handler(event)
Expand Down