You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/12/18 07:49:41 UTC

[skywalking-nodejs] branch master updated: Avoid init the client twice, make sure the config take effect (#12)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-nodejs.git


The following commit(s) were added to refs/heads/master by this push:
     new 6123eb4  Avoid init the client twice, make sure the config take effect (#12)
6123eb4 is described below

commit 6123eb4ab80b4138abff854e2c5570db44f5185c
Author: Quanjie.Deng <ww...@163.com>
AuthorDate: Fri Dec 18 15:49:31 2020 +0800

    Avoid init the client twice, make sure the config take effect (#12)
    
    Co-authored-by: kezhenxu94 <ke...@apache.org>
---
 src/agent/protocol/grpc/clients/HeartbeatClient.ts   | 18 ++++++++----------
 src/agent/protocol/grpc/clients/TraceReportClient.ts | 19 ++++++++-----------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/agent/protocol/grpc/clients/HeartbeatClient.ts b/src/agent/protocol/grpc/clients/HeartbeatClient.ts
old mode 100644
new mode 100755
index 8873d3d..bd36b7a
--- a/src/agent/protocol/grpc/clients/HeartbeatClient.ts
+++ b/src/agent/protocol/grpc/clients/HeartbeatClient.ts
@@ -33,20 +33,18 @@ import * as os from 'os';
 const logger = createLogger(__filename);
 
 class HeartbeatClient implements Client {
-  heartbeatClient: ManagementServiceClient;
+  heartbeatClient?: ManagementServiceClient;
   heartbeatTimer?: NodeJS.Timeout;
 
-  constructor() {
-    this.heartbeatClient = new ManagementServiceClient(config.collectorAddress, grpc.credentials.createInsecure(), {
-      interceptors: [AuthInterceptor],
-    });
-  }
-
   get isConnected(): boolean {
-    return this.heartbeatClient.getChannel().getConnectivityState(true) === connectivityState.READY;
+    return this.heartbeatClient?.getChannel().getConnectivityState(true) === connectivityState.READY;
   }
 
   start() {
+    this.heartbeatClient = new ManagementServiceClient(config.collectorAddress, grpc.credentials.createInsecure(), {
+      interceptors: [AuthInterceptor],
+    });
+
     if (this.heartbeatTimer) {
       logger.warn(`
         The heartbeat timer has already been scheduled,
@@ -71,7 +69,7 @@ class HeartbeatClient implements Client {
     ]);
 
     this.heartbeatTimer = setInterval(() => {
-      this.heartbeatClient.reportInstanceProperties(
+      this.heartbeatClient?.reportInstanceProperties(
         instanceProperties,
 
         (error, _) => {
@@ -80,7 +78,7 @@ class HeartbeatClient implements Client {
           }
         },
       );
-      this.heartbeatClient.keepAlive(
+      this.heartbeatClient?.keepAlive(
         keepAlivePkg,
 
         (error, _) => {
diff --git a/src/agent/protocol/grpc/clients/TraceReportClient.ts b/src/agent/protocol/grpc/clients/TraceReportClient.ts
old mode 100644
new mode 100755
index 028ddbf..9a18032
--- a/src/agent/protocol/grpc/clients/TraceReportClient.ts
+++ b/src/agent/protocol/grpc/clients/TraceReportClient.ts
@@ -30,19 +30,11 @@ import SegmentObjectAdapter from '../SegmentObjectAdapter';
 const logger = createLogger(__filename);
 
 class TraceReportClient implements Client {
-  reporterClient: TraceSegmentReportServiceClient;
+  reporterClient?: TraceSegmentReportServiceClient;
   timeout: any;
 
-  constructor() {
-    this.reporterClient = new TraceSegmentReportServiceClient(
-      config.collectorAddress,
-      grpc.credentials.createInsecure(),
-      { interceptors: [AuthInterceptor] },
-    );
-  }
-
   get isConnected(): boolean {
-    return this.reporterClient.getChannel().getConnectivityState(true) === connectivityState.READY;
+    return this.reporterClient?.getChannel().getConnectivityState(true) === connectivityState.READY;
   }
 
   ref() {
@@ -50,9 +42,14 @@ class TraceReportClient implements Client {
   }
 
   start() {
+    this.reporterClient = new TraceSegmentReportServiceClient(
+      config.collectorAddress,
+      grpc.credentials.createInsecure(),
+      { interceptors: [AuthInterceptor] },
+    );
     const reportFunction = () => {
       try {
-        if (buffer.length === 0) {
+        if (buffer.length === 0 || !this.reporterClient) {
           return;
         }