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 9fa2192 commit 38613da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
15 changes: 11 additions & 4 deletions lib/client/grpc-data-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Scheduler = require('../utils/scheduler')
const makeAgentInformationMetadataInterceptor = require('./grpc/make-agent-information-metadata-interceptor')
const socketIdInterceptor = require('./grpc/socketid-interceptor')
const CallArgumentsBuilder = require('./call-arguments-builder')
const OptionsBuilder = require('./grpc/options-builder')

// AgentInfoSender.java
// refresh daily
Expand All @@ -40,7 +41,7 @@ class GrpcDataSender {
config
) {
this.agentInfo = agentInfo
this.initializeClients(collectorIp, collectorTcpPort)
this.initializeClients(collectorIp, collectorTcpPort, config)
this.initializeSpanStream(collectorIp, collectorSpanPort, config)
this.initializeStatStream(collectorIp, collectorStatPort, config)
this.initializePingStream()
Expand Down Expand Up @@ -72,9 +73,15 @@ class GrpcDataSender {
}
}

initializeClients(collectorIp, collectorTcpPort) {
this.agentClient = new services.AgentClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(),
{ interceptors: [makeAgentInformationMetadataInterceptor(this.agentInfo), socketIdInterceptor] })
initializeClients(collectorIp, collectorTcpPort, config) {
const builder = new OptionsBuilder()
.addInterceptor(makeAgentInformationMetadataInterceptor(this.agentInfo))
.addInterceptor(socketIdInterceptor)

if (config && config.grpcServiceConfig && typeof config.grpcServiceConfig.getAgentServiceConfig === 'function') {
builder.setGrpcServiceConfig(config.grpcServiceConfig.getAgentServiceConfig())
}
this.agentClient = new services.AgentClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(), builder.build())

this.metadataClient = new services.MetadataClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(),
{ interceptors: [makeAgentInformationMetadataInterceptor(this.agentInfo)] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict'

class Options {
class OptionsBuilder {
constructor() {
this.options = {
interceptors: []
Expand All @@ -15,15 +15,17 @@ class Options {

addInterceptor(interceptor) {
this.options.interceptors.push(interceptor)
return this
}

setGrpcServiceConfig(serviceConfig) {
this.options['grpc.service_config'] = serviceConfig
return this
}

options() {
build() {
return this.options
}
}

module.exports = Options
module.exports = OptionsBuilder
4 changes: 2 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ const init = (initOptions = {}) => {

if (initOptions['grpc.service_config'] && initOptions['grpc.service_config'].name === 'ServiceConfig') {
const config = initOptions['grpc.service_config']
agentConfig.serviceConfig = config
agentConfig.grpcServiceConfig = config
} else {
agentConfig.serviceConfig = defaultServiceConfigBuilder.build()
agentConfig.grpcServiceConfig = defaultServiceConfigBuilder.build()
}
}

Expand Down

0 comments on commit 38613da

Please sign in to comment.