ddtrace 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (364) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +125 -1
  3. data/README.md +8 -10
  4. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +110 -18
  5. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +26 -3
  6. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +3 -0
  7. data/lib/datadog/appsec/component.rb +40 -6
  8. data/lib/datadog/appsec/configuration/settings.rb +20 -4
  9. data/lib/datadog/appsec/configuration.rb +8 -0
  10. data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -0
  11. data/lib/datadog/appsec/contrib/configuration/settings.rb +2 -0
  12. data/lib/datadog/appsec/contrib/integration.rb +2 -0
  13. data/lib/datadog/appsec/contrib/patcher.rb +2 -0
  14. data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +2 -0
  15. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +4 -15
  16. data/lib/datadog/appsec/contrib/rack/gateway/response.rb +1 -1
  17. data/lib/datadog/appsec/contrib/rack/patcher.rb +2 -0
  18. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +6 -0
  19. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +17 -4
  20. data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +2 -0
  21. data/lib/datadog/appsec/contrib/rails/framework.rb +2 -0
  22. data/lib/datadog/appsec/contrib/rails/gateway/request.rb +1 -1
  23. data/lib/datadog/appsec/contrib/rails/request.rb +2 -0
  24. data/lib/datadog/appsec/contrib/rails/request_middleware.rb +2 -0
  25. data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +2 -0
  26. data/lib/datadog/appsec/contrib/sinatra/framework.rb +2 -0
  27. data/lib/datadog/appsec/contrib/sinatra/gateway/route_params.rb +1 -1
  28. data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +2 -0
  29. data/lib/datadog/appsec/extensions.rb +2 -0
  30. data/lib/datadog/appsec/instrumentation/gateway/argument.rb +2 -4
  31. data/lib/datadog/appsec/processor/rule_loader.rb +63 -0
  32. data/lib/datadog/appsec/processor/rule_merger.rb +146 -0
  33. data/lib/datadog/appsec/processor.rb +15 -70
  34. data/lib/datadog/appsec/remote.rb +121 -0
  35. data/lib/datadog/appsec/utils/http.rb +2 -0
  36. data/lib/datadog/appsec/utils.rb +2 -0
  37. data/lib/datadog/appsec.rb +18 -4
  38. data/lib/datadog/ci/configuration/components.rb +2 -0
  39. data/lib/datadog/ci/configuration/settings.rb +2 -0
  40. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +2 -0
  41. data/lib/datadog/ci/contrib/cucumber/formatter.rb +2 -0
  42. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +2 -0
  43. data/lib/datadog/ci/contrib/cucumber/patcher.rb +2 -0
  44. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +2 -0
  45. data/lib/datadog/ci/contrib/rspec/patcher.rb +2 -0
  46. data/lib/datadog/ci/extensions.rb +2 -0
  47. data/lib/datadog/ci/flush.rb +2 -0
  48. data/lib/datadog/ci.rb +2 -0
  49. data/lib/datadog/core/buffer/cruby.rb +2 -0
  50. data/lib/datadog/core/buffer/random.rb +2 -0
  51. data/lib/datadog/core/buffer/thread_safe.rb +2 -0
  52. data/lib/datadog/core/chunker.rb +2 -0
  53. data/lib/datadog/core/configuration/agent_settings_resolver.rb +68 -17
  54. data/lib/datadog/core/configuration/components.rb +11 -14
  55. data/lib/datadog/core/configuration/dependency_resolver.rb +2 -0
  56. data/lib/datadog/core/configuration/option.rb +2 -0
  57. data/lib/datadog/core/configuration/option_definition.rb +2 -0
  58. data/lib/datadog/core/configuration/option_definition_set.rb +2 -0
  59. data/lib/datadog/core/configuration/option_set.rb +2 -0
  60. data/lib/datadog/core/configuration/settings.rb +70 -16
  61. data/lib/datadog/core/diagnostics/health.rb +2 -0
  62. data/lib/datadog/core/environment/class_count.rb +2 -0
  63. data/lib/datadog/core/environment/gc.rb +2 -0
  64. data/lib/datadog/core/environment/identity.rb +58 -0
  65. data/lib/datadog/core/environment/socket.rb +2 -0
  66. data/lib/datadog/core/environment/thread_count.rb +2 -0
  67. data/lib/datadog/core/environment/variable_helpers.rb +10 -2
  68. data/lib/datadog/core/environment/vm_cache.rb +2 -0
  69. data/lib/datadog/core/extensions.rb +2 -0
  70. data/lib/datadog/core/header_collection.rb +2 -0
  71. data/lib/datadog/core/metrics/helpers.rb +2 -0
  72. data/lib/datadog/core/metrics/metric.rb +2 -0
  73. data/lib/datadog/core/remote/client/capabilities.rb +57 -0
  74. data/lib/datadog/core/remote/client.rb +225 -0
  75. data/lib/datadog/core/remote/component.rb +158 -0
  76. data/lib/datadog/core/remote/configuration/content.rb +84 -0
  77. data/lib/datadog/core/remote/configuration/digest.rb +62 -0
  78. data/lib/datadog/core/remote/configuration/path.rb +90 -0
  79. data/lib/datadog/core/remote/configuration/repository.rb +292 -0
  80. data/lib/datadog/core/remote/configuration/target.rb +74 -0
  81. data/lib/datadog/core/remote/configuration.rb +18 -0
  82. data/lib/datadog/core/remote/dispatcher.rb +59 -0
  83. data/lib/datadog/core/remote/ext.rb +12 -0
  84. data/lib/datadog/core/remote/negotiation.rb +57 -0
  85. data/lib/datadog/core/remote/worker.rb +96 -0
  86. data/lib/datadog/core/remote.rb +24 -0
  87. data/lib/datadog/core/telemetry/collector.rb +8 -9
  88. data/lib/datadog/core/telemetry/heartbeat.rb +2 -0
  89. data/lib/datadog/core/telemetry/http/env.rb +2 -0
  90. data/lib/datadog/core/telemetry/http/transport.rb +2 -0
  91. data/lib/datadog/core/telemetry/v1/app_event.rb +2 -0
  92. data/lib/datadog/core/telemetry/v1/application.rb +7 -1
  93. data/lib/datadog/core/telemetry/v1/dependency.rb +7 -1
  94. data/lib/datadog/core/telemetry/v1/host.rb +9 -1
  95. data/lib/datadog/core/telemetry/v1/integration.rb +7 -1
  96. data/lib/datadog/core/telemetry/v1/product.rb +9 -1
  97. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +7 -1
  98. data/lib/datadog/core/transport/config.rb +58 -0
  99. data/lib/datadog/core/transport/http/api/instance.rb +37 -0
  100. data/lib/datadog/core/transport/http/api/spec.rb +19 -0
  101. data/lib/datadog/core/transport/http/api.rb +57 -0
  102. data/lib/datadog/core/transport/http/builder.rb +217 -0
  103. data/lib/datadog/core/transport/http/client.rb +45 -0
  104. data/lib/datadog/core/transport/http/config.rb +268 -0
  105. data/lib/datadog/core/transport/http/negotiation.rb +144 -0
  106. data/lib/datadog/core/transport/http.rb +169 -0
  107. data/lib/datadog/core/transport/negotiation.rb +60 -0
  108. data/lib/datadog/core/utils/compression.rb +2 -0
  109. data/lib/datadog/core/utils/hash.rb +32 -0
  110. data/lib/datadog/core/utils/object_set.rb +2 -0
  111. data/lib/datadog/core/utils/safe_dup.rb +20 -2
  112. data/lib/datadog/core/utils/sequence.rb +2 -0
  113. data/lib/datadog/core/utils/time.rb +2 -0
  114. data/lib/datadog/core/worker.rb +2 -0
  115. data/lib/datadog/core/workers/async.rb +6 -2
  116. data/lib/datadog/core/workers/interval_loop.rb +7 -1
  117. data/lib/datadog/core/workers/queue.rb +2 -0
  118. data/lib/datadog/core/workers/runtime_metrics.rb +2 -0
  119. data/lib/datadog/kit.rb +2 -0
  120. data/lib/datadog/opentracer/binary_propagator.rb +2 -0
  121. data/lib/datadog/opentracer/carrier.rb +2 -0
  122. data/lib/datadog/opentracer/global_tracer.rb +2 -0
  123. data/lib/datadog/opentracer/propagator.rb +2 -0
  124. data/lib/datadog/opentracer/scope.rb +2 -0
  125. data/lib/datadog/opentracer/scope_manager.rb +2 -0
  126. data/lib/datadog/opentracer/span_context.rb +2 -0
  127. data/lib/datadog/opentracer/span_context_factory.rb +2 -0
  128. data/lib/datadog/opentracer/thread_local_scope.rb +2 -0
  129. data/lib/datadog/opentracer.rb +2 -0
  130. data/lib/datadog/profiling/backtrace_location.rb +2 -0
  131. data/lib/datadog/profiling/buffer.rb +2 -0
  132. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +19 -3
  133. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +2 -0
  134. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  135. data/lib/datadog/profiling/collectors/stack.rb +2 -0
  136. data/lib/datadog/profiling/collectors/thread_context.rb +2 -2
  137. data/lib/datadog/profiling/component.rb +103 -29
  138. data/lib/datadog/profiling/event.rb +2 -0
  139. data/lib/datadog/profiling/events/stack.rb +2 -0
  140. data/lib/datadog/profiling/ext.rb +28 -26
  141. data/lib/datadog/profiling/flush.rb +2 -0
  142. data/lib/datadog/profiling/native_extension.rb +2 -0
  143. data/lib/datadog/profiling/pprof/message_set.rb +2 -0
  144. data/lib/datadog/profiling/pprof/payload.rb +2 -0
  145. data/lib/datadog/profiling/pprof/string_table.rb +2 -0
  146. data/lib/datadog/profiling/preload.rb +2 -0
  147. data/lib/datadog/profiling/scheduler.rb +3 -1
  148. data/lib/datadog/profiling/stack_recorder.rb +0 -18
  149. data/lib/datadog/profiling/tag_builder.rb +2 -0
  150. data/lib/datadog/profiling/tasks/setup.rb +0 -26
  151. data/lib/datadog/profiling.rb +2 -1
  152. data/lib/datadog/tracing/analytics.rb +2 -0
  153. data/lib/datadog/tracing/configuration/ext.rb +7 -0
  154. data/lib/datadog/tracing/configuration/settings.rb +14 -0
  155. data/lib/datadog/tracing/context.rb +2 -0
  156. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +2 -0
  157. data/lib/datadog/tracing/contrib/action_cable/event.rb +2 -0
  158. data/lib/datadog/tracing/contrib/action_cable/events.rb +2 -0
  159. data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -0
  160. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +2 -0
  161. data/lib/datadog/tracing/contrib/action_mailer/event.rb +2 -0
  162. data/lib/datadog/tracing/contrib/action_mailer/events.rb +2 -0
  163. data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -0
  164. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -24
  165. data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -0
  166. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +14 -1
  167. data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -0
  168. data/lib/datadog/tracing/contrib/action_view/event.rb +2 -0
  169. data/lib/datadog/tracing/contrib/action_view/events.rb +2 -0
  170. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +2 -0
  171. data/lib/datadog/tracing/contrib/active_job/event.rb +2 -0
  172. data/lib/datadog/tracing/contrib/active_job/events.rb +2 -0
  173. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +2 -0
  174. data/lib/datadog/tracing/contrib/active_job/patcher.rb +2 -0
  175. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +2 -0
  176. data/lib/datadog/tracing/contrib/active_model_serializers/event.rb +2 -0
  177. data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +2 -0
  178. data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +2 -0
  179. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +8 -1
  180. data/lib/datadog/tracing/contrib/active_record/event.rb +2 -0
  181. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -1
  182. data/lib/datadog/tracing/contrib/active_record/events.rb +2 -0
  183. data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -0
  184. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +6 -2
  185. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +2 -0
  186. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -0
  187. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +2 -0
  188. data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +2 -0
  189. data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +2 -0
  190. data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -0
  191. data/lib/datadog/tracing/contrib/analytics.rb +2 -0
  192. data/lib/datadog/tracing/contrib/auto_instrument.rb +2 -0
  193. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +9 -1
  194. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +8 -1
  195. data/lib/datadog/tracing/contrib/aws/patcher.rb +2 -0
  196. data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +2 -0
  197. data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +2 -0
  198. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +2 -0
  199. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +2 -0
  200. data/lib/datadog/tracing/contrib/configurable.rb +2 -0
  201. data/lib/datadog/tracing/contrib/configuration/resolver.rb +2 -0
  202. data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +2 -0
  203. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +8 -1
  204. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -1
  205. data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -0
  206. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +2 -0
  207. data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +2 -0
  208. data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +2 -0
  209. data/lib/datadog/tracing/contrib/delayed_job/server_internal_tracer/worker.rb +2 -0
  210. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +8 -1
  211. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +4 -1
  212. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +8 -1
  213. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -3
  214. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +6 -2
  215. data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -0
  216. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +8 -1
  217. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -2
  218. data/lib/datadog/tracing/contrib/excon/patcher.rb +2 -0
  219. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +8 -1
  220. data/lib/datadog/tracing/contrib/faraday/connection.rb +2 -0
  221. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -2
  222. data/lib/datadog/tracing/contrib/faraday/rack_builder.rb +2 -0
  223. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +2 -0
  224. data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -0
  225. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +2 -0
  226. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +8 -1
  227. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -2
  228. data/lib/datadog/tracing/contrib/grpc/intercept_with_datadog.rb +2 -0
  229. data/lib/datadog/tracing/contrib/grpc/patcher.rb +2 -0
  230. data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +2 -0
  231. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +2 -0
  232. data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -0
  233. data/lib/datadog/tracing/contrib/hanami/plugin.rb +2 -0
  234. data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +2 -0
  235. data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +2 -0
  236. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +2 -0
  237. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +8 -1
  238. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -2
  239. data/lib/datadog/tracing/contrib/http/integration.rb +2 -0
  240. data/lib/datadog/tracing/contrib/http/patcher.rb +2 -0
  241. data/lib/datadog/tracing/contrib/http_annotation_helper.rb +2 -0
  242. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +2 -0
  243. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +2 -0
  244. data/lib/datadog/tracing/contrib/integration.rb +2 -0
  245. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +2 -0
  246. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +2 -0
  247. data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +2 -0
  248. data/lib/datadog/tracing/contrib/kafka/event.rb +2 -0
  249. data/lib/datadog/tracing/contrib/kafka/events.rb +2 -0
  250. data/lib/datadog/tracing/contrib/kafka/patcher.rb +2 -0
  251. data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +2 -0
  252. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +2 -0
  253. data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -0
  254. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +2 -0
  255. data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +2 -0
  256. data/lib/datadog/tracing/contrib/mongodb/patcher.rb +2 -0
  257. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +2 -0
  258. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -0
  259. data/lib/datadog/tracing/contrib/mysql2/patcher.rb +2 -0
  260. data/lib/datadog/tracing/contrib/patchable.rb +2 -0
  261. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +2 -0
  262. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +2 -0
  263. data/lib/datadog/tracing/contrib/pg/patcher.rb +2 -0
  264. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +2 -0
  265. data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +2 -0
  266. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +2 -0
  267. data/lib/datadog/tracing/contrib/qless/patcher.rb +2 -0
  268. data/lib/datadog/tracing/contrib/qless/tracer_cleaner.rb +2 -0
  269. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +2 -0
  270. data/lib/datadog/tracing/contrib/racecar/event.rb +2 -0
  271. data/lib/datadog/tracing/contrib/racecar/events.rb +2 -0
  272. data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -0
  273. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +9 -2
  274. data/lib/datadog/tracing/contrib/rails/framework.rb +2 -0
  275. data/lib/datadog/tracing/contrib/rails/middlewares.rb +2 -0
  276. data/lib/datadog/tracing/contrib/rails/utils.rb +3 -1
  277. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +2 -0
  278. data/lib/datadog/tracing/contrib/rake/patcher.rb +2 -0
  279. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +2 -0
  280. data/lib/datadog/tracing/contrib/redis/tags.rb +2 -0
  281. data/lib/datadog/tracing/contrib/registerable.rb +2 -0
  282. data/lib/datadog/tracing/contrib/registry.rb +2 -0
  283. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +2 -0
  284. data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -0
  285. data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
  286. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +2 -0
  287. data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -0
  288. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
  289. data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +34 -0
  290. data/lib/datadog/tracing/contrib/roda/ext.rb +18 -0
  291. data/lib/datadog/tracing/contrib/roda/instrumentation.rb +76 -0
  292. data/lib/datadog/tracing/contrib/roda/integration.rb +45 -0
  293. data/lib/datadog/tracing/contrib/roda/patcher.rb +30 -0
  294. data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +2 -0
  295. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +3 -0
  296. data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -0
  297. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +2 -0
  298. data/lib/datadog/tracing/contrib/sequel/dataset.rb +2 -0
  299. data/lib/datadog/tracing/contrib/sequel/patcher.rb +2 -0
  300. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +2 -0
  301. data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -0
  302. data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
  303. data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +12 -3
  304. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +3 -0
  305. data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +38 -0
  306. data/lib/datadog/tracing/contrib/sidekiq/integration.rb +8 -0
  307. data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +16 -2
  308. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +11 -4
  309. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/job_fetch.rb +2 -0
  310. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/redis_info.rb +2 -0
  311. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/scheduled_poller.rb +2 -0
  312. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/stop.rb +34 -0
  313. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +18 -2
  314. data/lib/datadog/tracing/contrib/sidekiq/{tracing.rb → utils.rb} +3 -1
  315. data/lib/datadog/tracing/contrib/sinatra/headers.rb +2 -0
  316. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -0
  317. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +2 -0
  318. data/lib/datadog/tracing/contrib/span_attribute_schema.rb +28 -0
  319. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +2 -0
  320. data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +2 -0
  321. data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +2 -0
  322. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  323. data/lib/datadog/tracing/contrib.rb +3 -0
  324. data/lib/datadog/tracing/correlation.rb +10 -10
  325. data/lib/datadog/tracing/diagnostics/health.rb +2 -0
  326. data/lib/datadog/tracing/distributed/trace_context.rb +22 -15
  327. data/lib/datadog/tracing/flush.rb +2 -0
  328. data/lib/datadog/tracing/metadata/analytics.rb +2 -0
  329. data/lib/datadog/tracing/metadata/errors.rb +2 -0
  330. data/lib/datadog/tracing/metadata/ext.rb +6 -0
  331. data/lib/datadog/tracing/metadata.rb +2 -0
  332. data/lib/datadog/tracing/pipeline/span_filter.rb +2 -0
  333. data/lib/datadog/tracing/pipeline/span_processor.rb +2 -0
  334. data/lib/datadog/tracing/propagation/http.rb +2 -0
  335. data/lib/datadog/tracing/runtime/metrics.rb +2 -0
  336. data/lib/datadog/tracing/sampling/all_sampler.rb +2 -0
  337. data/lib/datadog/tracing/sampling/matcher.rb +2 -0
  338. data/lib/datadog/tracing/sampling/priority_sampler.rb +2 -0
  339. data/lib/datadog/tracing/sampling/span/sampler.rb +2 -0
  340. data/lib/datadog/tracing/sync_writer.rb +2 -0
  341. data/lib/datadog/tracing/trace_digest.rb +2 -0
  342. data/lib/datadog/tracing/utils.rb +2 -0
  343. data/lib/datadog/tracing.rb +2 -0
  344. data/lib/ddtrace/auto_instrument.rb +2 -0
  345. data/lib/ddtrace/auto_instrument_base.rb +2 -0
  346. data/lib/ddtrace/transport/http/adapters/net.rb +12 -0
  347. data/lib/ddtrace/transport/http/adapters/registry.rb +2 -0
  348. data/lib/ddtrace/transport/http/api/endpoint.rb +2 -0
  349. data/lib/ddtrace/transport/http/api/fallbacks.rb +2 -0
  350. data/lib/ddtrace/transport/http/api/instance.rb +2 -0
  351. data/lib/ddtrace/transport/http/api/map.rb +2 -0
  352. data/lib/ddtrace/transport/http/api/spec.rb +2 -0
  353. data/lib/ddtrace/transport/http/env.rb +2 -0
  354. data/lib/ddtrace/transport/http/response.rb +2 -0
  355. data/lib/ddtrace/transport/io/response.rb +2 -0
  356. data/lib/ddtrace/transport/io/traces.rb +2 -0
  357. data/lib/ddtrace/transport/io.rb +2 -0
  358. data/lib/ddtrace/transport/parcel.rb +2 -0
  359. data/lib/ddtrace/transport/request.rb +3 -1
  360. data/lib/ddtrace/transport/statistics.rb +2 -0
  361. data/lib/ddtrace/transport/trace_formatter.rb +2 -0
  362. data/lib/ddtrace/version.rb +9 -5
  363. data/lib/ddtrace.rb +2 -0
  364. metadata +43 -6
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'processor'
4
+ require_relative 'processor/rule_merger'
5
+ require_relative 'processor/rule_loader'
4
6
 
5
7
  module Datadog
6
8
  module AppSec
@@ -10,14 +12,27 @@ module Datadog
10
12
  def build_appsec_component(settings)
11
13
  return unless settings.respond_to?(:appsec) && settings.appsec.enabled
12
14
 
13
- processor = create_processor
15
+ processor = create_processor(settings)
14
16
  new(processor: processor)
15
17
  end
16
18
 
17
19
  private
18
20
 
19
- def create_processor
20
- processor = Processor.new
21
+ def create_processor(settings)
22
+ rules = AppSec::Processor::RuleLoader.load_rules(ruleset: settings.appsec.ruleset)
23
+ return nil unless rules
24
+
25
+ data = AppSec::Processor::RuleLoader.load_data(
26
+ ip_denylist: settings.appsec.ip_denylist,
27
+ user_id_denylist: settings.appsec.user_id_denylist
28
+ )
29
+
30
+ ruleset = AppSec::Processor::RuleMerger.merge(
31
+ rules: [rules],
32
+ data: data,
33
+ )
34
+
35
+ processor = Processor.new(ruleset: ruleset)
21
36
  return nil unless processor.ready?
22
37
 
23
38
  processor
@@ -28,12 +43,31 @@ module Datadog
28
43
 
29
44
  def initialize(processor:)
30
45
  @processor = processor
46
+ @mutex = Mutex.new
47
+ end
48
+
49
+ def reconfigure(ruleset:)
50
+ @mutex.synchronize do
51
+ new = Processor.new(ruleset: ruleset)
52
+
53
+ if new && new.ready?
54
+ old = @processor
55
+ @processor = new
56
+ old.finalize if old
57
+ end
58
+ end
59
+ end
60
+
61
+ def reconfigure_lock(&block)
62
+ @mutex.synchronize(&block)
31
63
  end
32
64
 
33
65
  def shutdown!
34
- if processor && processor.ready?
35
- processor.finalize
36
- @processor = nil
66
+ @mutex.synchronize do
67
+ if processor && processor.ready?
68
+ processor.finalize
69
+ @processor = nil
70
+ end
37
71
  end
38
72
  end
39
73
  end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
1
5
  module Datadog
2
6
  module AppSec
3
7
  module Configuration
@@ -87,8 +91,8 @@ module Datadog
87
91
  end
88
92
 
89
93
  # rubocop:disable Layout/LineLength
90
- DEFAULT_OBFUSCATOR_KEY_REGEX = '(?i)(?:p(?:ass)?w(?:or)?d|pass(?:_?phrase)?|secret|(?:api_?|private_?|public_?)key)|token|consumer_?(?:id|key|secret)|sign(?:ed|ature)|bearer|authorization'.freeze
91
- DEFAULT_OBFUSCATOR_VALUE_REGEX = '(?i)(?:p(?:ass)?w(?:or)?d|pass(?:_?phrase)?|secret|(?:api_?|private_?|public_?|access_?|secret_?)key(?:_?id)?|token|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)(?:\s*=[^;]|"\s*:\s*"[^"]+")|bearer\s+[a-z0-9\._\-]+|token:[a-z0-9]{13}|gh[opsu]_[0-9a-zA-Z]{36}|ey[I-L][\w=-]+\.ey[I-L][\w=-]+(?:\.[\w.+\/=-]+)?|[\-]{5}BEGIN[a-z\s]+PRIVATE\sKEY[\-]{5}[^\-]+[\-]{5}END[a-z\s]+PRIVATE\sKEY|ssh-rsa\s*[a-z0-9\/\.+]{100,}'.freeze
94
+ DEFAULT_OBFUSCATOR_KEY_REGEX = '(?i)(?:p(?:ass)?w(?:or)?d|pass(?:_?phrase)?|secret|(?:api_?|private_?|public_?)key)|token|consumer_?(?:id|key|secret)|sign(?:ed|ature)|bearer|authorization'
95
+ DEFAULT_OBFUSCATOR_VALUE_REGEX = '(?i)(?:p(?:ass)?w(?:or)?d|pass(?:_?phrase)?|secret|(?:api_?|private_?|public_?|access_?|secret_?)key(?:_?id)?|token|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)(?:\s*=[^;]|"\s*:\s*"[^"]+")|bearer\s+[a-z0-9\._\-]+|token:[a-z0-9]{13}|gh[opsu]_[0-9a-zA-Z]{36}|ey[I-L][\w=-]+\.ey[I-L][\w=-]+(?:\.[\w.+\/=-]+)?|[\-]{5}BEGIN[a-z\s]+PRIVATE\sKEY[\-]{5}[^\-]+[\-]{5}END[a-z\s]+PRIVATE\sKEY|ssh-rsa\s*[a-z0-9\/\.+]{100,}'
92
96
  # rubocop:enable Layout/LineLength
93
97
 
94
98
  DEFAULTS = {
@@ -116,9 +120,14 @@ module Datadog
116
120
 
117
121
  def initialize
118
122
  @integrations = []
123
+ # Stores which options have been configured using Datadog.configure block or ENV variables
124
+ @configured = Set.new
119
125
  @options = DEFAULTS.dup.tap do |options|
120
126
  ENVS.each do |env, (key, conv)|
121
- options[key] = conv.call(ENV[env]) if ENV[env]
127
+ if ENV[env]
128
+ options[key] = conv.call(ENV[env])
129
+ @configured << key
130
+ end
122
131
  end
123
132
  end
124
133
  end
@@ -182,7 +191,10 @@ module Datadog
182
191
 
183
192
  def merge(dsl)
184
193
  dsl.options.each do |k, v|
185
- @options[k] = v unless v.nil?
194
+ unless v.nil?
195
+ @options[k] = v
196
+ @configured << k
197
+ end
186
198
  end
187
199
 
188
200
  return self unless @options[:enabled]
@@ -206,6 +218,10 @@ module Datadog
206
218
 
207
219
  private
208
220
 
221
+ def default?(option)
222
+ !@configured.include?(option)
223
+ end
224
+
209
225
  # Restore to original state, for testing only.
210
226
  def reset!
211
227
  initialize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'configuration/settings'
2
4
 
3
5
  module Datadog
@@ -82,6 +84,12 @@ module Datadog
82
84
  def settings
83
85
  @settings ||= Settings.new
84
86
  end
87
+
88
+ private
89
+
90
+ def default_setting?(setting)
91
+ settings.send(:default?, setting)
92
+ end
85
93
  end
86
94
  end
87
95
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../../core/configuration/base'
2
4
 
3
5
  module Datadog
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../configuration/settings'
2
4
  require_relative '../ext'
3
5
 
@@ -14,7 +14,7 @@ module Datadog
14
14
  attr_reader :env
15
15
 
16
16
  def initialize(env)
17
- super
17
+ super()
18
18
  @env = env
19
19
  end
20
20
 
@@ -33,20 +33,9 @@ module Datadog
33
33
  end
34
34
  end
35
35
 
36
- # Rack < 2.0 does not have :each_header
37
- # TODO: We need access to Rack here. We must make sure we are able to load AppSec without Rack,
38
- # TODO: while still ensure correctness in ths code path.
39
- if defined?(::Rack) && ::Rack::Request.instance_methods.include?(:each_header)
40
- def headers
41
- request.each_header.each_with_object({}) do |(k, v), h|
42
- h[k.gsub(/^HTTP_/, '').downcase.tr('_', '-')] = v if k =~ /^HTTP_/
43
- end
44
- end
45
- else
46
- def headers
47
- request.env.each_with_object({}) do |(k, v), h|
48
- h[k.gsub(/^HTTP_/, '').downcase.tr('_', '-')] = v if k =~ /^HTTP_/
49
- end
36
+ def headers
37
+ request.env.each_with_object({}) do |(k, v), h|
38
+ h[k.gsub(/^HTTP_/, '').downcase.tr('_', '-')] = v if k =~ /^HTTP_/
50
39
  end
51
40
  end
52
41
 
@@ -12,7 +12,7 @@ module Datadog
12
12
  attr_reader :body, :status, :headers, :active_context
13
13
 
14
14
  def initialize(body, status, headers, active_context:)
15
- super
15
+ super()
16
16
  @body = body
17
17
  @status = status
18
18
  @headers = headers.each_with_object({}) { |(k, v), h| h[k.downcase] = v }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../patcher'
2
4
  require_relative '../../monitor'
3
5
  require_relative 'gateway/watcher'
@@ -9,12 +9,14 @@ module Datadog
9
9
  module Response
10
10
  ADDRESSES = [
11
11
  'response.status',
12
+ 'response.headers',
12
13
  ].freeze
13
14
  private_constant :ADDRESSES
14
15
 
15
16
  def self.publish(op, gateway_response)
16
17
  catch(:block) do
17
18
  op.publish('response.status', gateway_response.status)
19
+ op.publish('response.headers', gateway_response.headers)
18
20
 
19
21
  nil
20
22
  end
@@ -25,9 +27,13 @@ module Datadog
25
27
  Datadog.logger.debug { "reacted to #{ADDRESSES.inspect}: #{values.inspect}" }
26
28
 
27
29
  response_status = values[0]
30
+ response_headers = values[1]
31
+ response_headers_no_cookies = response_headers.dup.tap { |h| h.delete('set-cookie') }
28
32
 
29
33
  waf_args = {
30
34
  'server.response.status' => response_status.to_s,
35
+ 'server.response.headers' => response_headers,
36
+ 'server.response.headers.no_cookies' => response_headers_no_cookies,
31
37
  }
32
38
 
33
39
  waf_timeout = Datadog::AppSec.settings.waf_timeout
@@ -23,17 +23,29 @@ module Datadog
23
23
  @oneshot_tags_sent = false
24
24
  end
25
25
 
26
+ # rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/MethodLength
26
27
  def call(env)
27
28
  return @app.call(env) unless Datadog::AppSec.enabled?
28
29
 
29
- processor = Datadog::AppSec.processor
30
+ Datadog::Core::Remote.active_remote.barrier(:once) unless Datadog::Core::Remote.active_remote.nil?
30
31
 
31
- return @app.call(env) if processor.nil? || !processor.ready?
32
+ processor = nil
33
+ ready = false
34
+ context = nil
35
+
36
+ Datadog::AppSec.reconfigure_lock do
37
+ processor = Datadog::AppSec.processor
38
+
39
+ if !processor.nil? && processor.ready?
40
+ context = processor.activate_context
41
+ env['datadog.waf.context'] = context
42
+ ready = true
43
+ end
44
+ end
32
45
 
33
46
  # TODO: handle exceptions, except for @app.call
34
47
 
35
- context = processor.activate_context
36
- env['datadog.waf.context'] = context
48
+ return @app.call(env) unless ready
37
49
 
38
50
  gateway_request = Gateway::Request.new(env)
39
51
 
@@ -76,6 +88,7 @@ module Datadog
76
88
  processor.deactivate_context
77
89
  end
78
90
  end
91
+ # rubocop:enable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity,Metrics/MethodLength
79
92
 
80
93
  private
81
94
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../configuration/settings'
2
4
  require_relative '../ext'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -12,7 +12,7 @@ module Datadog
12
12
  attr_reader :request
13
13
 
14
14
  def initialize(request)
15
- super
15
+ super()
16
16
  @request = request
17
17
  end
18
18
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../configuration/settings'
2
4
  require_relative '../ext'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -12,7 +12,7 @@ module Datadog
12
12
  attr_reader :params
13
13
 
14
14
  def initialize(params)
15
- super
15
+ super()
16
16
  @params = params
17
17
  end
18
18
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module AppSec
3
5
  module Contrib
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'configuration'
2
4
 
3
5
  module Datadog
@@ -5,16 +5,14 @@ module Datadog
5
5
  module Instrumentation
6
6
  class Gateway
7
7
  # Base class for Gateway Arguments
8
- class Argument
9
- def initialize(*); end
10
- end
8
+ class Argument; end # rubocop:disable Lint/EmptyClass
11
9
 
12
10
  # Gateway User argument
13
11
  class User < Argument
14
12
  attr_reader :id
15
13
 
16
14
  def initialize(id)
17
- super
15
+ super()
18
16
  @id = id
19
17
  end
20
18
  end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../assets'
4
+
5
+ module Datadog
6
+ module AppSec
7
+ class Processor
8
+ # RuleLoader utility modules
9
+ # that load appsec rules and data from settings
10
+ module RuleLoader
11
+ class << self
12
+ def load_rules(ruleset:)
13
+ begin
14
+ case ruleset
15
+ when :recommended, :strict
16
+ JSON.parse(Datadog::AppSec::Assets.waf_rules(ruleset))
17
+ when :risky
18
+ Datadog.logger.warn(
19
+ 'The :risky Application Security Management ruleset has been deprecated and no longer available.'\
20
+ 'The `:recommended` ruleset will be used instead.'\
21
+ 'Please remove the `appsec.ruleset = :risky` setting from your Datadog.configure block.'
22
+ )
23
+ JSON.parse(Datadog::AppSec::Assets.waf_rules(:recommended))
24
+ when String
25
+ JSON.parse(File.read(File.expand_path(ruleset)))
26
+ when File, StringIO
27
+ JSON.parse(ruleset.read || '').tap { ruleset.rewind }
28
+ when Hash
29
+ ruleset
30
+ else
31
+ raise ArgumentError, "unsupported value for ruleset setting: #{ruleset.inspect}"
32
+ end
33
+ rescue StandardError => e
34
+ Datadog.logger.error do
35
+ "libddwaf ruleset failed to load, ruleset: #{ruleset.inspect} error: #{e.inspect}"
36
+ end
37
+
38
+ nil
39
+ end
40
+ end
41
+
42
+ def load_data(ip_denylist: [], user_id_denylist: [])
43
+ data = []
44
+ data << { 'rules_data' => [denylist_data('blocked_ips', ip_denylist)] } if ip_denylist.any?
45
+ data << { 'rules_data' => [denylist_data('blocked_users', user_id_denylist)] } if user_id_denylist.any?
46
+
47
+ data.any? ? data : nil
48
+ end
49
+
50
+ private
51
+
52
+ def denylist_data(id, denylist)
53
+ {
54
+ 'id' => id,
55
+ 'type' => 'data_with_expiration',
56
+ 'data' => denylist.map { |v| { 'value' => v.to_s, 'expiration' => 2**63 } }
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module AppSec
5
+ class Processor
6
+ # RuleMerger merge different sources of information
7
+ # into the rules payload
8
+ module RuleMerger
9
+ # RuleVersionMismatchError
10
+ class RuleVersionMismatchError < StandardError
11
+ def initialize(version1, version2)
12
+ msg = 'Merging rule files with different version could lead to unkown behaviour. '\
13
+ "We have receieve two rule files with versions: #{version1}, #{version2}. "\
14
+ 'Please validate the configuration is correct and try again.'
15
+ super(msg)
16
+ end
17
+ end
18
+
19
+ class << self
20
+ def merge(rules:, data: nil, overrides: nil, exclusions: nil)
21
+ combined_rules = combine_rules(rules)
22
+
23
+ rules_data = combine_data(data) if data
24
+ rules_overrides = combine_overrides(overrides) if overrides
25
+ rules_exclusions = combine_exclusions(exclusions) if exclusions
26
+
27
+ combined_rules['rules_data'] = rules_data if rules_data
28
+ combined_rules['rules_override'] = rules_overrides if rules_overrides
29
+ combined_rules['exclusions'] = rules_exclusions if rules_exclusions
30
+
31
+ combined_rules
32
+ end
33
+
34
+ private
35
+
36
+ def combine_rules(rules)
37
+ return rules[0].dup if rules.size == 1
38
+
39
+ final_rules = []
40
+ # @type var final_version: ::String
41
+ final_version = (_ = nil)
42
+
43
+ rules.each do |rule_file|
44
+ version = rule_file['version']
45
+
46
+ if version && !final_version
47
+ final_version = version
48
+ elsif final_version != version
49
+ raise RuleVersionMismatchError.new(final_version, version)
50
+ end
51
+
52
+ final_rules.concat(rule_file['rules'])
53
+ end
54
+
55
+ {
56
+ 'version' => final_version,
57
+ 'rules' => final_rules
58
+ }
59
+ end
60
+
61
+ def combine_data(data)
62
+ result = []
63
+
64
+ data.each do |data_entry|
65
+ data_entry['rules_data'].each do |value|
66
+ existing_data = result.find { |x| x['id'] == value['id'] }
67
+
68
+ if existing_data && existing_data['type'] == value['type']
69
+ # Duplicate entry base on type and id
70
+ # We need to merge the existing data with the new one
71
+ # and make sure to remove duplicates
72
+ merged_data = merge_data_base_on_expiration(existing_data['data'], value['data'])
73
+ existing_data['data'] = merged_data
74
+ else
75
+ result << value
76
+ end
77
+ end
78
+ end
79
+
80
+ return unless result.any?
81
+
82
+ result
83
+ end
84
+
85
+ def merge_data_base_on_expiration(data1, data2)
86
+ result = data1.each_with_object({}) do |value, acc|
87
+ acc[value['value']] = value['expiration']
88
+ end
89
+
90
+ data2.each do |data|
91
+ if result.key?(data['value'])
92
+ # The value is duplicated so we need to keep
93
+ # the one with the highest expiration value
94
+ # We replace it if the expiration is higher than the current one
95
+ # or if no experiration
96
+ current_expiration = result[data['value']]
97
+ new_expiration = data['expiration']
98
+
99
+ if new_expiration.nil? || current_expiration && new_expiration > current_expiration
100
+ result[data['value']] = new_expiration
101
+ end
102
+ else
103
+ result[data['value']] = data['expiration']
104
+ end
105
+ end
106
+
107
+ result.each_with_object([]) do |entry, acc|
108
+ value = { 'value' => entry[0] }
109
+ value['expiration'] = entry[1] if entry[1]
110
+
111
+ acc << value
112
+ end
113
+ end
114
+
115
+ def combine_overrides(overrides)
116
+ rules_override = []
117
+
118
+ overrides.each do |override|
119
+ override['rules_override'].each do |rule_override|
120
+ rules_override << rule_override
121
+ end
122
+ end
123
+
124
+ return if rules_override.empty?
125
+
126
+ rules_override
127
+ end
128
+
129
+ def combine_exclusions(exclusions)
130
+ rules_exclusions = []
131
+
132
+ exclusions.each do |exclusion|
133
+ exclusion['exclusions'].each do |rule_exclusion|
134
+ rules_exclusions << rule_exclusion
135
+ end
136
+ end
137
+
138
+ return if rules_exclusions.empty?
139
+
140
+ rules_exclusions
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end