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 changeset #2696

Merged
merged 4 commits into from
Mar 22, 2023
Merged

Conversation

lloeki
Copy link
Contributor

@lloeki lloeki commented Mar 16, 2023

What does this PR do?

Add a reporting of which paths were touched, what the content was before and what it is after the transaction.

Motivation

Remote configuration.

Contrary to transactions which are a sequential list of operations to apply in order, for mutative usage internal to the repository, a changeset is a report of state change, for a consumer external to the repository (more precisely the upcoming dispatcher).

Additional Notes

Using an Array-based ContentList may not be the most optimal data structure. I am considering changing it to a Hash-based ContentMap instead in the future. Nonetheless, ContentList does the job for this PR.

How to test the change?

  require 'datadog/core/remote/configuration/path'
  require 'datadog/core/remote/configuration/target'
  require 'datadog/core/remote/configuration/content'

  path2 = Datadog::Core::Remote::Configuration::Path.parse('datadog/42/PRODUCT/bar/config')
  content2 = Datadog::Core::Remote::Configuration::Content.parse({path: 'datadog/42/PRODUCT/bar/config', content: StringIO.new('Lorem ipsum')})
  target2 = Datadog::Core::Remote::Configuration::Target.parse({'length' => 11, 'hashes' => {'sha256' => 'a9a66978f378456c818fb8a3e7c6ad3d2c83e62724ccbdea7b36253fb8df5edd'}})
  content3 = Datadog::Core::Remote::Configuration::Content.parse({path: 'datadog/42/PRODUCT/foo/config', content: StringIO.new('dolor sit amet')})
  target3 = Datadog::Core::Remote::Configuration::Target.parse({'length' => 11, 'hashes' => {'sha256' => 'aa8311d08b68a5fdda55ad0947fff3c5a4b2397f5f766e9c9a79f4a5486c633c'}})

  require 'datadog/core/remote/configuration/repository'

  repository = Datadog::Core::Remote::Configuration::Repository.new

  changes = repository.transaction do |repo, txn|
    txn.insert(path, target, content) # new => change
    txn.insert(path2, target2, content2) # new => change
    txn.set(targets_version: 42) # no path touched  => no change
    txn.update(path, target3, content3) # different => change
  end

  changes # should have 2 inserts, with content2 and content3

  changes = repository.transaction do |repo, txn|
    txn.update(path, target, content) # new => change
    txn.insert(path2, target2, content2) # already there => no change
  end

  changes # should have 1 update

  changes = repository.transaction do |repo, txn|
    txn.delete(path) # exists => change
  end

  changes # should have 1 delete

  changes = repository.transaction do |repo, txn|
    txn.delete(path) # absent => no change
  end
 
  changes # should have no delete

@github-actions github-actions bot added the core Involves Datadog core libraries label Mar 16, 2023
@lloeki lloeki force-pushed the add-remote-config-changeset branch from 8950105 to 904ca43 Compare March 20, 2023 15:45
@lloeki lloeki force-pushed the add-remote-config-component branch from 5b0d4d0 to 6fbc961 Compare March 21, 2023 10:27
@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-component branch from 6fbc961 to 1bf6a5d Compare March 21, 2023 13:37
@lloeki lloeki force-pushed the add-remote-config-changeset branch from 8c7212d to aa89610 Compare March 21, 2023 13:37
Base automatically changed from add-remote-config-component to master March 22, 2023 10:10
@codecov-commenter
Copy link

Codecov Report

Merging #2696 (7ccbbb1) into master (e0f9564) will increase coverage by 0.00%.
The diff coverage is 99.09%.

@@           Coverage Diff           @@
##           master    #2696   +/-   ##
=======================================
  Coverage   98.05%   98.06%           
=======================================
  Files        1208     1208           
  Lines       66246    66340   +94     
  Branches     2961     2969    +8     
=======================================
+ Hits        64960    65056   +96     
+ Misses       1286     1284    -2     
Impacted Files Coverage Δ
...ib/datadog/core/remote/configuration/repository.rb 99.21% <97.95%> (-0.79%) ⬇️
lib/datadog/core/remote/configuration/content.rb 100.00% <100.00%> (ø)
.../datadog/core/remote/configuration/content_spec.rb 100.00% <100.00%> (ø)
...adog/core/remote/configuration/respository_spec.rb 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@GustavoCaso GustavoCaso marked this pull request as ready for review March 22, 2023 11:38
@GustavoCaso GustavoCaso requested a review from a team March 22, 2023 11:38
@GustavoCaso GustavoCaso merged commit c53f31f into master Mar 22, 2023
@GustavoCaso GustavoCaso deleted the add-remote-config-changeset branch March 22, 2023 13:51
@github-actions github-actions bot added this to the 1.11.0 milestone Mar 22, 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