Skip to content

Commit

Permalink
[#176] initializeProfilerCommand client
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Aug 16, 2024
1 parent 95795ab commit eb113c8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
23 changes: 19 additions & 4 deletions lib/client/grpc-data-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GrpcDataSender {
this.initializeStatStream(collectorIp, collectorStatPort, config)
this.initializePingStream()
this.initializeAgentInfoScheduler()
this.initializeProfilerClients()
}

close() {
Expand All @@ -57,6 +58,9 @@ class GrpcDataSender {
if (this.statClient) {
this.statClient.close()
}
if (this.profilerClient) {
this.profilerClient.close()
}
}

initializeClients(collectorIp, collectorTcpPort, config) {
Expand All @@ -65,8 +69,8 @@ class GrpcDataSender {
.addInterceptor(socketIdInterceptor)
.addInterceptor(grpcBuiltInRetryHeaderInterceptor)

if (config && config.grpcServiceConfig && typeof config.grpcServiceConfig.getAgentServiceConfig === 'function') {
agentBuilder.setGrpcServiceConfig(config.grpcServiceConfig.getAgentServiceConfig())
if (config && config.grpcServiceConfig && typeof config.grpcServiceConfig.getAgent === 'function') {
agentBuilder.setGrpcServiceConfig(config.grpcServiceConfig.getAgent())
}
this.agentClient = new services.AgentClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(), agentBuilder.build())
}
Expand All @@ -76,8 +80,8 @@ class GrpcDataSender {
.addInterceptor(makeAgentInformationMetadataInterceptor(this.agentInfo))
.addInterceptor(grpcBuiltInRetryHeaderInterceptor)

if (config && config.grpcServiceConfig && typeof config.grpcServiceConfig.getMetadataServiceConfig === 'function') {
metadataBuilder.setGrpcServiceConfig(config.grpcServiceConfig.getMetadataServiceConfig())
if (config && config.grpcServiceConfig && typeof config.grpcServiceConfig.getMetadata === 'function') {
metadataBuilder.setGrpcServiceConfig(config.grpcServiceConfig.getMetadata())
}
this.metadataClient = new services.MetadataClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(), metadataBuilder.build())
}
Expand Down Expand Up @@ -112,6 +116,17 @@ class GrpcDataSender {
this.agentInfoDailyScheduler = new Scheduler(this.agentInfoRefreshInterval())
}

initializeProfilerClients(collectorIp, collectorTcpPort, config) {
const profilerBuilder = new OptionsBuilder()
.addInterceptor(makeAgentInformationMetadataInterceptor(this.agentInfo))
.addInterceptor(grpcBuiltInRetryHeaderInterceptor)

if (config && config.grpcServiceConfig && typeof config.grpcServiceConfig.getProfiler === 'function') {
profilerBuilder.setGrpcServiceConfig(config.grpcServiceConfig.getProfiler())
}
this.profilerClient = new services.ProfilerCommandServiceClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(), profilerBuilder.build())
}

agentInfoRefreshInterval() {
return DEFAULT_AGENT_INFO_REFRESH_INTERVAL_MS
}
Expand Down
27 changes: 21 additions & 6 deletions lib/client/grpc/service-config-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

class ServiceConfig {
constructor(agentServiceConfig, metadataServiceConfig) {
this.agentServiceConfig = agentServiceConfig
this.metadataServiceConfig = metadataServiceConfig
this.agent = agentServiceConfig
this.metadata = metadataServiceConfig
this.profiler = metadataServiceConfig
}

getAgentServiceConfig() {
return this.agentServiceConfig
getAgent() {
return this.agent
}

getMetadataServiceConfig() {
return this.metadataServiceConfig
getMetadata() {
return this.metadata
}

getProfiler() {
return this.profiler
}
}

Expand Down Expand Up @@ -61,13 +66,23 @@ class ServiceConfigBuilder {
return this
}

setProfilerServiceConfig(config) {
if (typeof config !== 'string') {
return this
}

this.profilerServiceConfig = config
return this
}

setJSON(config) {
if (typeof config !== 'object') {
return this
}

this.agentServiceConfig = JSON.stringify(config)
this.metadataServiceConfig = JSON.stringify(config)
this.profilerServiceConfig = JSON.stringify(config)
return this
}

Expand Down
4 changes: 4 additions & 0 deletions test/client/grpc-data-sender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,4 +741,8 @@ test('sendStat', (t) => {
const pCpuLoad = pAgentStat.getCpuload()
t.equal(pCpuLoad.getJvmcpuload(), 0.0003919068831319893, 'cpu.user')
t.equal(pCpuLoad.getSystemcpuload(), 0, 'cpu.system')
})

test('commandEcho', (t) => {
t.end()
})

0 comments on commit eb113c8

Please sign in to comment.