Skip to content

Commit 3e2f685

Browse files
Merge pull request #14 from scribd/COREINF-7108-fix-hostname-and-secure-connection
COREINF-7108: fix hostname and secure connection
2 parents d69a3dd + b0ff531 commit 3e2f685

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lambda_function.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env ruby
22
# frozen_string_literal: true
33

4-
# Copyright 2020 Scribd, Inc.
5-
64
require 'logger'
75
require 'date'
86
require 'dogapi'
@@ -28,8 +26,8 @@ def lambda_handler(event: {}, context: {})
2826
@event = event
2927
log_context
3028

31-
ssm_path = ENV.fetch('SSM_PATH', false)
32-
if ssm_path
29+
# Optionally hydrate env from SSM
30+
if (ssm_path = ENV.fetch('SSM_PATH', false))
3331
require 'aws-sdk-ssm'
3432
resp = Aws::SSM::Client.new.get_parameters_by_path(
3533
path: "/#{ssm_path}/",
@@ -43,15 +41,19 @@ def lambda_handler(event: {}, context: {})
4341
end
4442
end
4543

46-
unless defined? @slowlog_check
44+
unless defined?(@slowlog_check)
45+
# Give Dogapi a stable hostname so it won't call the `hostname` binary
46+
dd_hostname = ENV['HOSTNAME'] || "slowlog-check-#{ENV.fetch('ENV', 'env')}-#{ENV.fetch('NAMESPACE', 'ns')}"
47+
48+
dd_client = Dogapi::Client.new(
49+
ENV.fetch('DATADOG_API_KEY'),
50+
ENV.fetch('DATADOG_APP_KEY'),
51+
dd_hostname # 3rd arg = host
52+
)
53+
4754
@slowlog_check = SlowlogCheck.new(
48-
ddog: Dogapi::Client.new(
49-
ENV.fetch('DATADOG_API_KEY'),
50-
ENV.fetch('DATADOG_APP_KEY')
51-
),
52-
redis: {
53-
host: ENV.fetch('REDIS_HOST')
54-
},
55+
ddog: dd_client,
56+
redis: { host: ENV.fetch('REDIS_HOST') },
5557
namespace: ENV.fetch('NAMESPACE'),
5658
env: ENV.fetch('ENV'),
5759
metricname: ENV.fetch('METRICNAME', 'elasticache.slowlog')
@@ -61,7 +63,6 @@ def lambda_handler(event: {}, context: {})
6163
end
6264

6365
@slowlog_check.ship_slowlogs
64-
6566
nil
6667
end
6768

0 commit comments

Comments
 (0)