From 52e0ddd48b320c6f4f66315367a18e25e71d8550 Mon Sep 17 00:00:00 2001 From: Andrew Thauer <6507159+andrewthauer@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:02:20 -0500 Subject: [PATCH 1/3] feat: support uds in datadog statsd --- README.md | 3 ++- lib/racecar/cli.rb | 9 +++++---- lib/racecar/config.rb | 3 +++ lib/racecar/datadog.rb | 15 ++++++++++++++- spec/datadog_spec.rb | 29 +++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 38cb9869..a2a16a3a 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 port of the Datadog agent. - `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..2b4236f6 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" + 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 } From 7e14cacf771e2de4e30176ff53f1b991844e07fa Mon Sep 17 00:00:00 2001 From: Andrew Thauer <6507159+andrewthauer@users.noreply.github.com> Date: Wed, 28 Feb 2024 19:36:17 -0500 Subject: [PATCH 2/3] update socket_path docs --- README.md | 2 +- lib/racecar/config.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2a16a3a..68199b52 100644 --- a/README.md +++ b/README.md @@ -414,7 +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 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. diff --git a/lib/racecar/config.rb b/lib/racecar/config.rb index 2b4236f6..069e41e4 100644 --- a/lib/racecar/config.rb +++ b/lib/racecar/config.rb @@ -158,7 +158,7 @@ class Config < KingKonf::Config desc "The port of the Datadog agent" integer :datadog_port - desc "The unix domain socket of the Datadog agent" + 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" From 934ddc1cb9985e9b3969b3f9c3ff6991ecc7cc1a Mon Sep 17 00:00:00 2001 From: Andrew Thauer <6507159+andrewthauer@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:34:42 -0400 Subject: [PATCH 3/3] chore(docs): add changelog entry for dd uds --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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