-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce Datadog::CI::Contrib::Instrumentation module to extract the…
… logic from Settings
- Loading branch information
1 parent
a0b41cc
commit 4905314
Showing
5 changed files
with
51 additions
and
23 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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Instrumentation | ||
class InvalidIntegrationError < StandardError; end | ||
|
||
def self.instrument(integration_name, options = {}, &block) | ||
integration = fetch_integration(integration_name) | ||
integration.configure(options, &block) | ||
|
||
return unless integration.enabled | ||
|
||
patch_results = integration.patch | ||
return if patch_results == true | ||
|
||
error_message = <<-ERROR | ||
Available?: #{patch_results[:available]}, Loaded?: #{patch_results[:loaded]}, | ||
Compatible?: #{patch_results[:compatible]}, Patchable?: #{patch_results[:patchable]}" | ||
ERROR | ||
Datadog.logger.warn("Unable to patch #{integration_name} (#{error_message})") | ||
end | ||
|
||
def self.fetch_integration(name) | ||
Datadog::CI::Contrib::Integration.registry[name] || | ||
raise(InvalidIntegrationError, "'#{name}' is not a valid integration.") | ||
end | ||
end | ||
end | ||
end | ||
end |
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,14 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Instrumentation | ||
class InvalidIntegrationError < StandardError | ||
end | ||
|
||
def self.instrument: (Symbol integration_name, ?::Hash[untyped, untyped] options) { (?) -> untyped } -> void | ||
|
||
def self.fetch_integration: (Symbol name) -> untyped | ||
end | ||
end | ||
end | ||
end |
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