Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#214] handleCommandV2 #217

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ const stringMetaService = require('./context/string-meta-service')
const apiMetaService = require('./context/api-meta-service')
const Scheduler = require('./utils/scheduler')
const AgentStatsMonitor = require('./metric/agent-stats-monitor')
const getConfig = require('./config').getConfig
const { initializeConfig, getConfig } = require('./config')
const PinpointClient = require('./client/pinpoint-client')
const dataSenderFactory = require('./client/data-sender-factory')
const AgentInfo = require('./data/dto/agent-info')
const PinScheduler = require('./metric/ping-scheduler')

class Agent {
constructor(initOptions) {
this.config = getConfig(initOptions)
initializeConfig(initOptions)
this.config = getConfig()

log.init(this.config.logLevel)
log.warn('[Pinpoint Agent] Configuration', this.config)

if (!this.config || !this.config.enable || this.config.enable.toString() !== 'true') {
Expand Down
4 changes: 4 additions & 0 deletions lib/client/grpc-data-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class GrpcDataSender {
if (this.profilerClient) {
this.profilerClient.close()
}
if (this.profilerStream) {
this.profilerStream.grpcStream.end()
}
}

initializeClients(collectorIp, collectorTcpPort, config) {
Expand Down Expand Up @@ -125,6 +128,7 @@ class GrpcDataSender {
profilerBuilder.setGrpcServiceConfig(config.grpcServiceConfig.getProfiler())
}
this.profilerClient = new services.ProfilerCommandServiceClient(collectorIp + ":" + collectorTcpPort, grpc.credentials.createInsecure(), profilerBuilder.build())
this.profilerStream = new GrpcBidirectionalStream('profilerStream', this.profilerClient, this.profilerClient.handleCommandV2)
}

agentInfoRefreshInterval() {
Expand Down
12 changes: 9 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ const CONFIG_FILE_MAP = {
profilerSqlStat: 'profiler-sql-stat'
}

let agentConfig = null

const REQUIRE_CONFIG = {
agentId: 'an Agent ID',
applicationName: 'an Application Name'
Expand Down Expand Up @@ -237,6 +235,11 @@ const getConfig = (initOptions) => {
return agentConfig
}

const initializeConfig = (initOptions) => {
clear()
init(initOptions)
}

const clear = () => agentConfig && (agentConfig = null)

//https://github.com/sindresorhus/is-docker
Expand All @@ -261,11 +264,14 @@ function hasDockerCGroup() {
}
}

let agentConfig = readConfigJson(defaultConfig)

module.exports = {
getConfig,
clear,
readConfigJson,
readRootConfigFile,
getMainModulePath,
isContainerEnvironment
isContainerEnvironment,
initializeConfig,
}
6 changes: 3 additions & 3 deletions lib/context/transaction-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const transactionIdGenerator = require('./sequence-generators').transactionIdGenerator

const DELIMETER = '^'
const delimiter = '^'

class TransactionId {
constructor (agentId, agentStartTime, sequence) {
Expand All @@ -23,12 +23,12 @@ class TransactionId {
}

toString () {
return [this.agentId, this.agentStartTime, this.sequence].join(DELIMETER)
return [this.agentId, this.agentStartTime, this.sequence].join(delimiter)
}

static toTransactionId(str) {
if (str !== null && str !== undefined) {
const r = str.split(DELIMETER)
const r = str.split(delimiter)
if (r.length === 3) {
return new TransactionId(r[0], r[1], r[2])
}
Expand Down
28 changes: 19 additions & 9 deletions lib/instrumentation/context/span-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
* Apache License v2.0
*/

const TransactionId = require("../../context/transaction-id")
const TraceId = require("../../context/trace-id")

class SpanBuilder {
constructor(traceId, agentId, applicationName, applicationServiceType, agentStartTime, serviceType, host, parentApplicationName, parentApplicationType) {
constructor(traceId, agentInfo) {
this.traceId = traceId
this.agentId = agentId
this.applicationName = applicationName
this.agentStartTime = agentStartTime
this.serviceType = serviceType
this.agentId = agentInfo.agentId
this.applicationName = agentInfo.applicationName
this.agentStartTime = agentInfo.agentStartTime
this.serviceType = agentInfo.serviceType
this.spanId = traceId.spanId
this.parentSpanId = traceId.parentSpanId
this.startTime = Date.now()
Expand All @@ -24,12 +27,19 @@ class SpanBuilder {
this.spanEventList = []
this.apiId = null
this.exceptionInfo = null
this.applicationServiceType = applicationServiceType
this.applicationServiceType = agentInfo.applicationServiceType
this.loggingTransactionInfo = null
this.version = 1
this.acceptorHost = host
this.parentApplicationName = parentApplicationName
this.parentApplicationType = parentApplicationType
this.acceptorHost = undefined
this.parentApplicationName = undefined
this.parentApplicationType = undefined
}

static makeSpanBuilderWithSpanId(spanId, agentInfo, parentSpanId = '-1') {
const transactionId = new TransactionId(agentInfo.agentId, agentInfo.agentStartTime)
const traceId = new TraceId(transactionId, spanId, parentSpanId)
const builder = new SpanBuilder(traceId, agentInfo)
return builder
}

static valueOf(span) {
Expand Down
Loading
Loading