Skip to content

Commit

Permalink
Merge pull request #365 from andrewthauer/dd-uds
Browse files Browse the repository at this point in the history
feat: support uds in datadog statsd
  • Loading branch information
deepredsky committed Apr 2, 2024
2 parents 5200577 + 934ddc1 commit bf8c862
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* Add unix domain socket support for Datadog StatsD metrics
* Bump minimum rdkafka gem version to 0.15.0
* Bump minimum Ruby version to 3.0

Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -414,6 +414,7 @@ Racecar supports [Datadog](https://www.datadoghq.com/) monitoring integration. I
- `datadog_enabled` – Whether Datadog monitoring is enabled (defaults to `false`).
- `datadog_host` – The host running the Datadog agent.
- `datadog_port` – The port of the Datadog agent.
- `datadog_socket_path` – The unix domain socket of the Datadog agent (when set takes precedence over host/port).
- `datadog_namespace` – The namespace to use for Datadog metrics.
- `datadog_tags` – Tags that should always be set on Datadog metrics.

Expand Down Expand Up @@ -695,7 +696,7 @@ In order to safely upgrade from Racecar v1 to v2, you need to completely shut do

Racecar v2 requires a C library (zlib) to compress the messages before producing to the topic. If not already installed on you consumer docker container, please install using following command in Dockerfile of consumer

```
```
apt-get update && apt-get install -y libzstd-dev
```

Expand Down
9 changes: 5 additions & 4 deletions lib/racecar/cli.rb
Expand Up @@ -157,10 +157,11 @@ def configure_datadog
require_relative './datadog'

Datadog.configure do |datadog|
datadog.host = config.datadog_host unless config.datadog_host.nil?
datadog.port = config.datadog_port unless config.datadog_port.nil?
datadog.namespace = config.datadog_namespace unless config.datadog_namespace.nil?
datadog.tags = config.datadog_tags unless config.datadog_tags.nil?
datadog.host = config.datadog_host unless config.datadog_host.nil?
datadog.port = config.datadog_port unless config.datadog_port.nil?
datadog.socket_path = config.socket_path unless config.socket_path.nil?
datadog.namespace = config.datadog_namespace unless config.datadog_namespace.nil?
datadog.tags = config.datadog_tags unless config.datadog_tags.nil?
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/racecar/config.rb
Expand Up @@ -158,6 +158,9 @@ class Config < KingKonf::Config
desc "The port of the Datadog agent"
integer :datadog_port

desc "The unix domain socket of the Datadog agent (when set takes precedence over host/port)"
integer :datadog_socket_path

desc "The namespace to use for Datadog metrics"
string :datadog_namespace

Expand Down
15 changes: 14 additions & 1 deletion lib/racecar/datadog.rb
Expand Up @@ -19,7 +19,11 @@ def configure
end

def statsd
@statsd ||= ::Datadog::Statsd.new(host, port, namespace: namespace, tags: tags)
@statsd ||= if socket_path
::Datadog::Statsd.new(socket_path: socket_path, namespace: namespace, tags: tags)
else
::Datadog::Statsd.new(host, port, namespace: namespace, tags: tags)
end
end

def statsd=(statsd)
Expand All @@ -45,6 +49,15 @@ def port=(port)
clear
end

def socket_path
@socket_path
end

def socket_path=(socket_path)
@socket_path = socket_path
clear
end

def namespace
@namespace ||= STATSD_NAMESPACE
end
Expand Down
29 changes: 29 additions & 0 deletions spec/datadog_spec.rb
@@ -1,6 +1,35 @@
# frozen_string_literal: true

require "racecar/datadog"

RSpec.describe Racecar::Datadog do
describe '.statsd' do
it 'configures with host/port by default' do
statsd = Racecar::Datadog.statsd
expect(statsd.host).to eq('127.0.0.1')
expect(statsd.port).to eq(8125)
expect(statsd.socket_path).to be_nil
end

it 'configures with host/port explicitly' do
Racecar::Datadog.host = '10.0.0.1'
Racecar::Datadog.port = 8555
statsd = Racecar::Datadog.statsd
expect(statsd.host).to eq('10.0.0.1')
expect(statsd.port).to eq(8555)
expect(statsd.socket_path).to be_nil
end

it 'configures with socket_path explicitly' do
Racecar::Datadog.socket_path = '/var/run/datadog/dsd.socket'
statsd = Racecar::Datadog.statsd
expect(statsd.socket_path).to eq('/var/run/datadog/dsd.socket')
expect(statsd.host).to be_nil
expect(statsd.port).to be_nil
end
end
end

RSpec.describe Racecar::Datadog::StatsdSubscriber do
describe '#emit' do
let(:subscriber) { Racecar::Datadog::StatsdSubscriber.new }
Expand Down

0 comments on commit bf8c862

Please sign in to comment.