Class: Datadog::CI::Transport::RemoteSettingsApi

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/transport/remote_settings_api.rb

Overview

Datadog API client Calls settings endpoint to fetch library settings for given service and env

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(dd_env:, api: nil, config_tags: {}) ⇒ RemoteSettingsApi

Returns a new instance of RemoteSettingsApi.



65
66
67
68
69
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 65

def initialize(dd_env:, api: nil, config_tags: {})
  @api = api
  @dd_env = dd_env
  @config_tags = config_tags || {}
end

Instance Method Details

#fetch_library_settings(test_session) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
# File 'lib/datadog/ci/transport/remote_settings_api.rb', line 71

def fetch_library_settings(test_session)
  api = @api
  return Response.new(nil) unless api

  request_payload = payload(test_session)
  Datadog.logger.debug("Fetching library settings with request: #{request_payload}")

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

  Transport::Telemetry.api_requests(
    Ext::Telemetry::METRIC_GIT_REQUESTS_SETTINGS,
    1,
    compressed: http_response.request_compressed
  )
  Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_REQUESTS_SETTINGS_MS, http_response.duration_ms)

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

  response = Response.new(http_response)

  Utils::Telemetry.inc(
    Ext::Telemetry::METRIC_GIT_REQUESTS_SETTINGS_RESPONSE,
    1,
    {
      Ext::Telemetry::TAG_COVERAGE_ENABLED => response.payload[Ext::Transport::DD_API_SETTINGS_RESPONSE_CODE_COVERAGE_KEY],
      Ext::Telemetry::TAG_ITR_SKIP_ENABLED => response.payload[Ext::Transport::DD_API_SETTINGS_RESPONSE_TESTS_SKIPPING_KEY]
    }
  )

  response
end