Class: Datadog::CI::TestManagement::TestsProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/test_management/tests_properties.rb

Overview

fetches and stores a map of tests to their test management properties from the backend

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(api: nil) ⇒ TestsProperties

Returns a new instance of TestsProperties.



81
82
83
# File 'lib/datadog/ci/test_management/tests_properties.rb', line 81

def initialize(api: nil)
  @api = api
end

Instance Method Details

#fetch(test_session) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/datadog/ci/test_management/tests_properties.rb', line 85

def fetch(test_session)
  api = @api
  return {} unless api

  request_payload = payload(test_session)
  Datadog.logger.debug("Fetching test management tests with request: #{request_payload}")

  http_response = api.api_request(
    path: Ext::Transport::DD_API_TEST_MANAGEMENT_TESTS_PATH,
    payload: request_payload
  )

  CI::Transport::Telemetry.api_requests(
    Ext::Telemetry::METRIC_TEST_MANAGEMENT_TESTS_REQUEST,
    1,
    compressed: http_response.request_compressed
  )
  Utils::Telemetry.distribution(Ext::Telemetry::METRIC_TEST_MANAGEMENT_TESTS_REQUEST_MS, http_response.duration_ms)
  Utils::Telemetry.distribution(
    Ext::Telemetry::METRIC_TEST_MANAGEMENT_TESTS_RESPONSE_BYTES,
    http_response.response_size.to_f,
    {Ext::Telemetry::TAG_RESPONSE_COMPRESSED => http_response.gzipped_content?.to_s}
  )

  unless http_response.ok?
    CI::Transport::Telemetry.api_requests_errors(
      Ext::Telemetry::METRIC_TEST_MANAGEMENT_TESTS_REQUEST_ERRORS,
      1,
      error_type: http_response.telemetry_error_type,
      status_code: http_response.code
    )

    # mark the test session so that all events emitted in this session are tagged
    # with the hidden _dd.ci.library_configuration_error.test_management_tests tag
    test_session.set_tag(Ext::Test::LibraryConfigurationError::TAG_TEST_MANAGEMENT_TESTS, "true")
  end

  Response.from_http_response(http_response).tests
end