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, #store_component_state

Constructor Details

#initialize(library_settings_client:) ⇒ Component

Returns a new instance of Component.



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

def initialize(library_settings_client:)
  @library_settings_client = library_settings_client
  @library_configuration = nil
end

Instance Method Details

#configure(test_session) ⇒ Object

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/datadog/ci/remote/component.rb', line 22

def configure(test_session)
  # If component state is loaded successfully, skip fetching library configuration
  unless load_component_state
    @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

    # Store component state for distributed test runs
    store_component_state if test_session.distributed
  end

  # 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) }
  ]

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

  # block until all workers are done (or 60 seconds has passed)
  configuration_workers.each(&:wait_until_done)
end

#restore_state(state) ⇒ Object



66
67
68
# File 'lib/datadog/ci/remote/component.rb', line 66

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

#serialize_stateObject

Implementation of Stateful interface



60
61
62
63
64
# File 'lib/datadog/ci/remote/component.rb', line 60

def serialize_state
  {
    library_configuration: @library_configuration
  }
end

#storage_keyObject



70
71
72
# File 'lib/datadog/ci/remote/component.rb', line 70

def storage_key
  FILE_STORAGE_KEY
end