Skip to content

Commit 32598af

Browse files
committed
[#371] Add ConfigurationBuilder for flexible config management
1 parent 543351d commit 32598af

File tree

13 files changed

+108
-108
lines changed

13 files changed

+108
-108
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
const { AgentBuilder } = require('./lib/agent-builder')
1010
const AgentInfo = require('./lib/data/dto/agent-info')
11-
const { getConfig2 } = require('./lib/config')
11+
const { getConfig } = require('./lib/config')
1212
const { LogBuilder } = require('./lib/utils/log/log-builder')
1313
const logger = require('./lib/utils/log/logger')
1414

15-
const config = getConfig2()
15+
const config = getConfig()
1616
logger.setRootLogger(LogBuilder.createDefaultLogBuilder().setConfig(config).build())
1717

1818
const agentInfo = AgentInfo.make(config)

lib/agent-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { ModuleHook } = require('./instrumentation/module-hook')
1616
const Scheduler = require('./utils/scheduler')
1717
const AgentStatsMonitor = require('./metric/agent-stats-monitor')
1818
const PingScheduler = require('./metric/ping-scheduler')
19-
const { getConfig2 } = require('./config')
19+
const { getConfig } = require('./config')
2020

2121
class Agent {
2222
constructor(agentInfo, config, logger) {
@@ -117,7 +117,7 @@ class AgentBuilder {
117117

118118
build() {
119119
if (!this.config) {
120-
this.config = getConfig2()
120+
this.config = getConfig()
121121
}
122122

123123
const agent = new Agent(this.agentInfo, this.config, logger)

lib/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ const valueValidations = {
430430
}
431431

432432
let configInstance
433-
const getConfig2 = (json) => {
433+
const getConfig = (json) => {
434434
if (!configInstance) {
435435
configInstance = new ConfigBuilder(json).build()
436436
}
@@ -445,15 +445,15 @@ const setConfig = (config) => {
445445
configInstance = config
446446
}
447447

448-
const clear2 = () => configInstance && (configInstance = null)
448+
const clear = () => configInstance && (configInstance = null)
449449

450450
module.exports = {
451451
readConfigJson,
452452
readRootConfigFile,
453453
getMainModulePath,
454454
isContainerEnvironment,
455455
ConfigBuilder,
456-
getConfig2,
456+
getConfig,
457457
setConfig,
458-
clear2
458+
clear
459459
}

lib/context/method-descriptor-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class MethodDescriptorBuilder {
177177
}
178178

179179
shouldCallSiteFileNameAndLineNumber() {
180-
const conf = config.getConfig2()
180+
const conf = config.getConfig()
181181
if (!conf || !conf.traceLocationAndFileNameOfCallSite) {
182182
return false
183183
}

lib/instrumentation/http/http-status-code-errors-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
'use strict'
88

9-
const { getConfig2 } = require('./../../config')
9+
const { getConfig } = require('./../../config')
1010

1111
class HttpStatusCodeErrors {
1212
constructor(errors) {
@@ -68,7 +68,7 @@ class HttpStatusCodeErrorsBuilder {
6868
let httpStatusCodeErrors
6969
function getHttpStatusCodeErrors() {
7070
if (!httpStatusCodeErrors) {
71-
const config = getConfig2()
71+
const config = getConfig()
7272
httpStatusCodeErrors = new HttpStatusCodeErrorsBuilder(config.httpStatusCodeErrors).build()
7373
}
7474
return httpStatusCodeErrors

lib/instrumentation/sql/parsing-result.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const UidParsingResult = require('./uid-parsing-result')
1212

1313
class ParsingResult {
1414
constructor(originalSql, normalizedSql) {
15-
const conf = config.getConfig2()
15+
const conf = config.getConfig()
1616
if (conf && conf.profilerSqlStat) {
1717
this.result = new UidParsingResult(originalSql, normalizedSql)
1818
} else {

test/agent/env-config.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*/
66

77
const test = require('tape')
8-
const { getConfig2, clear2, isContainerEnvironment } = require('../../lib/config')
8+
const { getConfig, clear, isContainerEnvironment } = require('../../lib/config')
99

1010
function isRunGithubAction() {
1111
return isContainerEnvironment
1212
}
1313

1414

1515
test('should return the string value when the env value is string type', function(t) {
16-
clear2()
16+
clear()
1717

1818
process.env['PINPOINT_AGENT_ID'] = "agentId"
1919
process.env['PINPOINT_APPLICATION_NAME'] = "appication name"
2020
process.env['PINPOINT_COLLECTOR_IP'] = "192.168.78.79"
2121
process.env['PINPOINT_LOG_LEVEL'] = "Debug"
2222

23-
const given = getConfig2()
23+
const given = getConfig()
2424
t.equal(given.agentId, "agentId", "given PINPOINT_AGENT_ID env, should equal config")
2525
t.equal(given.applicationName, "appication name", "given PINPOINT_APPLICATION_NAME env, should equal config")
2626
t.equal(given.collectorIp, "192.168.78.79", "given PINPOINT_COLLECTOR_IP env, should equal config")
@@ -31,15 +31,15 @@ test('should return the string value when the env value is string type', functio
3131
delete process.env.PINPOINT_COLLECTOR_IP
3232
delete process.env.PINPOINT_LOG_LEVEL
3333

34-
clear2()
34+
clear()
3535
t.end()
3636
})
3737

3838
const givenDefaultIdAndName = () => {
3939
process.env['PINPOINT_AGENT_ID'] = "agentId"
4040
process.env['PINPOINT_APPLICATION_NAME'] = "appication name"
4141

42-
const given = getConfig2()
42+
const given = getConfig()
4343

4444
delete process.env.PINPOINT_AGENT_ID
4545
delete process.env.PINPOINT_APPLICATION_NAME
@@ -48,7 +48,7 @@ const givenDefaultIdAndName = () => {
4848
}
4949

5050
test('should return the number value when the env value is number type', function(t) {
51-
clear2()
51+
clear()
5252

5353
process.env['PINPOINT_SERVICE_TYPE'] = "1400"
5454
process.env['PINPOINT_COLLECTOR_TCP_PORT'] = "9894"
@@ -69,12 +69,12 @@ test('should return the number value when the env value is number type', functio
6969
delete process.env.PINPOINT_COLLECTOR_SPAN_PORT
7070
delete process.env.PINPOINT_SAMPLING_RATE
7171

72-
clear2()
72+
clear()
7373
t.end()
7474
})
7575

7676
test('should return the true value when the env value is boolean type', function(t) {
77-
clear2()
77+
clear()
7878

7979
process.env['PINPOINT_SAMPLING'] = "true"
8080
process.env['PINPOINT_ENABLE'] = "true"
@@ -89,18 +89,18 @@ test('should return the true value when the env value is boolean type', function
8989
delete process.env.PINPOINT_ENABLE
9090
delete process.env.PINPOINT_CONTAINER
9191

92-
clear2()
92+
clear()
9393
t.end()
9494
})
9595

9696
test('should return the false value when the env value is boolean type', function(t) {
97-
clear2()
97+
clear()
9898

9999
process.env['PINPOINT_SAMPLING'] = "false"
100100
process.env['PINPOINT_ENABLE'] = "false"
101101
process.env['PINPOINT_CONTAINER'] = "false"
102102

103-
const given = getConfig2()
103+
const given = getConfig()
104104
t.equal(given.sampling, false, 'given PINPOINT_SAMPLING env, should equal config')
105105
t.equal(given.enable, false, 'given PINPOINT_ENABLE env, should equal config')
106106
if (!isRunGithubAction()) {
@@ -111,12 +111,12 @@ test('should return the false value when the env value is boolean type', functio
111111
delete process.env.PINPOINT_ENABLE
112112
delete process.env.PINPOINT_CONTAINER
113113

114-
clear2()
114+
clear()
115115
t.end()
116116
})
117117

118118
test('should not exist in the process.env property when you do not set an environment variable', function(t) {
119-
clear2()
119+
clear()
120120

121121
delete process.env.PINPOINT_COLLECTOR_IP
122122
delete process.env.PINPOINT_LOG_LEVEL
@@ -149,12 +149,12 @@ test('should not exist in the process.env property when you do not set an enviro
149149
t.equal(given.collectorSpanPort, 9993, 'No set PINPOINT_COLLECTOR_SPAN_PORT env, should equal default config')
150150
t.equal(given.sampleRate, 10, 'No set PINPOINT_SAMPLING_RATE env, should equal default config')
151151

152-
clear2()
152+
clear()
153153
t.end()
154154
})
155155

156156
test(`default config`, (t) => {
157-
clear2()
157+
clear()
158158

159159
const given = givenDefaultIdAndName()
160160
t.equal(given.enabledActiveThreadCount, false, 'No set activeThreadCount')
@@ -163,10 +163,10 @@ test(`default config`, (t) => {
163163
})
164164

165165
test(`detect container`, (t) => {
166-
clear2()
166+
clear()
167167

168168
process.env['KUBERNETES_SERVICE_HOST'] = "aaa"
169-
const given = getConfig2()
169+
const given = getConfig()
170170

171171
t.plan(1)
172172
t.equal(given.container, true, 'container detect')
@@ -175,10 +175,10 @@ test(`detect container`, (t) => {
175175
})
176176

177177
test(`detect container2`, (t) => {
178-
clear2()
178+
clear()
179179

180180
if (!isRunGithubAction()) {
181-
const given = getConfig2()
181+
const given = getConfig()
182182
t.equal(given.container, false, 'container detect')
183183
}
184184

test/client/grpc-fixture.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'use strict'
88

99
const agent = require('../support/agent-singleton-mock')
10-
const { clear2, getConfig2 } = require('../../lib/config')
10+
const { clear, getConfig } = require('../../lib/config')
1111
const GrpcDataSender = require('../../lib/client/grpc-data-sender')
1212
const SpanBuilder = require('../../lib/context/span-builder')
1313
const RemoteTraceRootBuilder = require('../../lib/context/remote-trace-root-builder')
@@ -20,10 +20,10 @@ let callMetadata = []
2020
function beforeSpecificOne(port, one, serviceConfig) {
2121
callCount = 0
2222
afterCount = 0
23-
clear2()
23+
clear()
2424
callRequests = []
2525
callMetadata = []
26-
const actualConfig = getConfig2({
26+
const actualConfig = getConfig({
2727
'grpc': { 'service_config': serviceConfig },
2828
'collector': {
2929
'ip': '127.0.0.1',

test/client/grpc-unary-rpc.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const AgentInfo = require('../../lib/data/dto/agent-info')
1414
const ApiMetaInfo = require('../../lib/data/dto/api-meta-info')
1515
const StringMetaInfo = require('../../lib/data/dto/string-meta-info')
1616
const MethodDescriptorBuilder = require('../../lib/context/method-descriptor-builder')
17-
const { clear2, getConfig2 } = require('../../lib/config')
17+
const { clear, getConfig } = require('../../lib/config')
1818
const SqlMetaData = require('../../lib/client/sql-meta-data')
1919
const sqlMetadataService = require('../../lib/instrumentation/sql/sql-metadata-service')
2020
const SqlUidMetaData = require('../../lib/client/sql-uid-meta-data')
@@ -424,10 +424,10 @@ test('sendSqlMetaData retry', (t) => {
424424
})
425425

426426
test('sendSqlUidMetaData retry', (t) => {
427-
clear2()
427+
clear()
428428
process.env['PINPOINT_PROFILER_SQL_STAT'] = 'true'
429429
sqlMetadataService.cache.cache.clear()
430-
const conf = getConfig2()
430+
const conf = getConfig()
431431
t.true(conf.profilerSqlStat, 'profiler SQL Stat is false')
432432

433433
const server = new grpc.Server()
@@ -467,7 +467,7 @@ test('sendSqlUidMetaData retry', (t) => {
467467
dataSender.close()
468468
server.forceShutdown()
469469
delete process.env.PINPOINT_PROFILER_SQL_STAT
470-
clear2()
470+
clear()
471471
})
472472
})
473473
})

0 commit comments

Comments
 (0)