-
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.
Merge pull request #51 from DataDog/anmarchenko/introduce_api_concept
[CIVIS-2467] Support test visibility protocol via Datadog Agent with EVP proxy
- Loading branch information
Showing
22 changed files
with
674 additions
and
138 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
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,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../ext/transport" | ||
|
||
module Datadog | ||
module CI | ||
module Transport | ||
module Api | ||
class Base | ||
attr_reader :http | ||
|
||
def initialize(http:) | ||
@http = http | ||
end | ||
|
||
def request(path:, payload:, verb: "post") | ||
http.request( | ||
path: path, | ||
payload: payload, | ||
verb: verb, | ||
headers: headers | ||
) | ||
end | ||
|
||
private | ||
|
||
def headers | ||
{ | ||
Ext::Transport::HEADER_CONTENT_TYPE => Ext::Transport::CONTENT_TYPE_MESSAGEPACK | ||
} | ||
end | ||
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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "ci_test_cycle" | ||
require_relative "evp_proxy" | ||
require_relative "../http" | ||
require_relative "../../ext/transport" | ||
|
||
module Datadog | ||
module CI | ||
module Transport | ||
module Api | ||
module Builder | ||
def self.build_ci_test_cycle_api(settings) | ||
dd_site = settings.site || Ext::Transport::DEFAULT_DD_SITE | ||
url = settings.ci.agentless_url || | ||
"https://#{Ext::Transport::TEST_VISIBILITY_INTAKE_HOST_PREFIX}.#{dd_site}:443" | ||
|
||
uri = URI.parse(url) | ||
raise "Invalid agentless mode URL: #{url}" if uri.host.nil? | ||
|
||
http = Datadog::CI::Transport::HTTP.new( | ||
host: uri.host, | ||
port: uri.port, | ||
ssl: uri.scheme == "https" || uri.port == 443, | ||
compress: true | ||
) | ||
|
||
CiTestCycle.new(api_key: settings.api_key, http: http) | ||
end | ||
|
||
def self.build_evp_proxy_api(agent_settings) | ||
http = Datadog::CI::Transport::HTTP.new( | ||
host: agent_settings.hostname, | ||
port: agent_settings.port, | ||
ssl: agent_settings.ssl, | ||
timeout: agent_settings.timeout_seconds, | ||
compress: false | ||
) | ||
|
||
EvpProxy.new(http: http) | ||
end | ||
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,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "base" | ||
require_relative "../../ext/transport" | ||
|
||
module Datadog | ||
module CI | ||
module Transport | ||
module Api | ||
class CiTestCycle < Base | ||
attr_reader :api_key | ||
|
||
def initialize(api_key:, http:) | ||
@api_key = api_key | ||
|
||
super(http: http) | ||
end | ||
|
||
private | ||
|
||
def headers | ||
headers = super | ||
headers[Ext::Transport::HEADER_DD_API_KEY] = api_key | ||
headers | ||
end | ||
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/core/environment/container" | ||
|
||
require_relative "base" | ||
require_relative "../../ext/transport" | ||
|
||
module Datadog | ||
module CI | ||
module Transport | ||
module Api | ||
class EvpProxy < Base | ||
def request(path:, payload:, verb: "post") | ||
path = "#{Ext::Transport::EVP_PROXY_PATH_PREFIX}#{path.sub(/^\//, "")}" | ||
|
||
super( | ||
path: path, | ||
payload: payload, | ||
verb: verb | ||
) | ||
end | ||
|
||
private | ||
|
||
def container_id | ||
return @container_id if defined?(@container_id) | ||
|
||
@container_id = Datadog::Core::Environment::Container.container_id | ||
end | ||
|
||
def headers | ||
headers = super | ||
headers[Ext::Transport::HEADER_EVP_SUBDOMAIN] = Ext::Transport::TEST_VISIBILITY_INTAKE_HOST_PREFIX | ||
|
||
c_id = container_id | ||
headers[Ext::Transport::HEADER_CONTAINER_ID] = c_id unless c_id.nil? | ||
|
||
headers | ||
end | ||
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.