Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote configuration dispatcher #2705

Merged
merged 5 commits into from
Mar 23, 2023
Merged

Conversation

lloeki
Copy link
Contributor

@lloeki lloeki commented Mar 21, 2023

What does this PR do?

Add a dispatcher.

The last commit is only adding some spec cleanup and has nothing to do with the actual logic of the PR e70ca73. Please review separately

Motivation

Remote configuration

Additional Notes

The dispatcher gets registered against using a receiver for a block to be called and a matcher to select relevant changes from the changeset.

Upon changes, the dispatcher matches changes against the matcher and calls the receiver, passing the subset of changes as well as the repository itself. This is because:

  • A receiver might need not just the change but complement that change with the full state. therefore the repository state is needed.
  • A receiver might need to understand a specific change in the changeset and act in a specific way according to the type (it might want to operate differently on an update vs a deletion) or content (it might want to look at the diff in state) so passing the current repository state is not sufficient. Therefore passing the list of changes is needed.

A generic matcher that takes a block is available, for other matchers to be implemented. A simple product matcher is implemented, based on the generic one.

How to test the change?

  require 'ddtrace'

  Datadog.configure do |c|
    c.agent.host = '192.168.135.133'
    c.diagnostics.debug = true
  end

  Datadog::Core::Remote.active_remote.sync
  repository = Datadog::Core::Remote.active_remote.client.instance_eval { @repository }

  require 'irb'

  sleep 1000

Wait a bit to receive first batch of RC. This should happen:

D, [2023-03-21T10:18:10.338264 #29926] DEBUG -- ddtrace: [ddtrace] (/Users/lloeki/Source/github.com/DataDog/dd-trace-rb-alt/lib/datadog/core/remote/client.rb:187:in `block (2 levels) in register_receivers') remote config change: #<Datadog::Core::Remote::Configuration::Path:0x00000001066225f8 @source="datadog", @org_id=603646, @product="ASM_DATA", @config_id="blocked_users", @name="config">
D, [2023-03-21T10:18:10.338312 #29926] DEBUG -- ddtrace: [ddtrace] (/Users/lloeki/Source/github.com/DataDog/dd-trace-rb-alt/lib/datadog/core/remote/client.rb:187:in `block (2 levels) in register_receivers') remote config change: #<Datadog::Core::Remote::Configuration::Path:0x00000001066223c8 @source="employee", @org_id=nil, @product="ASM_DD", @config_id="16.recommended.json", @name="config">
D, [2023-03-21T10:18:10.338326 #29926] DEBUG -- ddtrace: [ddtrace] (/Users/lloeki/Source/github.com/DataDog/dd-trace-rb-alt/lib/datadog/core/remote/client.rb:187:in `block (2 levels) in register_receivers') remote config change: #<Datadog::Core::Remote::Configuration::Path:0x0000000106622148 @source="datadog", @org_id=603646, @product="ASM", @config_id="blocking", @name="config">
D, [2023-03-21T10:18:10.338392 #29926] DEBUG -- ddtrace: [ddtrace] (/Users/lloeki/Source/github.com/DataDog/dd-trace-rb-alt/lib/datadog/core/remote/client.rb:187:in `block (2 levels) in register_receivers') remote config change: #<Datadog::Core::Remote::Configuration::Path:0x0000000106621950 @source="datadog", @org_id=603646, @product="ASM", @config_id="exclusion_filters", @name="config">
D, [2023-03-21T10:18:10.338406 #29926] DEBUG -- ddtrace: [ddtrace] (/Users/lloeki/Source/github.com/DataDog/dd-trace-rb-alt/lib/datadog/core/remote/client.rb:187:in `block (2 levels) in register_receivers') remote config change: #<Datadog::Core::Remote::Configuration::Path:0x00000001066202d0 @source="datadog", @org_id=603646, @product="ASM_DATA", @config_id="blocked_ips", @name="config">

Go in the DD Application Security UI and add a new IP to the list. Wait a bit. This should pop up:

D, [2023-03-21T10:20:50.616185 #29926] DEBUG -- ddtrace: [ddtrace] (/Users/lloeki/Source/github.com/DataDog/dd-trace-rb-alt/lib/datadog/core/remote/client.rb:187:in `block (2 levels) in register_receivers') remote config change: #<Datadog::Core::Remote::Configuration::Path:0x0000000106b17f68 @source="datadog", @org_id=603646, @product="ASM_DATA", @config_id="blocked_ips", @name="config">

@github-actions github-actions bot added the core Involves Datadog core libraries label Mar 21, 2023
@lloeki lloeki force-pushed the add-remote-config-changeset branch from 904ca43 to 8c7212d Compare March 21, 2023 10:28
@lloeki lloeki force-pushed the add-remote-config-dispatcher branch from 64ca007 to d32c2a1 Compare March 21, 2023 10:29
@ivoanjo
Copy link
Member

ivoanjo commented Mar 21, 2023

Minor note, just in case: Be careful not to add too noisy debug logs. They are indeed for us, but often we tell customers to enable DD_TRACE_DEBUG=true when investigating issues, so it's best if that mode doesn't add a torrent of extra logs ;)

@lloeki lloeki force-pushed the add-remote-config-changeset branch from 8c7212d to aa89610 Compare March 21, 2023 13:37
@lloeki lloeki force-pushed the add-remote-config-dispatcher branch from d32c2a1 to d564501 Compare March 21, 2023 13:37
@GustavoCaso GustavoCaso force-pushed the add-remote-config-dispatcher branch 2 times, most recently from af361fa to 9fc092d Compare March 21, 2023 16:38
@GustavoCaso GustavoCaso force-pushed the add-remote-config-changeset branch 2 times, most recently from 9692f2e to 7ccbbb1 Compare March 22, 2023 10:34
Base automatically changed from add-remote-config-changeset to master March 22, 2023 13:51
@GustavoCaso GustavoCaso marked this pull request as ready for review March 22, 2023 16:00
@GustavoCaso GustavoCaso requested a review from a team March 22, 2023 16:00
Comment on lines +143 to +151
[instance_of(Datadog::Core::Remote::Configuration::Repository::Change::Inserted)]
)

dispatcher.dispatch(changes, repository)
end
end
end

describe Datadog::Core::Remote::Dispatcher::Matcher::Product do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note but... I::Think::We're::Getting::A::Bit::Too::Deep::With::All::The::Namespacing. Consider flattening things a bit maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super fair point.

I think we can have a cleanup PR once all the code has landed in master

@GustavoCaso GustavoCaso merged commit e16beae into master Mar 23, 2023
@GustavoCaso GustavoCaso deleted the add-remote-config-dispatcher branch March 23, 2023 12:18
@github-actions github-actions bot added this to the 1.11.0 milestone Mar 23, 2023
@lloeki lloeki modified the milestones: 1.11.0, 1.11.0.beta1 Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants