Class: Datadog::CI::Remote::Component

Inherits:
Object
  • Object
show all
Includes:
Utils::Stateful
Defined in:
lib/datadog/ci/remote/component.rb

Overview

Remote configuration component. Responsible for fetching library settings and configuring the library accordingly.

Constant Summary collapse

FILE_STORAGE_KEY =
"remote_component_state"

Instance Method Summary collapse

Methods included from Utils::Stateful

#load_component_state, #load_json, #store_component_state

Constructor Details

#initialize(library_settings_client:, test_discovery_enabled: false) ⇒ Component

Returns a new instance of Component.



17
18
19
20
# File 'lib/datadog/ci/remote/component.rb', line 17

def initialize(library_settings_client:, test_discovery_enabled: false)
  @library_settings_client = library_settings_client
  @test_discovery_enabled = test_discovery_enabled
end

Instance Method Details

#configure(test_session) ⇒ Object

called on test session start, uses test session info to send configuration request to the backend



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/datadog/ci/remote/component.rb', line 23

def configure(test_session)
  fetch_library_configuration(test_session)

  # configure different components in parallel because they might block on HTTP requests
  configuration_workers = [
    Worker.new { test_optimisation.configure(@library_configuration, test_session) },
    Worker.new { test_retries.configure(@library_configuration, test_session) },
    Worker.new { test_visibility.configure(@library_configuration, test_session) },
    Worker.new { test_management.configure(@library_configuration, test_session) },
    Worker.new { impacted_tests_detection.configure(@library_configuration, test_session) },
    Worker.new { code_coverage.configure(@library_configuration) }
  ]

  # launch configuration workers
  configuration_workers.each(&:perform)

  # block until all workers are done
  configuration_workers.each(&:wait_until_done)
end

#restore_state(state) ⇒ Object



50
51
52
# File 'lib/datadog/ci/remote/component.rb', line 50

def restore_state(state)
  @library_configuration = state[:library_configuration]
end

#restore_state_from_datadog_test_runnerObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/datadog/ci/remote/component.rb', line 58

def restore_state_from_datadog_test_runner
  Datadog.logger.debug { "Restoring library configuration from DDTest cache" }

  settings = load_json(Ext::DDTest::SETTINGS_FILE_NAME)
  if settings.nil?
    Datadog.logger.debug { "Restoring library configuration failed, will request again" }
    return false
  end

  Datadog.logger.debug { "Restored library configuration from DDTest: #{settings}" }
  @library_configuration = LibrarySettings.from_json(settings)
  true
end

#serialize_stateObject

Implementation of Stateful interface



44
45
46
47
48
# File 'lib/datadog/ci/remote/component.rb', line 44

def serialize_state
  {
    library_configuration: @library_configuration
  }
end

#storage_keyObject



54
55
56
# File 'lib/datadog/ci/remote/component.rb', line 54

def storage_key
  FILE_STORAGE_KEY
end