diff --git a/lib/client/config/configHelpers.ts b/lib/client/config/configHelpers.ts index bc9381379..2665fcae5 100644 --- a/lib/client/config/configHelpers.ts +++ b/lib/client/config/configHelpers.ts @@ -6,6 +6,7 @@ import { getConfig, loadBrokerConfig, } from '../../common/config/config'; +import version from '../../common/utils/version'; export const reloadConfig = async (clientOpts) => { // Reload config with connection @@ -22,6 +23,8 @@ export const getClientConfigMetadata = ( clientConfig: Record, ): ConfigMetadata => { const configMetadata: ConfigMetadata = { + brokerClientId: clientConfig.brokerClientId, + version: `${version}`, haMode: highAvailabilityModeEnabled(clientConfig), debugMode: clientConfig.logLevel === 'debug' ? true : false, bodyLogMode: clientConfig.logEnableBody ? true : false, diff --git a/lib/client/config/remoteConfig.ts b/lib/client/config/remoteConfig.ts index c03813c82..9189437dd 100644 --- a/lib/client/config/remoteConfig.ts +++ b/lib/client/config/remoteConfig.ts @@ -4,6 +4,7 @@ import { PostFilterPreparedRequest } from '../../common/relay/prepareRequest'; import { ClientOpts } from '../../common/types/options'; import { BrokerConnectionApiResponse } from '../types/api'; import { capitalizeKeys } from '../utils/configurations'; +import version from '../../common/utils/version'; export const retrieveConnectionsForDeployment = async ( clientOpts: ClientOpts, @@ -16,6 +17,8 @@ export const retrieveConnectionsForDeployment = async ( headers: { 'Content-Type': 'application/vnd.api+json', Authorization: `${clientOpts.accessToken?.authHeader}`, + 'x-broker-client-id': `${clientOpts.config.brokerClientId}`, + 'x-broker-client-version': `${version}`, }, method: 'GET', }; diff --git a/lib/client/index.ts b/lib/client/index.ts index 1e2fe0339..0f5b11df7 100644 --- a/lib/client/index.ts +++ b/lib/client/index.ts @@ -51,8 +51,11 @@ export const main = async (clientOpts: ClientOpts) => { try { logger.info({ version }, 'Broker starting in client mode'); let hookResults: HookResults = {}; - const brokerClientId = uuidv4(); - logger.info({ brokerClientId }, 'generated broker client id'); + clientOpts.config.brokerClientId = uuidv4(); + logger.info( + { brokerClientId: clientOpts.config.brokerClientId }, + 'generated broker client id', + ); clientOpts.config.API_BASE_URL = clientOpts.config.API_BASE_URL ?? @@ -79,7 +82,10 @@ export const main = async (clientOpts: ClientOpts) => { ); } else { // universal broker logic is in connection manager - hookResults = await processStartUpHooks(clientOpts, brokerClientId); + hookResults = await processStartUpHooks( + clientOpts, + clientOpts.config.brokerClientId, + ); } const loadedClientOpts: LoadedClientOpts = { @@ -94,7 +100,7 @@ export const main = async (clientOpts: ClientOpts) => { const globalIdentifyingMetadata: IdentifyingMetadata = { capabilities: ['post-streams'], - clientId: brokerClientId, + clientId: clientOpts.config.brokerClientId, filters: loadedClientOpts.filters, preflightChecks: hookResults.preflightCheckResults, version, diff --git a/lib/client/types/client.ts b/lib/client/types/client.ts index 802760922..7171de0a6 100644 --- a/lib/client/types/client.ts +++ b/lib/client/types/client.ts @@ -6,6 +6,8 @@ export interface HookResults { } export interface ConfigMetadata { + brokerClientId: string; + version: string; haMode: boolean; debugMode: boolean; bodyLogMode: boolean; diff --git a/test/functional/server-client.test.ts b/test/functional/server-client.test.ts index 8d33de67a..73aec4f2e 100644 --- a/test/functional/server-client.test.ts +++ b/test/functional/server-client.test.ts @@ -70,6 +70,7 @@ describe('proxy requests originating from behind the broker server', () => { role: 'primary', clientConfig: { bodyLogMode: false, + brokerClientId: expect.any(String), credPooling: true, //client sets a PASSWORD_POOL customAccept: true, debugMode: false, @@ -79,6 +80,7 @@ describe('proxy requests originating from behind the broker server', () => { proxy: false, tlsReject: false, universalBroker: false, + version: 'local', }, identifier: '67f47824f806ee9c2fe6c7cc5849269fc1bc599c18e401ee2e2aea422bab6128', @@ -92,6 +94,7 @@ describe('proxy requests originating from behind the broker server', () => { role: 'secondary', clientConfig: { bodyLogMode: false, + brokerClientId: expect.any(String), credPooling: true, //client sets a PASSWORD_POOL customAccept: true, debugMode: false, @@ -101,6 +104,7 @@ describe('proxy requests originating from behind the broker server', () => { proxy: false, tlsReject: false, universalBroker: false, + version: 'local', }, identifier: '67f47824f806ee9c2fe6c7cc5849269fc1bc599c18e401ee2e2aea422bab6128', diff --git a/test/unit/configHelper.test.ts b/test/unit/configHelper.test.ts index f5d108e69..371da07dd 100644 --- a/test/unit/configHelper.test.ts +++ b/test/unit/configHelper.test.ts @@ -37,8 +37,10 @@ describe('config', () => { it('everything is false for empty config', async () => { await loadBrokerConfig(); const config = getConfig(); + config.brokerClientId = '123'; expect(getClientConfigMetadata(config as LoadedClientOpts)).toEqual({ bodyLogMode: false, + brokerClientId: '123', credPooling: false, customAccept: false, debugMode: false, @@ -48,6 +50,7 @@ describe('config', () => { tlsReject: false, insecureDownstream: false, universalBroker: false, + version: 'local', }); }); @@ -64,8 +67,10 @@ describe('config', () => { process.env.UNIVERSAL_BROKER_ENABLED = 'true'; await loadBrokerConfig(); const config = getConfig(); + config.brokerClientId = '123'; expect(getClientConfigMetadata(config as LoadedClientOpts)).toEqual({ bodyLogMode: true, + brokerClientId: '123', credPooling: true, customAccept: true, debugMode: true, @@ -75,6 +80,7 @@ describe('config', () => { tlsReject: true, insecureDownstream: true, universalBroker: true, + version: 'local', }); }); @@ -85,8 +91,10 @@ describe('config', () => { process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'; await loadBrokerConfig(); const config = getConfig(); + config.brokerClientId = '123'; expect(getClientConfigMetadata(config as LoadedClientOpts)).toEqual({ bodyLogMode: false, + brokerClientId: '123', credPooling: false, customAccept: false, debugMode: false, @@ -96,6 +104,7 @@ describe('config', () => { tlsReject: false, insecureDownstream: false, universalBroker: false, + version: 'local', }); }); diff --git a/test/unit/connectionsManager/manager.test.ts b/test/unit/connectionsManager/manager.test.ts index d642c33a9..7421e084a 100644 --- a/test/unit/connectionsManager/manager.test.ts +++ b/test/unit/connectionsManager/manager.test.ts @@ -20,6 +20,7 @@ describe('Connections Manager', () => { id: '', isDisabled: false, clientConfig: { + brokerClientId: '123', haMode: false, debugMode: false, bodyLogMode: false, @@ -30,6 +31,7 @@ describe('Connections Manager', () => { customAccept: false, insecureDownstream: false, universalBroker: false, + version: 'local', }, role: Role.primary, };