Skip to content

Commit

Permalink
[pinpoint-apm#182] Support ServiceConfig spec( https://github.com/grp…
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Jul 3, 2024
1 parent 2866426 commit c88e1db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
40 changes: 40 additions & 0 deletions lib/client/grpc/service-config-builder.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -140,6 +141,8 @@ const configurationValueValidations = {
}
}

const defaultServiceConfigBuilder = new ServiceConfigBuilder()

const init = (initOptions = {}) => {
agentConfig = Object.assign({},
readConfigJson(defaultConfig),
Expand All @@ -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 = () => {
Expand Down
29 changes: 0 additions & 29 deletions test/client/service-config-builder.js

This file was deleted.

0 comments on commit c88e1db

Please sign in to comment.