Skip to content

Commit cc65396

Browse files
authored
[APMAPI-1068] Enable Service Discovery (#4649)
1 parent e55b643 commit cc65396

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

.github/forced-tests-list.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"PARAMETRIC": [
3-
"tests/parametric/test_config_consistency.py::Test_Stable_Config_Default"
3+
"tests/parametric/test_config_consistency.py::Test_Stable_Config_Default",
4+
"tests/parametric/test_process_discovery.py"
45
]
56
}

Matrixfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
'error_tracking' => {
1414
'' => '❌ 2.5 / ❌ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby',
1515
},
16+
'process_discovery' => {
17+
'' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby'
18+
},
1619
'appsec:main' => {
1720
'' => '✅ 2.5 / ✅ 2.6 / ✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby'
1821
},

Rakefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ namespace :spec do
7070
:graphql, :graphql_unified_trace_patcher, :graphql_trace_patcher, :graphql_tracing_patcher,
7171
:rails, :railsredis, :railsredis_activesupport, :railsactivejob,
7272
:elasticsearch, :http, :redis, :sidekiq, :sinatra, :hanami, :hanami_autoinstrument,
73-
:profiling, :crashtracking, :error_tracking]
73+
:profiling, :crashtracking, :error_tracking, :process_discovery]
7474

7575
desc '' # "Explicitly hiding from `rake -T`"
7676
RSpec::Core::RakeTask.new(:main) do |t, args|
7777
t.pattern = 'spec/**/*_spec.rb'
7878
t.exclude_pattern = 'spec/**/{appsec/integration,contrib,benchmark,redis,auto_instrument,opentelemetry,profiling,crashtracking,error_tracking}/**/*_spec.rb,'\
79-
' spec/**/{auto_instrument,opentelemetry}_spec.rb, spec/datadog/gem_packaging_spec.rb'
79+
' spec/**/{auto_instrument,opentelemetry,process_discovery}_spec.rb, spec/datadog/gem_packaging_spec.rb'
8080
t.rspec_opts = args.to_a.join(' ')
8181
end
8282

@@ -205,6 +205,15 @@ namespace :spec do
205205
end
206206
# rubocop:enable Style/MultilineBlockChain
207207

208+
# rubocop:disable Style/MultilineBlockChain
209+
RSpec::Core::RakeTask.new(:process_discovery) do |t, args|
210+
t.pattern = 'spec/datadog/core/process_discovery_spec.rb'
211+
t.rspec_opts = args.to_a.join(' ')
212+
end.tap do |t|
213+
Rake::Task[t.name].enhance(["compile:libdatadog_api.#{RUBY_VERSION[/\d+.\d+/]}_#{RUBY_PLATFORM}"])
214+
end
215+
# rubocop:enable Style/MultilineBlockChain
216+
208217
desc '' # "Explicitly hiding from `rake -T`"
209218
RSpec::Core::RakeTask.new(:error_tracking) do |t, args|
210219
t.pattern = 'spec/datadog/error_tracking/**/*_spec.rb'

ext/libdatadog_api/process_discovery.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <errno.h>
22
#include <stdlib.h>
33
#include <ruby.h>
4-
#include <datadog/common.h>
4+
#include <datadog/library-config.h>
55

66
#include "datadog_ruby_common.h"
77

@@ -36,8 +36,7 @@ void process_discovery_init(VALUE core_module) {
3636
rb_define_singleton_method(process_discovery_class, "_native_close_tracer_memfd", _native_close_tracer_memfd, 2);
3737
}
3838

39-
// TODO: Remove DDTRACE_UNUSED and rename _self to self once we have updated libdatadog to 17.1
40-
static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self) {
39+
static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, VALUE self) {
4140
VALUE logger;
4241
VALUE options;
4342
rb_scan_args(argc, argv, "1:", &logger, &options);
@@ -61,7 +60,6 @@ static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, DDTRACE_UNUSED
6160
ENFORCE_TYPE(service_env, T_STRING);
6261
ENFORCE_TYPE(service_version, T_STRING);
6362

64-
/*
6563
ddog_Result_TracerMemfdHandle result = ddog_store_tracer_metadata(
6664
(uint8_t) NUM2UINT(schema_version),
6765
char_slice_from_ruby_string(runtime_id),
@@ -86,9 +84,6 @@ static VALUE _native_store_tracer_metadata(int argc, VALUE *argv, DDTRACE_UNUSED
8684
VALUE tracer_memfd_class = rb_const_get(self, rb_intern("TracerMemfd"));
8785
VALUE tracer_memfd = TypedData_Wrap_Struct(tracer_memfd_class, &tracer_memfd_type, fd);
8886
return tracer_memfd;
89-
*/
90-
91-
rb_raise(rb_eNotImpError, "TODO: Not in use yet, waiting for libdatadog 17.1");
9287
}
9388

9489
static VALUE _native_to_rb_int(DDTRACE_UNUSED VALUE _self, VALUE tracer_memfd) {

lib/datadog/core/configuration/components.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def initialize(settings)
126126
@dynamic_instrumentation = Datadog::DI::Component.build(settings, agent_settings, @logger, telemetry: telemetry)
127127
@error_tracking = Datadog::ErrorTracking::Component.build(settings, @tracer, @logger)
128128
@environment_logger_extra[:dynamic_instrumentation_enabled] = !!@dynamic_instrumentation
129-
# TODO: Re-enable this once we have updated libdatadog to 17.1
130-
# @process_discovery_fd = Core::ProcessDiscovery.get_and_store_metadata(settings, @logger)
129+
@process_discovery_fd = Core::ProcessDiscovery.get_and_store_metadata(settings, @logger)
131130

132131
self.class.configure_tracing(settings)
133132
end
@@ -211,8 +210,7 @@ def shutdown!(replacement = nil)
211210
telemetry.emit_closing! unless replacement&.telemetry&.enabled
212211
telemetry.shutdown!
213212

214-
# TODO: Re-enable this once we have updated libdatadog to 17.1
215-
# Core::ProcessDiscovery._native_close_tracer_memfd(@process_discovery_fd, @logger) if @process_discovery_fd
213+
Core::ProcessDiscovery._native_close_tracer_memfd(@process_discovery_fd, @logger) if @process_discovery_fd
216214
end
217215

218216
# Returns the current state of various components.

spec/datadog/core/configuration/components_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
RSpec.describe Datadog::Core::Configuration::Components do
2929
subject(:components) { described_class.new(settings) }
3030

31-
let(:logger) { instance_double(Datadog::Core::Logger) }
31+
# Using a double does not give access to superclass methods like debug
32+
let(:logger) do
33+
instance_double(Datadog::Core::Logger).tap do |logger|
34+
allow(logger).to receive(:debug)
35+
end
36+
end
3237
let(:settings) { Datadog::Core::Configuration::Settings.new }
3338
let(:agent_settings) { Datadog::Core::Configuration::AgentSettingsResolver.call(settings, logger: nil) }
3439
let(:agent_info) { Datadog::Core::Environment::AgentInfo.new(agent_settings, logger: logger) }

spec/datadog/core/process_discovery_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
require 'spec_helper'
66
require 'datadog/core/process_discovery'
77

8-
# TODO: Re-enable this once we have updated libdatadog to 17.1
9-
RSpec.xdescribe Datadog::Core::ProcessDiscovery do
8+
RSpec.describe Datadog::Core::ProcessDiscovery do
109
describe '.get_and_store_metadata' do
1110
context 'when libdatadog API is not available' do
1211
it 'returns nil' do

0 commit comments

Comments
 (0)