-
Notifications
You must be signed in to change notification settings - Fork 405
feat(openfeature): preserve configuration source semantics #9413
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
Closed
leoromanovsky
wants to merge
15
commits into
leo.romanovsky/ffl-2697-nodejs-agentless-configuration-source
from
leo.romanovsky/ffl-2697-nodejs-configuration-contract
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7ffa2a3
feat(openfeature): resolve configuration delivery
leoromanovsky 7b0b67e
feat(openfeature): load agentless UFC snapshots
leoromanovsky b83caab
feat(openfeature): harden agentless polling
leoromanovsky ac9b55d
feat(openfeature): activate agentless delivery
leoromanovsky beeeaeb
test(openfeature): cover agentless delivery branches
leoromanovsky 5b83654
fix(openfeature): keep delivery configuration environment-only
leoromanovsky fe91564
fix(openfeature): send canonical client library headers
leoromanovsky a59fc06
fix(telemetry): preserve client library header casing
leoromanovsky 50c9f10
refactor(telemetry): reuse client library headers
leoromanovsky 053684d
fix(openfeature): report agentless base URL configuration
leoromanovsky 4f57fe8
feat(openfeature): preserve configuration source semantics
leoromanovsky 23a9e2b
fix(openfeature): separate enablement from source selection
leoromanovsky e9abe8f
test(openfeature): gate proxy RC subscription
leoromanovsky f62b5ec
fix(openfeature): treat blank source as unset
leoromanovsky 94a16dc
fix(openfeature): defer module startup until access
leoromanovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| 'use strict' | ||
|
|
||
| const tracer = require('dd-trace') | ||
| const http = require('node:http') | ||
| const { OpenFeature } = require('@openfeature/server-sdk') | ||
|
|
||
| tracer.init({ | ||
| env: 'integration', | ||
| service: 'ffe-agentless-integration', | ||
| }) | ||
|
|
||
| OpenFeature.setProvider(tracer.openfeature) | ||
| const client = OpenFeature.getClient() | ||
|
|
||
| const server = http.createServer((request, response) => { | ||
| if (request.url !== '/evaluate') { | ||
| response.writeHead(404).end() | ||
| return | ||
| } | ||
|
|
||
| client.getStringDetails('agentless-integration-flag', 'default', { | ||
| targetingKey: 'integration-user', | ||
| }).then(details => { | ||
| response.setHeader('Content-Type', 'application/json') | ||
| response.end(JSON.stringify(details)) | ||
| }, error => { | ||
| response.writeHead(500, { 'Content-Type': 'application/json' }) | ||
| response.end(JSON.stringify({ error: error.message })) | ||
| }) | ||
| }) | ||
|
|
||
| server.listen(0, function () { | ||
| process.send?.({ port: this.address().port }) | ||
| }) |
132 changes: 132 additions & 0 deletions
132
integration-tests/openfeature/openfeature-agentless.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| 'use strict' | ||
|
|
||
| const assert = require('node:assert/strict') | ||
| const http = require('node:http') | ||
| const path = require('node:path') | ||
| const zlib = require('node:zlib') | ||
| const { afterEach, before, beforeEach, describe, it } = require('mocha') | ||
| const { VERSION } = require('../../version') | ||
| const { sandboxCwd, useSandbox, spawnProc, stopProc } = require('../helpers') | ||
|
|
||
| const UFC = { | ||
| createdAt: '2026-01-01T00:00:00.000Z', | ||
| environment: { name: 'integration' }, | ||
| flags: { | ||
| 'agentless-integration-flag': { | ||
| key: 'agentless-integration-flag', | ||
| enabled: true, | ||
| variationType: 'STRING', | ||
| variations: { | ||
| local: { key: 'local', value: 'loaded-from-agentless' }, | ||
| }, | ||
| allocations: [ | ||
| { | ||
| key: 'agentless-integration-allocation', | ||
| splits: [{ variationKey: 'local', shards: [] }], | ||
| doLog: false, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| describe('OpenFeature agentless configuration integration', () => { | ||
| let appFile | ||
| let backend | ||
| let backendUrl | ||
| let cwd | ||
| let observedRequests | ||
| let proc | ||
|
|
||
| useSandbox( | ||
| ['@openfeature/server-sdk', '@openfeature/core'], | ||
| false, | ||
| [path.join(__dirname, 'app')] | ||
| ) | ||
|
|
||
| before(() => { | ||
| cwd = sandboxCwd() | ||
| appFile = path.join(cwd, 'app', 'agentless-evaluation.js') | ||
| }) | ||
|
|
||
| beforeEach(async () => { | ||
| observedRequests = [] | ||
| backend = http.createServer((request, response) => { | ||
| observedRequests.push({ | ||
| url: request.url, | ||
| headers: request.headers, | ||
| }) | ||
|
|
||
| if (request.headers['if-none-match'] === '"agentless-integration"') { | ||
| response.writeHead(304).end() | ||
| return | ||
| } | ||
|
|
||
| response.writeHead(200, { | ||
| 'Content-Type': 'application/json', | ||
| 'Content-Encoding': 'gzip', | ||
| ETag: '"agentless-integration"', | ||
| }) | ||
| const body = JSON.stringify({ | ||
| data: { | ||
| id: '1', | ||
| type: 'universal-flag-configuration', | ||
| attributes: UFC, | ||
| }, | ||
| }) | ||
| response.end(zlib.gzipSync(body)) | ||
| }) | ||
| await new Promise((resolve, reject) => { | ||
| backend.once('error', reject) | ||
| backend.listen(0, '127.0.0.1', resolve) | ||
| }) | ||
| backendUrl = `http://127.0.0.1:${backend.address().port}` | ||
|
|
||
| proc = await spawnProc(appFile, { | ||
| cwd, | ||
| env: { | ||
| DD_API_KEY: 'integration-api-key', | ||
| DD_FEATURE_FLAGS_ENABLED: 'true', | ||
| DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL: backendUrl, | ||
| DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_POLL_INTERVAL_SECONDS: '5', | ||
| DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_REQUEST_TIMEOUT_SECONDS: '1', | ||
| DD_INSTRUMENTATION_TELEMETRY_ENABLED: 'false', | ||
| DD_REMOTE_CONFIGURATION_ENABLED: 'false', | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await stopProc(proc) | ||
| await new Promise(resolve => backend.close(resolve)) | ||
| }) | ||
|
|
||
| it('loads UFC from the default agentless source and evaluates locally', async () => { | ||
| let details | ||
| for (let attempt = 0; attempt < 50; attempt++) { | ||
| const response = await fetch(`${proc.url}/evaluate`) | ||
| details = await response.json() | ||
| if (details.value === 'loaded-from-agentless') break | ||
| await new Promise(resolve => setTimeout(resolve, 20)) | ||
| } | ||
|
|
||
| assert.strictEqual(details.value, 'loaded-from-agentless') | ||
| assert.notStrictEqual(details.reason, 'ERROR') | ||
|
|
||
| for (let attempt = 0; observedRequests.length < 2 && attempt < 350; attempt++) { | ||
| await new Promise(resolve => setTimeout(resolve, 20)) | ||
| } | ||
|
|
||
| assert.ok(observedRequests.length >= 2) | ||
| assert.strictEqual( | ||
| observedRequests[0].url, | ||
| '/api/v2/feature-flagging/config/rules-based/server' | ||
| ) | ||
| assert.strictEqual(observedRequests[0].headers['dd-api-key'], 'integration-api-key') | ||
| assert.strictEqual(observedRequests[0].headers['accept-encoding'], 'gzip') | ||
| assert.strictEqual(observedRequests[0].headers['dd-client-library-language'], 'nodejs') | ||
| assert.strictEqual(observedRequests[0].headers['dd-client-library-version'], VERSION) | ||
| assert.strictEqual(observedRequests[0].headers['dd-flagging-source-mode'], undefined) | ||
| assert.strictEqual(observedRequests[1].headers['if-none-match'], '"agentless-integration"') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/dd-trace/src/exporters/common/client-library-headers.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 'use strict' | ||
|
|
||
| const { VERSION } = require('../../../../../version') | ||
|
|
||
| const LANGUAGE = 'nodejs' | ||
|
|
||
| /** | ||
| * Returns the canonical client-library identification headers. | ||
| * | ||
| * @param {string} [language] - Client library language name. | ||
| * @param {string} [version] - Client library version. | ||
| * @returns {Record<string, string>} Client library identification headers. | ||
| */ | ||
| function getClientLibraryHeaders (language = LANGUAGE, version = VERSION) { | ||
| return { | ||
| 'DD-Client-Library-Language': language, | ||
| 'DD-Client-Library-Version': version, | ||
| } | ||
| } | ||
|
|
||
| module.exports = { getClientLibraryHeaders } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file needs more revising.
Would it be beneficial to mention
DD_FEATURE_FLAGS_ENABLEDto encourage the newer env variable instead? Also, is it worth documentingDD_FEATURE_FLAGS_CONFIGURATION_SOURCEhere? Another place to add documentation about configuring the provider might bedocs/API.mdAlso the provider now defaults to enabled, and that legacy variable specifically selects Remote Config, so this might be confusing
dd-trace-js/index.d.ts
Lines 159 to 164 in 5b83654