-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../core/remote/dispatcher' | ||
|
||
module Datadog | ||
module Tracing | ||
# Remote configuration declaration | ||
module Remote | ||
class ReadError < StandardError; end | ||
|
||
class << self | ||
PRODUCT = 'APM_LIBRARY' | ||
|
||
def products | ||
[PRODUCT] | ||
end | ||
|
||
def capabilities | ||
[] | ||
end | ||
|
||
def receivers | ||
receiver do |repository, _changes| | ||
config = [] | ||
|
||
# DEV: Filter our by product. Given it will be very common | ||
# DEV: we can filter this out before we receive the data in this method. | ||
# DEV: Apply this refactor to AppSec as well if implemented. | ||
repository.contents.each do |content| | ||
case content.path.product | ||
when PRODUCT | ||
config << parse_content(content) | ||
end | ||
end | ||
|
||
# TODO: Make the magic happen! | ||
# Tracing::Component.reconfigure(config) | ||
end | ||
end | ||
|
||
def receiver(products = [PRODUCT], &block) | ||
matcher = Core::Remote::Dispatcher::Matcher::Product.new(products) | ||
[Core::Remote::Dispatcher::Receiver.new(matcher) do |repository, changes| | ||
changes.each do |change| | ||
Datadog.logger.debug { "remote config change: '#{change.path}'" } | ||
end | ||
yield(repository, changes) | ||
end] | ||
end | ||
|
||
private | ||
|
||
def parse_content(content) | ||
data = content.data.read | ||
|
||
content.data.rewind | ||
|
||
raise ReadError, 'EOF reached' if data.nil? | ||
|
||
JSON.parse(data) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.