Skip to content

Commit 8c47ea9

Browse files
committed
Refactor Data Streams configuration to follow AppSec pattern
- Move Data Streams configuration to use self.extended hook pattern - Add Extensions module to activate Data Streams configuration - Move ENV_ENABLED constant to lib/datadog/data_streams/ext.rb - Add comprehensive RBS type signatures for Data Streams modules - Fix type errors: add missing timestamp field to consumer stats - Improve type coverage to 88-100% across data_streams files - Add configuration settings tests This addresses review comments to align with the existing AppSec configuration pattern and improve type safety.
1 parent bd915cc commit 8c47ea9

File tree

18 files changed

+206
-32
lines changed

18 files changed

+206
-32
lines changed

lib/datadog/core/configuration/settings.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
require_relative '../../profiling/ext'
1313

1414
require_relative '../../tracing/configuration/settings'
15-
require_relative '../../data_streams/configuration/settings'
1615

1716
module Datadog
1817
module Core
@@ -1031,7 +1030,6 @@ def initialize(*_)
10311030
# TODO: Tracing should manage its own settings.
10321031
# Keep this extension here for now to keep things working.
10331032
extend Datadog::Tracing::Configuration::Settings
1034-
extend Datadog::DataStreams::Configuration::Settings
10351033
end
10361034
# standard:enable Metrics/BlockLength
10371035
end

lib/datadog/data_streams.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative 'data_streams/processor'
44
require_relative 'data_streams/pathway_context'
55
require_relative 'data_streams/configuration/settings'
6+
require_relative 'data_streams/extensions'
67
require_relative 'core/utils/time'
78

89
module Datadog
@@ -104,5 +105,8 @@ def components
104105
Datadog.send(:components)
105106
end
106107
end
108+
109+
# Expose Data Streams to global shared objects
110+
Extensions.activate!
107111
end
108112
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'configuration/settings'
4+
5+
module Datadog
6+
module DataStreams
7+
# Configuration for Data Streams Monitoring
8+
module Configuration
9+
end
10+
end
11+
end
12+

lib/datadog/data_streams/configuration/settings.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# frozen_string_literal: true
22

33
require_relative '../../core/environment/variable_helpers'
4+
require_relative '../ext'
45

56
module Datadog
67
module DataStreams
78
module Configuration
89
# Configuration settings for Data Streams Monitoring.
910
module Settings
1011
def self.extended(base)
12+
base = base.singleton_class unless base.is_a?(Class)
13+
add_settings!(base)
14+
end
15+
16+
def self.add_settings!(base)
1117
base.class_eval do
1218
# Data Streams Monitoring configuration
1319
# @public_api
@@ -19,7 +25,7 @@ def self.extended(base)
1925
# @return [Boolean]
2026
option :enabled do |o|
2127
o.type :bool
22-
o.env 'DD_DATA_STREAMS_ENABLED'
28+
o.env Ext::ENV_ENABLED
2329
o.default false
2430
end
2531

lib/datadog/data_streams/ext.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module Datadog
4+
module DataStreams
5+
# Constants for Data Streams Monitoring configuration
6+
# @public_api
7+
module Ext
8+
ENV_ENABLED = 'DD_DATA_STREAMS_ENABLED'
9+
end
10+
end
11+
end
12+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'configuration'
4+
require_relative '../core/configuration'
5+
6+
module Datadog
7+
module DataStreams
8+
# Extends Datadog with Data Streams Monitoring features
9+
module Extensions
10+
# Inject Data Streams settings into global configuration.
11+
def self.activate!
12+
Core::Configuration::Settings.extend(Configuration::Settings)
13+
end
14+
end
15+
end
16+
end
17+

lib/datadog/data_streams/processor.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def decode_pathway_b64(encoded_ctx)
246246
end
247247

248248
def flush_stats
249-
payload = nil
249+
payload = nil # : ::Hash[::String, untyped]?
250250

251251
@stats_mutex.synchronize do
252252
return if @buckets.empty? && @consumer_stats.empty?
@@ -357,6 +357,7 @@ def record_consumer_stats(topic:, partition:, offset:, timestamp:)
357357
topic: topic,
358358
partition: partition,
359359
offset: offset,
360+
timestamp: timestamp,
360361
timestamp_sec: timestamp.to_f
361362
}
362363

@@ -405,7 +406,7 @@ def aggregate_stats_by_time_buckets
405406

406407
def send_stats_to_agent(payload)
407408
response = transport.send_stats(payload)
408-
@logger.debug("DSM stats sent to agent: #{response.code if response.respond_to?(:code)}")
409+
@logger.debug("DSM stats sent to agent: ok=#{response.ok?}")
409410
end
410411

411412
def transport

lib/datadog/tracing/configuration/ext.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ module HTTPErrorStatuses
110110
ENV_SERVER_ERROR_STATUSES = 'DD_TRACE_HTTP_SERVER_ERROR_STATUSES'
111111
ENV_CLIENT_ERROR_STATUSES = 'DD_TRACE_HTTP_CLIENT_ERROR_STATUSES'
112112
end
113-
114-
# @public_api
115-
module DataStreams
116-
ENV_ENABLED = 'DD_DATA_STREAMS_ENABLED'
117-
end
118113
end
119114
end
120115
end

sig/datadog/data_streams/configuration/settings.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Datadog
22
module DataStreams
33
module Configuration
44
module Settings
5-
def self.extended: (untyped base) -> void
5+
def self.extended: (Module base) -> void
66
end
77
end
88
end

sig/datadog/data_streams/ext.rbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Datadog
2+
module DataStreams
3+
module Ext
4+
ENV_ENABLED: ::String
5+
end
6+
end
7+
end
8+

0 commit comments

Comments
 (0)