-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from DataDog/anmarchenko/remote_configuration…
…_component [SDTEST-172] Remote configuration component
- Loading branch information
Showing
19 changed files
with
415 additions
and
223 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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Remote | ||
# Remote configuration component. | ||
# Responsible for fetching library settings and configuring the library accordingly. | ||
class Component | ||
def initialize(library_settings_client:) | ||
@library_settings_client = library_settings_client | ||
end | ||
|
||
# called on test session start, uses test session info to send configuration request to the backend | ||
def configure(test_session) | ||
library_configuration = @library_settings_client.fetch(test_session) | ||
# sometimes we can skip code coverage for default branch if there are no changes in the repository | ||
# backend needs git metadata uploaded for this test session to check if we can skip code coverage | ||
if library_configuration.require_git? | ||
Datadog.logger.debug { "Library configuration endpoint requires git upload to be finished, waiting..." } | ||
git_tree_upload_worker.wait_until_done | ||
|
||
Datadog.logger.debug { "Requesting library configuration again..." } | ||
library_configuration = @library_settings_client.fetch(test_session) | ||
|
||
if library_configuration.require_git? | ||
Datadog.logger.debug { "git metadata upload did not complete in time when configuring library" } | ||
end | ||
end | ||
|
||
test_optimisation.configure(library_configuration, test_session) | ||
end | ||
|
||
private | ||
|
||
def test_optimisation | ||
Datadog.send(:components).test_optimisation | ||
end | ||
|
||
def git_tree_upload_worker | ||
Datadog.send(:components).git_tree_upload_worker | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
require_relative "../ext/telemetry" | ||
require_relative "../ext/transport" | ||
require_relative "../transport/telemetry" | ||
require_relative "../utils/parsing" | ||
|
||
module Datadog | ||
module CI | ||
module Remote | ||
# Wrapper around the settings HTTP response | ||
class LibrarySettings | ||
def initialize(http_response) | ||
@http_response = http_response | ||
@json = nil | ||
end | ||
|
||
def ok? | ||
resp = @http_response | ||
!resp.nil? && resp.ok? | ||
end | ||
|
||
def payload | ||
cached = @json | ||
return cached unless cached.nil? | ||
|
||
resp = @http_response | ||
return @json = default_payload if resp.nil? || !ok? | ||
|
||
begin | ||
@json = JSON.parse(resp.payload).dig(*Ext::Transport::DD_API_SETTINGS_RESPONSE_DIG_KEYS) || | ||
default_payload | ||
rescue JSON::ParserError => e | ||
Datadog.logger.error("Failed to parse settings response payload: #{e}. Payload was: #{resp.payload}") | ||
|
||
Transport::Telemetry.api_requests_errors( | ||
Ext::Telemetry::METRIC_GIT_REQUESTS_SETTINGS_ERRORS, | ||
1, | ||
error_type: "invalid_json", | ||
status_code: nil | ||
) | ||
|
||
@json = default_payload | ||
end | ||
end | ||
|
||
def require_git? | ||
return @require_git if defined?(@require_git) | ||
|
||
@require_git = bool(Ext::Transport::DD_API_SETTINGS_RESPONSE_REQUIRE_GIT_KEY) | ||
end | ||
|
||
def itr_enabled? | ||
return @itr_enabled if defined?(@itr_enabled) | ||
|
||
@itr_enabled = bool(Ext::Transport::DD_API_SETTINGS_RESPONSE_ITR_ENABLED_KEY) | ||
end | ||
|
||
def code_coverage_enabled? | ||
return @code_coverage_enabled if defined?(@code_coverage_enabled) | ||
|
||
@code_coverage_enabled = bool(Ext::Transport::DD_API_SETTINGS_RESPONSE_CODE_COVERAGE_KEY) | ||
end | ||
|
||
def tests_skipping_enabled? | ||
return @tests_skipping_enabled if defined?(@tests_skipping_enabled) | ||
|
||
@tests_skipping_enabled = bool(Ext::Transport::DD_API_SETTINGS_RESPONSE_TESTS_SKIPPING_KEY) | ||
end | ||
|
||
private | ||
|
||
def bool(key) | ||
Utils::Parsing.convert_to_bool(payload.fetch(key, false)) | ||
end | ||
|
||
def default_payload | ||
Ext::Transport::DD_API_SETTINGS_RESPONSE_DEFAULT | ||
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
Oops, something went wrong.