Skip to content

Commit 4b16a72

Browse files
committed
[#155] Support SQL UID
* Update gRPC idl * IdGenerator.stringValueOfNext * Change to spanId string type value * Support SqlUidMetaData gRPC stub * Profiler SQL UID by config * Support UID array id * sqluid functional test * Support murmur128 hash algorithm * Add murmur-128 package to NOTICE * Add murmur3-128 source code to repository because of ESM library * parsing result factory pattern * Add BytesStringStringValue * Fix coverage github actions * Uid annotationKey * Update PINPOINT_PROFILER_SQL_STAT ENV in README.md
1 parent 97d6e67 commit 4b16a72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3597
-463
lines changed

NOTICE

+7-1
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,10 @@ spring-projects/spring-framework
146146
https://github.com/spring-projects/spring-framework
147147
Apache License 2.0, https://github.com/spring-projects/spring-framework/blob/master/LICENSE.txt
148148

149-
=====
149+
=====
150+
151+
murmur-128 v1.0.0
152+
https://github.com/LinusU/murmur-128
153+
MIT https://github.com/LinusU/murmur-128/blob/master/package.json
154+
MIT https://github.com/LinusU/fmix/blob/master/package.json
155+
MIT https://github.com/LinusU/encode-utf8/blob/master/package.json

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ PINPOINT_ENABLE | true | If you set it to false, the agent will not work.
6262
PINPOINT_CONTAINER | false | Whether to use docker or kubernetes. If the PINPOINT_CONTAINER environment variable is not set, the agent analyzes the'/.dockerenv' and'/proc/self/cgroup' files to determine whether to use the Docker container. If the KUBERNETES_SERVICE_HOST environment variable exists, it is determined that it is the kubernetes environment and changes it to the true value.
6363
PINPOINT_TRACE_EXCLUSION_URL_PATTERN | | comma-separated string. ex) `/health_check,/admin/**` or [Unit tests](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/01fcbdefe5a0ffba9c957bee0da3fb7397638182/test/utils/ant-path-matcher.test.js#L332)
6464
PINPOINT_TRACE_EXCLUSION_URL_CACHE_SIZE | | If the app is designed so that the pathname of the URL is fixed, if the cache size is set, the pathname of the frequently used URL does not match with patterns. In case of using query for pathname like `/user/1000`, cache is unnecessarily. [Unit tests](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/01fcbdefe5a0ffba9c957bee0da3fb7397638182/test/utils/ant-path-matcher.test.js#L447)
65+
PINPOINT_PROFILER_SQL_STAT | false | SQL uid
6566

6667
### Agent ID
6768
The agent ID is used as the identifier per the server or node. You need to set the hostname or node identifier(The maximum length is 24) on the server.

grpc/grpc-idl

lib/client/data-sender.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const StringMetaInfo = require('../data/dto/string-meta-info')
1313
const Span = require('../context/span')
1414
const SpanChunk = require('../context/span-chunk')
1515
const SqlMetaData = require('./sql-meta-data')
16+
const SqlUidMetaData = require('./sql-uid-meta-data')
1617

1718
class DataSender {
1819
constructor(config, dataSender) {
@@ -45,6 +46,8 @@ class DataSender {
4546
this.dataSender.sendSpanChunk(data)
4647
} else if (data instanceof SqlMetaData) {
4748
this.dataSender.sendSqlMetaInfo(data)
49+
} else if (data instanceof SqlUidMetaData) {
50+
this.dataSender.sendSqlUidMetaData(data)
4851
}
4952
}
5053

lib/client/grpc-data-sender.js

+16
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class GrpcDataSender {
7373
this.requestApiMetaData = new GrpcUnaryRPC('requestApiMetaData', this.metadataClient, this.metadataClient.requestApiMetaData, DEFAULT_METADATA_RETRY_DELAY_MILLIS, DEFAULT_METADATA_RETRY_MAX_COUNT)
7474
this.requestStringMetaData = new GrpcUnaryRPC('requestStringMetaData', this.metadataClient, this.metadataClient.requestStringMetaData, DEFAULT_METADATA_RETRY_DELAY_MILLIS, DEFAULT_METADATA_RETRY_MAX_COUNT)
7575
this.requestSqlMetaData = new GrpcUnaryRPC('requestSqlMetaData', this.metadataClient, this.metadataClient.requestSqlMetaData, DEFAULT_METADATA_RETRY_DELAY_MILLIS, DEFAULT_METADATA_RETRY_MAX_COUNT)
76+
this.requestSqlUidMetaData = new GrpcUnaryRPC('requestSqlUidMetaData', this.metadataClient, this.metadataClient.requestSqlUidMetaData, DEFAULT_METADATA_RETRY_DELAY_MILLIS, DEFAULT_METADATA_RETRY_MAX_COUNT)
7677
}
7778

7879
initializeSpanStream(collectorIp, collectorSpanPort, headerInterceptor, config) {
@@ -178,6 +179,21 @@ class GrpcDataSender {
178179
})
179180
}
180181

182+
sendSqlUidMetaData(sqlMetaData, callback) {
183+
const pSqlMetaData = sqlMetaData.valueOfProtocolBuffer()
184+
if (log.isDebug()) {
185+
log.debug(`sendSqlMetaInfo sqlMetaData: ${JSON.stringify(pSqlMetaData.toObject())}`)
186+
}
187+
this.requestSqlUidMetaData.request(pSqlMetaData, (err, response) => {
188+
if (err) {
189+
log.error(err)
190+
}
191+
if (callback) {
192+
callback(err, response)
193+
}
194+
})
195+
}
196+
181197
sendSpan(span) {
182198
try {
183199
const pSpan = span.spanMessage

lib/client/sql-uid-meta-data.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Pinpoint Node.js Agent
3+
* Copyright 2020-present NAVER Corp.
4+
* Apache License v2.0
5+
*/
6+
7+
'use strict'
8+
const spanMessages = require('../data/v1/Span_pb')
9+
10+
class SqlUidMetaData {
11+
constructor(parsingResult) {
12+
this.sqlUid = parsingResult.getId()
13+
this.sql = parsingResult.getSql()
14+
}
15+
16+
valueOfProtocolBuffer() {
17+
const pSqlMetaData = new spanMessages.PSqlUidMetaData()
18+
pSqlMetaData.setSqluid(this.sqlUid)
19+
pSqlMetaData.setSql(this.sql)
20+
return pSqlMetaData
21+
}
22+
}
23+
24+
module.exports = SqlUidMetaData

lib/config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const ENV_MAP = {
5757
traceExclusionUrlPatterns: valueOfString('PINPOINT_TRACE_EXCLUSION_URL_PATTERN'),
5858
traceExclusionUrlCacheSize: valueOfNumber('PINPOINT_TRACE_EXCLUSION_URL_CACHE_SIZE'),
5959
traceLocationAndFileNameOfCallSite: valueOfBoolean('PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE'),
60+
profilerSqlStat: valueOfBoolean('PINPOINT_PROFILER_SQL_STAT'),
6061
}
6162

6263
const CONFIG_FILE_MAP = {
@@ -83,7 +84,8 @@ const CONFIG_FILE_MAP = {
8384
traceExclusionUrlPatterns: 'trace-exclusion-url.pattern',
8485
traceExclusionUrlCacheSize: 'trace-exclusion-url.cache-size',
8586
streamDeadlineMinutesClientSide: 'stream-deadline-minutes.client-side',
86-
traceLocationAndFileNameOfCallSite: 'trace-location-and-filename-of-call-site'
87+
traceLocationAndFileNameOfCallSite: 'trace-location-and-filename-of-call-site',
88+
profilerSqlStat: 'profiler-sql-stat'
8789
}
8890

8991
let agentConfig = null

lib/constant/annotation-key.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616

1717
SQL_ID: new AnnotationKey(20, "SQL-ID"),
1818
SQL_BINDVALUE: new AnnotationKey(24, "SQL-BindValue", AnnotationKeyProperty.VIEW_IN_RECORD_SET),
19+
SQL_UID: new AnnotationKey(25, 'SQL-UID'),
1920

2021
HTTP_URL: new AnnotationKey(40, 'http.url'),
2122
HTTP_PARAM: new AnnotationKey(41, 'http.param', AnnotationKeyProperty.VIEW_IN_RECORD_SET),

lib/context/id-generator.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class IdGenerator {
1414
get next () {
1515
return Math.floor(Math.random() * this.MAX_NUM)
1616
}
17+
18+
stringValueOfNext() {
19+
return this.next.toString()
20+
}
1721
}
1822

1923
module.exports = new IdGenerator()

lib/context/span-event-recorder.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const AnnotationKeyUtils = require('./annotation-key-utils')
1313
const log = require('../utils/logger')
1414
const sqlMetaDataService = require('../instrumentation/sql/sql-metadata-service')
1515
const Annotations = require('../instrumentation/context/annotation/annotations')
16-
const IntStringStringValue = require('../instrumentation/context/annotation/int-string-string-value')
1716

1817
// https://github.com/pinpoint-apm/pinpoint/blob/master/bootstraps/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/context/SpanEventRecorder.java
1918
class SpanEventRecorder {
@@ -172,11 +171,7 @@ class SpanEventRecorder {
172171
bindString = null
173172
}
174173

175-
this.recordSqlParam(new IntStringStringValue(parsingResult.getId(), parsingResult.getOutput(), bindString))
176-
}
177-
178-
recordSqlParam(intStringStringValue) {
179-
const annotation = Annotations.of(annotationKey.SQL_ID.getCode(), intStringStringValue)
174+
const annotation = parsingResult.newSqlAnnotation(bindString)
180175
this.spanEvent.addAnnotation(annotation)
181176
}
182177

lib/context/trace-context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class TraceContext {
6464
newTraceObject(sampling) {
6565
const transactionId = new TransactionId(this.agentInfo.agentId,
6666
this.agentInfo.agentStartTime.toString())
67-
const spanId = IdGenerator.next
68-
const traceId = new TraceId(transactionId, spanId.toString())
67+
const spanId = IdGenerator.stringValueOfNext()
68+
const traceId = new TraceId(transactionId, spanId)
6969
return this.createTraceObject(traceId, sampling)
7070
}
7171

0 commit comments

Comments
 (0)