From c88e1db103c4f3b541721213e827bc61b14bcbf4 Mon Sep 17 00:00:00 2001 From: Yongseok Date: Wed, 3 Jul 2024 15:36:23 +0900 Subject: [PATCH] [#182] Support ServiceConfig spec( https://github.com/grpc/grpc/blob/master/doc/service_config.md ) --- lib/client/grpc/service-config-builder.js | 40 +++++++++++++++++++++++ lib/config.js | 10 ++++++ test/client/service-config-builder.js | 29 ---------------- 3 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 lib/client/grpc/service-config-builder.js delete mode 100644 test/client/service-config-builder.js diff --git a/lib/client/grpc/service-config-builder.js b/lib/client/grpc/service-config-builder.js new file mode 100644 index 00000000..df1f0f9d --- /dev/null +++ b/lib/client/grpc/service-config-builder.js @@ -0,0 +1,40 @@ +/** + * Pinpoint Node.js Agent + * Copyright 2020-present NAVER Corp. + * Apache License v2.0 + */ + +'use strict' + +class ServiceConfig { + constructor(agentServiceConfig, metadataServiceConfig) { + this.agentServiceConfig = agentServiceConfig + this.metadataServiceConfig = metadataServiceConfig + } + + getAgentServiceConfig() { + return this.agentServiceConfig + } + + getMetadataServiceConfig() { + return this.metadataServiceConfig + } +} + +class ServiceConfigBuilder { + setAgentServiceConfig(config) { + this.agentServiceConfig = config + return this + } + + setMetadataServiceConfig(config) { + this.metadataServiceConfig = config + return this + } + + build() { + return new ServiceConfig(this.agentServiceConfig, this.metadataServiceConfig) + } +} + +module.exports = ServiceConfigBuilder \ No newline at end of file diff --git a/lib/config.js b/lib/config.js index 46ad9cc1..688af700 100644 --- a/lib/config.js +++ b/lib/config.js @@ -12,6 +12,7 @@ const defaultConfig = require('./pinpoint-config-default') const log = require('./utils/logger') const { setLog } = require('./supports') const { makeLogLevelLog } = require('./utils/log/log-level-logger') +const ServiceConfigBuilder = require('./client/grpc/service-config-builder') const valueOfString = (envName) => { return () => { @@ -140,6 +141,8 @@ const configurationValueValidations = { } } +const defaultServiceConfigBuilder = new ServiceConfigBuilder() + const init = (initOptions = {}) => { agentConfig = Object.assign({}, readConfigJson(defaultConfig), @@ -164,6 +167,13 @@ const init = (initOptions = {}) => { for (const [key, validation] of Object.entries(configurationValueValidations)) { validation() } + + if (initOptions['grpc.service_config'] && initOptions['grpc.service_config'].name === 'ServiceConfig') { + const config = initOptions['grpc.service_config'] + agentConfig.serviceConfig = config + } else { + agentConfig.serviceConfig = defaultServiceConfigBuilder.build() + } } const readFromEnv = () => { diff --git a/test/client/service-config-builder.js b/test/client/service-config-builder.js deleted file mode 100644 index fd5da1ec..00000000 --- a/test/client/service-config-builder.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Pinpoint Node.js Agent - * Copyright 2020-present NAVER Corp. - * Apache License v2.0 - */ - -'use strict' - -class ServiceConfig { - -} - -class ServiceConfigBuilder { - setAgentClient(config) { - this.agentClient = config - return this - } - - setMetadataClient(config) { - this.metadataClient = config - return this - } - - build() { - return new ServiceConfig() - } -} - -module.exports = ServiceConfigBuilder \ No newline at end of file