diff --git a/CHANGELOG.md b/CHANGELOG.md index 57fe4f02..b525e6a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 38cb9869..68199b52 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 ``` diff --git a/lib/racecar/cli.rb b/lib/racecar/cli.rb index 84c79f99..f2635dd6 100644 --- a/lib/racecar/cli.rb +++ b/lib/racecar/cli.rb @@ -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 diff --git a/lib/racecar/config.rb b/lib/racecar/config.rb index 17039f09..069e41e4 100644 --- a/lib/racecar/config.rb +++ b/lib/racecar/config.rb @@ -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 diff --git a/lib/racecar/datadog.rb b/lib/racecar/datadog.rb index abb1857d..d139dcae 100644 --- a/lib/racecar/datadog.rb +++ b/lib/racecar/datadog.rb @@ -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) @@ -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 diff --git a/spec/datadog_spec.rb b/spec/datadog_spec.rb index de04842c..84ff6db7 100644 --- a/spec/datadog_spec.rb +++ b/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 }