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

[#242] Fix Active Request statics Histogram gRPC Data convert No Data #260

Merged
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
4 changes: 3 additions & 1 deletion demo/express/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ router.get('/', async function(req, res, next) {
const json = await response.json()
console.log(json)

res.render('index', { title: 'Express' })
setTimeout(() => {
res.render('index', { title: 'Express' })
}, 3000)
})

router.get('/api', function(req, res, next) {
Expand Down
4 changes: 2 additions & 2 deletions lib/client/grpc-data-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ class GrpcDataSender {
try {
const pStatMessage = dataConvertor.convertStat(stat)
if (log.isDebug()) {
log.debug(`sendStats pStatMessage: ${stat}`)
log.debug('sendStats pStatMessage: ', stat)
}
this.statStream.write(pStatMessage)
} catch (e) {
if (e && e.stack) {
log.error(`sendStat(stat) Error: ${e.stack}`)
log.error('sendStat(stat) Error: ', e)
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions lib/context/trace-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AsyncSpanChunkBuilder = require('./trace/async-span-chunk-builder')
const ChildTraceBuilder = require('./trace/child-trace-builder')
const DisableChildTrace = require('./trace/disable-child-trace')
const disableAsyncId = require('./trace/disable-async-id')
const ActiveTraceRepository = require('../metric/active-trace-repository')
const activeRequestRepository = require('../metric/active-request-repository')

class TraceContext {
constructor(agentInfo, dataSender, config) {
Expand All @@ -35,7 +35,6 @@ class TraceContext {
this.enableSampling = config.sampling
}
this.traceSampler = new TraceSampler(agentInfo, config)
this.activeRequestRepository = new ActiveTraceRepository()
}

getAgentInfo() {
Expand Down Expand Up @@ -81,10 +80,10 @@ class TraceContext {
if (!trace) {
return
}

try {
trace.close()
this.activeRequestRepository.remove(trace.getTraceRoot())
// activeTrace.remove(trace)
activeRequestRepository.remove(trace.getTraceRoot())
} catch (e) {
log.error('Fail to complete trace object', e)
}
Expand Down Expand Up @@ -118,7 +117,7 @@ class TraceContext {
}

newLocalTrace(traceRoot) {
this.activeRequestRepository.register(traceRoot)
activeRequestRepository.register(traceRoot)
return new DisableTrace(traceRoot)
}

Expand All @@ -137,7 +136,7 @@ class TraceContext {
const spanBuilder = new SpanBuilder(traceRoot)
const spanChunkBuilder = new SpanChunkBuilder(traceRoot)
const repository = new SpanRepository(spanChunkBuilder, this.dataSender, this.agentInfo)
this.activeRequestRepository.register(traceRoot)
activeRequestRepository.register(traceRoot)
return new Trace2(spanBuilder, repository)
}

Expand Down
7 changes: 4 additions & 3 deletions lib/data/grpc-data-convertor.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@ const convertStat = (stat) => {
pActiveTraceHistogram.setVersion(0)
pActiveTraceHistogram.setHistogramschematype(stat.activeTrace.typeCode)

const count = stat.activeTrace.fastCount + stat.activeTrace.normalCount + stat.activeTrace.slowCount + stat.activeTrace.verySlowCount
pActiveTraceHistogram.addActivetracecount(count)

stat.activeTrace.histogramValues?.().forEach((value, index) => {
pActiveTraceHistogram.addActivetracecount(value)
})
pActiveTrace.setHistogram(pActiveTraceHistogram)
pAgentStat.setActivetrace(pActiveTrace)
}

pStatMessage.setAgentstat(pAgentStat)
Expand Down
48 changes: 48 additions & 0 deletions lib/metric/active-request-repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/

'use strict'

const SimpleCache = require('../utils/simple-cache')
const ActiveTraceHistogram = require('./active-trace-histogram')
const HistogramSchema = require('./histogram-schema')

// DefaultActiveTraceRepository.java
class ActiveRequestRepository {
constructor() {
this.activeTraceCache = new SimpleCache()
}

register(localTraceRoot) {
const id = localTraceRoot.getTransactionId()
if (typeof id !== 'string' || id.length < 1) {
return
}

this.activeTraceCache.put(id, localTraceRoot)
}

remove(localTraceRoot) {
const id = localTraceRoot.getTransactionId()
this.activeTraceCache.delete(id)
}

getCurrentActiveTraceHistogram() {
const currentTime = Date.now()
return this.getActiveTraceHistogram(currentTime)
}

getActiveTraceHistogram(currentTime) {
const histogram = new ActiveTraceHistogram(HistogramSchema.NORMAL_SCHEMA)
this.activeTraceCache.getAll().forEach((traceRoot) => {
const elapsedTime = currentTime - traceRoot.getTraceStartTime()
histogram.increase(elapsedTime)
})
return histogram
}
}

module.exports = new ActiveRequestRepository()
15 changes: 12 additions & 3 deletions lib/metric/active-trace-histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

const HistogramSchema = require('./histogram-schema')

class ActiveTraceHistogram{
constructor (schema) {
class ActiveTraceHistogram {
constructor(schema) {
this.schema = schema || HistogramSchema.NORMAL_SCHEMA
this.typeCode = schema.typeCode
this.fastCount = 0
Expand All @@ -18,7 +18,7 @@ class ActiveTraceHistogram{
this.verySlowCount = 0
}

increase (elapsedTime) {
increase(elapsedTime) {
if (!elapsedTime) {
return
}
Expand All @@ -33,6 +33,15 @@ class ActiveTraceHistogram{
this.verySlowCount++
}
}

histogramValues() {
return [
this.fastCount,
this.normalCount,
this.slowCount,
this.verySlowCount
]
}
}

module.exports = ActiveTraceHistogram
Expand Down
32 changes: 0 additions & 32 deletions lib/metric/active-trace-repository.js

This file was deleted.

3 changes: 2 additions & 1 deletion lib/metric/agent-stats-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

const ResourceStatsCollector = require('./resource-stats-collector')
const log = require('../utils/logger')
const activeRequestRepository = require('../metric/active-request-repository')

class AgentStatsMonitor {
constructor(dataSender, agentId, agentStartTime) {
Expand Down Expand Up @@ -47,7 +48,7 @@ class AgentStatsMonitor {
collectInterval: 1000,
memory: this.resourceStatCollector.getMemoryStats(),
cpu: cpuStatus,
// activeTrace: activeTrace.getCurrentActiveTraceHistogram(),
activeTrace: activeRequestRepository.getCurrentActiveTraceHistogram(),
}
}
}
Expand Down
Loading