Repository navigation
feat(openfeature): add shared agentless EVP fallback #6574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
9aa4fe9
946173d
ff41edc
a0182be
eb3b187
911180e
040f61a
a3cc55b
bda5c14
9c1ea91
b8c93df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2905,10 +2905,20 @@ Configure Feature Flags with environment variables or inside a `Datadog.configur | |
|
|
||
| `DD_EXPERIMENTAL_FLAGGING_PROVIDER_ENABLED` and `c.open_feature.enabled` are deprecated. When neither stable setting is explicitly configured, the legacy value `true` selects `remote_config` and `false` disables Feature Flags. | ||
|
|
||
| The API key is sent only to the managed Datadog endpoint. A custom agentless URL is treated as opaque, and its query string is preserved without automatically adding `dd_env`. | ||
| Configuration polling sends the API key only to the managed Datadog endpoint. A custom agentless configuration URL is treated as opaque, and its query string is preserved without automatically adding `dd_env`. | ||
|
|
||
| Feature Flags respects `DD_TRACE_DEBUG` and outputs debugging diagnostics when it is enabled. | ||
|
|
||
| #### Event delivery with agentless configuration | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker or anything - but is it maybe time to extract FFE documentation into a separate .md file? |
||
|
|
||
| When `c.feature_flags.configuration_source` is `agentless`, exposures and flag evaluations share one delivery route. The library prefers a local Agent or serverless relay that forwards EVP origin metadata; Datadog Agent 7.84.0 and later support this metadata. Otherwise, the library sends events directly to `https://event-platform-intake.<DD_SITE>`, authenticated with `DD_API_KEY`. Allow outbound HTTPS access to this host for direct delivery. If direct delivery is not configured, the library can still use an older Agent's advertised EVP endpoint. When `c.feature_flags.configuration_source` is `remote_config`, events are delivered only through the Agent. | ||
|
|
||
| Direct event delivery supports `https_proxy` or `HTTPS_PROXY` and `no_proxy` or `NO_PROXY`; lowercase variables take precedence. Proxy URLs must use `http://` or a bare `host:port`, including for HTTPS intake requests. An explicitly empty HTTPS proxy variable disables proxying. When neither HTTPS proxy variable is set, Ruby's standard HTTP proxy settings apply; prefer `http_proxy` because Ruby warns when using uppercase `HTTP_PROXY`. These HTTPS proxy settings apply to event delivery; agentless configuration polling uses Ruby's standard HTTP proxy settings. Event delivery does not follow redirects. | ||
|
|
||
| If the local route returns a 404 or 405 response, or a request fails before it is sent, the library resends that batch directly to Datadog one time, provided direct delivery is configured. If the local route returns a 403, 429, or 5xx response, or encounters another transport error, the library sends only later batches directly, so events the local route may have accepted are not duplicated. | ||
|
|
||
| After switching to direct delivery, the library keeps using it in that process until you reconfigure the library with `Datadog.configure`. If no usable local route is available and direct delivery is not configured, the library logs a warning once until reconfiguration, drops the batch, and retries local discovery on the next batch after a 30-second cooldown. | ||
|
|
||
| The provider requires `openfeature-sdk` 0.5.1 or later. It sends exposures, evaluation counts, and evaluation metrics from provider hooks, and earlier `openfeature-sdk` releases run no hooks. With an earlier release, flags still evaluate, Datadog receives no exposures or evaluation counts, and the provider logs one warning at initialization. | ||
|
|
||
| Exposures are sent only for evaluations that run the provider's hooks, which happens when the application evaluates through an OpenFeature client with the Datadog provider registered directly: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,7 @@ class Worker | |
| include Core::Workers::Queue | ||
| include Core::Workers::Polling | ||
|
|
||
| GRACEFUL_SHUTDOWN_EXTRA_SECONDS = 5 | ||
| GRACEFUL_SHUTDOWN_WAIT_INTERVAL_SECONDS = 0.5 | ||
| GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS = 3 | ||
|
|
||
| DEFAULT_FLUSH_INTERVAL_SECONDS = 30 | ||
| DEFAULT_BUFFER_LIMIT = Buffer::DEFAULT_LIMIT | ||
|
|
@@ -54,6 +53,9 @@ def stop(force_stop = false, timeout = Core::Workers::Polling::DEFAULT_SHUTDOWN_ | |
| end | ||
|
|
||
| def enqueue(event) | ||
| return false unless enabled? | ||
|
|
||
| start if forked? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment from Codex working with @sameerank: [P2] Wake the restarted poller after the first child enqueue This starts the restarted poller before the first child event is pushed. The poller can observe the new buffer while it is empty and enter its 30-second interval wait; the later Please remember whether this enqueue performed the fork restart and, after its push succeeds, signal that restarted poller. Limiting the signal to this first post-fork path preserves ordinary batching behavior. Executed validationThe baseline regression failed with 1,492 examples and one timeout. The candidate wakeup, together with the shutdown-race fix and a normal post-fork positive control, passed both OpenFeature dependency appraisals: 2,984 aggregate examples and zero failures. |
||
| unless buffer.push(event) | ||
| @logger.debug { "Feature Flags: exposure not queued: buffer closed" } | ||
| return false | ||
|
|
@@ -74,24 +76,27 @@ def perform(*args) | |
| end | ||
|
|
||
| def graceful_shutdown | ||
| return false unless enabled? || !run_loop? | ||
|
|
||
| buffer.close | ||
| @logger.debug do | ||
| "Feature Flags: exposure worker stopping; queued=#{buffer.length}, " \ | ||
| "upload_in_progress=#{!!in_iteration?}, wait_budget=#{GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS}s" | ||
| end | ||
| stopped = stop(true, GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS) | ||
| log_shutdown_outcome(GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS) | ||
| @logger.debug("Feature Flags: exposure worker stopped") unless running? | ||
| stopped | ||
| ensure | ||
| self.enabled = false | ||
| end | ||
|
|
||
| started = Core::Utils::Time.get_time | ||
| wait_time = loop_base_interval + GRACEFUL_SHUTDOWN_EXTRA_SECONDS | ||
|
|
||
| loop do | ||
| break if buffer.empty? && !in_iteration? | ||
| def work_pending? | ||
| !buffer.empty? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| end | ||
|
|
||
| sleep(GRACEFUL_SHUTDOWN_WAIT_INTERVAL_SECONDS) | ||
| break if Core::Utils::Time.get_time - started > wait_time | ||
| end | ||
| protected | ||
|
|
||
| log_shutdown_outcome(wait_time) | ||
| stopped = stop(true) | ||
| @logger.debug("Feature Flags: exposure worker stopped") unless running? | ||
| stopped | ||
| def after_fork | ||
| self.buffer = Buffer.new(@buffer_limit) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment from Codex working with @sameerank: [P2] Keep teardown terminal across this fork reset
Please record a terminal stop-requested state before closing or waiting, re-check it around the fork restart, and keep any replacement child buffer closed when teardown has begun. If restart creates a thread during the race, stop it after leaving the async lifecycle lock. Executed validationThe baseline regression failed with 1,491 examples and one failure. A candidate fix with the lifecycle checks above, an ordinary post-fork positive control, and the separate first-delivery regression passed both OpenFeature dependency appraisals: 2,984 aggregate examples and zero failures. |
||
| end | ||
|
|
||
| private | ||
|
|
@@ -106,11 +111,11 @@ def send_events(events, dropped) | |
| end | ||
|
|
||
| payload = @batch_builder.payload_for(events) | ||
| @logger.debug { "Feature Flags: flushing #{events.size} exposure event(s) to the Datadog Agent" } | ||
| @logger.debug { "Feature Flags: flushing #{events.size} exposure event(s) to Datadog" } | ||
| response = @transport.send_exposures(payload) | ||
|
|
||
| if response&.ok? | ||
| @logger.debug { "Feature Flags: sent #{events.size} exposure event(s) to the Datadog Agent" } | ||
| @logger.debug { "Feature Flags: sent #{events.size} exposure event(s) to Datadog" } | ||
| else | ||
| @logger.debug do | ||
| "Feature Flags: exposure upload response was not OK; dropping #{events.size} exposure event(s) " \ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative "../../core/encoding" | ||
| require_relative "../../core/evp" | ||
| require_relative "../../core/utils/time" | ||
| require_relative "http_client" | ||
|
|
||
| module Datadog | ||
| module OpenFeature | ||
| module Transport | ||
| # Component-owned route selection shared by both event writers. | ||
|
leoromanovsky marked this conversation as resolved.
Resolved
|
||
| class Agentless | ||
| DISCOVERY_TIMEOUT_SECONDS = 5 | ||
| REQUEST_TIMEOUT_SECONDS = 5 | ||
| RECOVERY_INTERVAL_SECONDS = 30 | ||
| LOCAL_ROUTES = ["/evp_proxy/v4", "/evp_proxy/v2"].freeze | ||
|
|
||
| def initialize(agent_settings:, site:, api_key:, logger:) | ||
| @client = HTTPClient.new(agent_settings: agent_settings, site: site, api_key: api_key) | ||
| @logger = logger | ||
| @mutex = Mutex.new | ||
| @fork_mutex = Mutex.new | ||
| @route = nil | ||
| @recover_at = 0.0 | ||
| @unavailable_warning_logged = false | ||
| @pid = Process.pid | ||
| @closed = false | ||
| @shutdown_deadline = nil | ||
| end | ||
|
|
||
| def send_exposures(payload) | ||
| send_batch("/api/v2/exposures", payload) | ||
| end | ||
|
|
||
| def send_flag_evaluations(payload) | ||
| send_batch("/api/v2/flagevaluation", payload) | ||
| end | ||
|
|
||
| def shutdown!(timeout:) | ||
| reset_after_fork | ||
| @shutdown_deadline = Core::Utils::Time.get_time + timeout | ||
| end | ||
|
|
||
| def close | ||
| @closed = true | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def send_batch(path, payload) | ||
| encoded = Core::Encoding::JSONEncoder.encode(payload) | ||
| route = select_route | ||
| return Response.new unless route | ||
|
|
||
| response = send_once(route, path, encoded) | ||
| if route != :direct && (response.internal_error? || [403, 404, 405, 429].include?(response.code) || | ||
| response.code&.between?(500, 599)) | ||
| fallback = leave_local(route) | ||
| if fallback && (response.pre_send? || [404, 405].include?(response.code)) | ||
| response = send_once(:direct, path, encoded) | ||
| end | ||
| end | ||
| @logger.debug { "OpenFeature EVP: batch dropped after delivery failure" } unless response.ok? | ||
| response | ||
| # Serialization and delivery failures must never interrupt flag evaluation or reveal event data. | ||
| rescue | ||
| @logger.debug { "OpenFeature EVP: batch dropped after internal delivery failure" } | ||
| Response.new | ||
| end | ||
|
|
||
| def send_once(route, path, encoded) | ||
| direct = route == :direct | ||
| @client.request(direct ? path : route.to_s + path, | ||
| payload: encoded, direct: direct, timeout: remaining(REQUEST_TIMEOUT_SECONDS)) | ||
| end | ||
|
|
||
| def select_route | ||
| reset_after_fork | ||
| @mutex.synchronize do | ||
| return if @closed || remaining(REQUEST_TIMEOUT_SECONDS) <= 0 | ||
| return @route if @route || Core::Utils::Time.get_time < @recover_at | ||
|
|
||
| info = @client.request("/info", timeout: remaining(DISCOVERY_TIMEOUT_SECONDS)).info | ||
| @route = compatible_route(info) | ||
| @route = :direct if !@route && @client.direct? | ||
| @route ||= local_route(info) | ||
| warn_unavailable unless @route | ||
| @recover_at = Core::Utils::Time.get_time + RECOVERY_INTERVAL_SECONDS unless @route | ||
|
leoromanovsky marked this conversation as resolved.
Resolved
|
||
| @route | ||
| end | ||
| end | ||
|
|
||
| def compatible_route(info) | ||
| return unless info | ||
|
|
||
| headers = info["evp_proxy_allowed_headers"] | ||
| return unless headers.is_a?(Array) | ||
|
|
||
| headers = headers.grep(String).map { |header| header.strip.downcase } | ||
| return unless HTTPClient::IDENTITY_HEADERS.keys.all? { |name| headers.include?(name.downcase) } | ||
|
leoromanovsky marked this conversation as resolved.
Resolved
|
||
|
|
||
| local_route(info) | ||
| end | ||
|
|
||
| def local_route(info) | ||
| endpoints = info && info["endpoints"] | ||
| return unless endpoints.is_a?(Array) | ||
|
|
||
| LOCAL_ROUTES.find { |path| endpoints.include?(path) || endpoints.include?(path + "/") } | ||
| end | ||
|
|
||
| def leave_local(route) | ||
| @mutex.synchronize do | ||
| return false if @closed | ||
|
|
||
| if @route == route | ||
| @route = @client.direct? ? :direct : nil | ||
| warn_unavailable unless @route | ||
| @recover_at = Core::Utils::Time.get_time + RECOVERY_INTERVAL_SECONDS unless @route | ||
| end | ||
| @route == :direct | ||
| end | ||
| end | ||
|
|
||
| def warn_unavailable | ||
| return if @unavailable_warning_logged || remaining(REQUEST_TIMEOUT_SECONDS) <= 0 | ||
|
|
||
| @unavailable_warning_logged = true | ||
| @logger.warn("Feature Flags exposures and flag evaluations are being dropped: " \ | ||
| "no usable local Agent EVP route is available, and direct delivery requires DD_API_KEY and a valid DD_SITE.") | ||
| end | ||
|
|
||
| def remaining(limit) | ||
| return 0 if @closed | ||
|
|
||
| deadline = @shutdown_deadline | ||
| deadline ? [limit, deadline - Core::Utils::Time.get_time].min : limit | ||
| end | ||
|
|
||
| def reset_after_fork | ||
| return if @pid == Process.pid | ||
|
|
||
| @fork_mutex.synchronize do | ||
| return if @pid == Process.pid | ||
|
|
||
| @mutex = Mutex.new | ||
| @route = nil | ||
| @recover_at = 0.0 | ||
| @unavailable_warning_logged = false | ||
| @shutdown_deadline = nil | ||
| @pid = Process.pid | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.