Module: Datadog::CI::Configuration::Settings

Defined in:
lib/datadog/ci/configuration/settings.rb

Overview

Adds CI behavior to ddtrace settings

Constant Summary collapse

InvalidIntegrationError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.add_settings!(base) ⇒ Object



18
19
20
21
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
58
59
60
61
62
63
64
65
66
67
68
69
70
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/datadog/ci/configuration/settings.rb', line 18

def self.add_settings!(base)
  base.class_eval do
    settings :ci do
      option :enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_MODE_ENABLED
        o.default false
      end

      option :test_session_name do |o|
        o.type :string, nilable: true
        o.env CI::Ext::Settings::ENV_TEST_SESSION_NAME
      end

      option :agentless_mode_enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_AGENTLESS_MODE_ENABLED
        o.default false
      end

      option :agentless_url do |o|
        o.type :string, nilable: true
        o.env CI::Ext::Settings::ENV_AGENTLESS_URL
      end

      option :force_test_level_visibility do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_FORCE_TEST_LEVEL_VISIBILITY
        o.default false
      end

      option :experimental_test_suite_level_visibility_enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_EXPERIMENTAL_TEST_SUITE_LEVEL_VISIBILITY_ENABLED
        o.default false
        o.after_set do |value|
          if value
            Datadog::Core.log_deprecation do
              "The experimental_test_suite_level_visibility_enabled setting has no effect and will be removed in 2.0. " \
                "Test suite level visibility is now enabled by default. " \
                "If you want to disable test suite level visibility set configuration.ci.force_test_level_visibility = true."
            end
          end
        end
      end

      option :itr_enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_ITR_ENABLED
        o.default true
      end

      option :git_metadata_upload_enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_GIT_METADATA_UPLOAD_ENABLED
        o.default true
      end

      option :itr_code_coverage_excluded_bundle_path do |o|
        o.type :string, nilable: true
        o.env CI::Ext::Settings::ENV_ITR_CODE_COVERAGE_EXCLUDED_BUNDLE_PATH
        o.default do
          Datadog::CI::Utils::Bundle.location
        end
      end

      option :itr_code_coverage_use_single_threaded_mode do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_ITR_CODE_COVERAGE_USE_SINGLE_THREADED_MODE
        o.default false
      end

      option :itr_test_impact_analysis_use_allocation_tracing do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_ITR_TEST_IMPACT_ANALYSIS_USE_ALLOCATION_TRACING
        o.default true
      end

      option :retry_failed_tests_enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_RETRY_FAILED_TESTS_ENABLED
        o.default true
      end

      option :retry_failed_tests_max_attempts do |o|
        o.type :int
        o.env CI::Ext::Settings::ENV_RETRY_FAILED_TESTS_MAX_ATTEMPTS
        o.default 5
      end

      option :retry_failed_tests_total_limit do |o|
        o.type :int
        o.env CI::Ext::Settings::ENV_RETRY_FAILED_TESTS_TOTAL_LIMIT
        o.default 1000
      end

      option :retry_new_tests_enabled do |o|
        o.type :bool
        o.env CI::Ext::Settings::ENV_RETRY_NEW_TESTS_ENABLED
        o.default true
      end

      # internal only
      option :discard_traces do |o|
        o.type :bool
        o.default false
      end

      define_method(:instrument) do |integration_name, options = {}, &block|
        return unless enabled

        integration = fetch_integration(integration_name)
        integration.configure(options, &block)

        return unless integration.enabled

        patch_results = integration.patch
        next if patch_results == true

        error_message = <<-ERROR
          Available?: #{patch_results[:available]}, Loaded?: #{patch_results[:loaded]},
          Compatible?: #{patch_results[:compatible]}, Patchable?: #{patch_results[:patchable]}"
        ERROR
        Datadog.logger.warn("Unable to patch #{integration_name} (#{error_message})")
      end

      define_method(:[]) do |integration_name|
        fetch_integration(integration_name).configuration
      end

      option :trace_flush

      option :writer_options do |o|
        o.type :hash
        o.default({})
      end

      define_method(:fetch_integration) do |name|
        Datadog::CI::Contrib::Integration.registry[name] ||
          raise(InvalidIntegrationError, "'#{name}' is not a valid integration.")
      end
    end
  end
end

.extended(base) ⇒ Object



13
14
15
16
# File 'lib/datadog/ci/configuration/settings.rb', line 13

def self.extended(base)
  base = base.singleton_class unless base.is_a?(Class)
  add_settings!(base)
end