@@ -23,8 +23,10 @@ const cmdMessages = require('../data/v1/Cmd_pb')
23
23
const wrappers = require ( 'google-protobuf/google/protobuf/wrappers_pb' )
24
24
const activeRequestRepository = require ( '../metric/active-request-repository' )
25
25
const { setInterval } = require ( 'node:timers/promises' )
26
- const DeadlineOptionsBuilder = require ( './deadline-options-builder' )
27
26
const { logError } = require ( './grpc-errors' )
27
+ const StreamDeadlineOptionsBuilder = require ( './stream-deadline-options-builder' )
28
+ const GrpcReadableStreamBuilder = require ( './grpc-readable-stream-builder' )
29
+ const UnaryDeadlineOptionsBuilder = require ( './unary-deadline-options-builder' )
28
30
29
31
// AgentInfoSender.java
30
32
// refresh daily
@@ -39,23 +41,22 @@ class GrpcDataSender {
39
41
this . collectorStatPort = collectorStatPort
40
42
this . collectorSpanPort = collectorSpanPort
41
43
44
+ this . unaryDeadlineOptionsBuilder = new UnaryDeadlineOptionsBuilder ( )
42
45
this . initializeClients ( )
43
46
this . initializeMetadataClients ( )
44
- this . initializeSpanStream ( collectorIp , collectorSpanPort , config )
45
- this . initializeStatStream ( collectorIp , collectorStatPort , config )
46
47
this . initializePingStream ( )
47
48
this . initializeAgentInfoScheduler ( )
48
49
this . initializeProfilerClients ( collectorIp , collectorTcpPort , config )
49
50
50
- this . commandEchoDeadlineOptionsBuilder = new DeadlineOptionsBuilder ( )
51
- this . agentInfoOptionsBuilder = new DeadlineOptionsBuilder ( )
52
- this . metadataOptionsBuilder = new DeadlineOptionsBuilder ( )
51
+ this . clientSideStreamDeadlineOptionsBuilder = new StreamDeadlineOptionsBuilder ( config )
52
+ this . initializeSpanStream ( collectorIp , collectorSpanPort , config )
53
+ this . initializeStatStream ( collectorIp , collectorStatPort , config )
53
54
}
54
55
55
56
close ( ) {
56
57
this . closeScheduler ( )
57
58
if ( this . spanStream ) {
58
- this . spanStream . grpcStream . end ( )
59
+ this . spanStream . end ( )
59
60
}
60
61
if ( this . statStream ) {
61
62
this . statStream . grpcStream . end ( )
@@ -118,10 +119,12 @@ class GrpcDataSender {
118
119
initializeSpanStream ( collectorIp , collectorSpanPort , config ) {
119
120
this . spanClient = new services . SpanClient ( collectorIp + ":" + collectorSpanPort , grpc . credentials . createInsecure ( ) , { interceptors : [ makeAgentInformationMetadataInterceptor ( this . agentInfo ) ] } )
120
121
121
- this . spanStream = new GrpcClientSideStream ( 'spanStream' , this . spanClient , this . spanClient . sendSpan )
122
- if ( config && config . streamDeadlineMinutesClientSide ) {
123
- this . spanStream . setDeadlineMinutes ( config . streamDeadlineMinutesClientSide )
124
- }
122
+ // this.spanStream = new GrpcClientSideStream('spanStream', this.spanClient, this.spanClient.sendSpan)
123
+ // if (config && config.streamDeadlineMinutesClientSide) {
124
+ // this.spanStream.setDeadlineMinutes(config.streamDeadlineMinutesClientSide)
125
+ // }
126
+ this . spanStreamBuilder = new GrpcReadableStreamBuilder ( this . spanClient , 'sendSpan' )
127
+ this . spanStreamBuilder . setDeadlineOptionsBuilder ( this . clientSideStreamDeadlineOptionsBuilder )
125
128
}
126
129
127
130
initializeStatStream ( collectorIp , collectorStatPort , config ) {
@@ -158,7 +161,7 @@ class GrpcDataSender {
158
161
159
162
sendAgentInfo ( agentInfo , callback ) {
160
163
const pAgentInfo = dataConvertor . convertAgentInfo ( agentInfo )
161
- let options = this . agentInfoOptionsBuilder . build ( )
164
+ let options = this . unaryDeadlineOptionsBuilder . build ( )
162
165
this . agentClient . requestAgentInfo ( pAgentInfo , options , ( err , response ) => {
163
166
logError ( 'sendAgentInfo err: ' , err )
164
167
if ( typeof callback === 'function' ) {
@@ -169,7 +172,7 @@ class GrpcDataSender {
169
172
this . closeScheduler ( )
170
173
if ( this . agentInfoDailyScheduler ) {
171
174
this . removeJobForAgentInfo = this . agentInfoDailyScheduler . addJob ( ( ) => {
172
- options = this . agentInfoOptionsBuilder . build ( )
175
+ options = this . unaryDeadlineOptionsBuilder . build ( )
173
176
this . agentClient . requestAgentInfo ( pAgentInfo , options , ( err , response ) => {
174
177
logError ( 'sendAgentInfo err: ' , err )
175
178
if ( typeof callback === 'function' ) {
@@ -183,7 +186,7 @@ class GrpcDataSender {
183
186
184
187
sendApiMetaInfo ( apiMetaInfo , callback ) {
185
188
const pApiMetaData = dataConvertor . convertApiMetaInfo ( apiMetaInfo )
186
- const options = this . metadataOptionsBuilder . build ( )
189
+ const options = this . unaryDeadlineOptionsBuilder . build ( )
187
190
this . metadataClient . requestApiMetaData ( pApiMetaData , options , ( err , response ) => {
188
191
logError ( err )
189
192
if ( callback ) {
@@ -194,7 +197,7 @@ class GrpcDataSender {
194
197
195
198
sendStringMetaInfo ( stringMetaInfo , callback ) {
196
199
const pStringMetaData = dataConvertor . convertStringMetaInfo ( stringMetaInfo )
197
- const options = this . metadataOptionsBuilder . build ( )
200
+ const options = this . unaryDeadlineOptionsBuilder . build ( )
198
201
this . metadataClient . requestStringMetaData ( pStringMetaData , options , ( err , response ) => {
199
202
logError ( err )
200
203
if ( callback ) {
@@ -205,7 +208,7 @@ class GrpcDataSender {
205
208
206
209
sendSqlMetaInfo ( sqlMetaData , callback ) {
207
210
const pSqlMetaData = sqlMetaData . valueOfProtocolBuffer ( )
208
- const options = this . metadataOptionsBuilder . build ( )
211
+ const options = this . unaryDeadlineOptionsBuilder . build ( )
209
212
this . metadataClient . requestSqlMetaData ( pSqlMetaData , options , ( err , response ) => {
210
213
logError ( err )
211
214
if ( callback ) {
@@ -216,7 +219,7 @@ class GrpcDataSender {
216
219
217
220
sendSqlUidMetaData ( sqlMetaData , callback ) {
218
221
const pSqlMetaData = sqlMetaData . valueOfProtocolBuffer ( )
219
- const options = this . metadataOptionsBuilder . build ( )
222
+ const options = this . unaryDeadlineOptionsBuilder . build ( )
220
223
this . metadataClient . requestSqlUidMetaData ( pSqlMetaData , options , ( err , response ) => {
221
224
logError ( err )
222
225
if ( callback ) {
@@ -228,24 +231,24 @@ class GrpcDataSender {
228
231
sendSpan ( span ) {
229
232
try {
230
233
const pSpan = span . toProtocolBuffer ( )
231
- if ( log . isDebug ( ) ) {
232
- log . debug ( `sendSpan pSpan: ${ pSpan } ` )
234
+
235
+ if ( ! this . spanStream ) {
236
+ this . spanStream = this . spanStreamBuilder . build ( )
233
237
}
234
- this . spanStream . write ( pSpan )
238
+ this . spanStream . push ( pSpan )
235
239
} catch ( e ) {
236
- if ( e && e . stack ) {
237
- log . error ( `sendSpan(span) Error: ${ e . stack } ` )
238
- }
240
+ logError ( 'sendSpan(span) Error: ' , e )
239
241
}
240
242
}
241
243
242
244
sendSpanChunk ( spanChunk ) {
243
245
try {
244
246
const pSpanChunk = spanChunk . toProtocolBuffer ( )
245
- if ( log . isDebug ( ) ) {
246
- log . debug ( `sendSpanChunk spanChunk: ` , spanChunk )
247
+
248
+ if ( ! this . spanStream ) {
249
+ this . spanStream = this . spanStreamBuilder . build ( )
247
250
}
248
- this . spanStream . write ( pSpanChunk )
251
+ this . spanStream . push ( pSpanChunk )
249
252
} catch ( e ) {
250
253
if ( e && e . stack ) {
251
254
log . error ( `sendSpanChunk(spanChunk) Error: ${ e . stack } ` )
@@ -349,7 +352,7 @@ class GrpcDataSender {
349
352
}
350
353
351
354
sendCommandEcho ( commandEchoResponse , callback ) {
352
- let options = this . commandEchoDeadlineOptionsBuilder . build ( )
355
+ let options = this . unaryDeadlineOptionsBuilder . build ( )
353
356
this . profilerClient . commandEcho ( commandEchoResponse , options , ( err , response ) => {
354
357
if ( err ) {
355
358
log . error ( err )
0 commit comments