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/11/30 07:10:31 UTC

[skywalking-nodejs] 01/01: Clean up unused codes and polish

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

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

commit 2fa4cca1aed3b34c5fe17c15ed72a54403b8a853
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Mon Nov 30 15:09:44 2020 +0800

    Clean up unused codes and polish
---
 src/trace/context/Context.ts      |  5 -----
 src/trace/context/DummyContext.ts | 15 ---------------
 src/trace/context/SegmentRef.ts   | 15 ---------------
 src/trace/context/Snapshot.ts     | 27 ---------------------------
 src/trace/context/SpanContext.ts  | 23 +++--------------------
 src/trace/span/Span.ts            |  3 ---
 tests/plugins/http/server.ts      |  1 +
 7 files changed, 4 insertions(+), 85 deletions(-)

diff --git a/src/trace/context/Context.ts b/src/trace/context/Context.ts
index d1b234e..54d4023 100644
--- a/src/trace/context/Context.ts
+++ b/src/trace/context/Context.ts
@@ -19,7 +19,6 @@
 
 import Span from '../../trace/span/Span';
 import Segment from '../../trace/context/Segment';
-import Snapshot from '../../trace/context/Snapshot';
 import { ContextCarrier } from './ContextCarrier';
 
 export default interface Context {
@@ -45,8 +44,4 @@ export default interface Context {
   resync(span: Span): void;
 
   currentSpan(): Span | undefined;
-
-  capture(): Snapshot;
-
-  restore(snapshot: Snapshot): void;
 }
diff --git a/src/trace/context/DummyContext.ts b/src/trace/context/DummyContext.ts
index 68c44cf..489d533 100644
--- a/src/trace/context/DummyContext.ts
+++ b/src/trace/context/DummyContext.ts
@@ -22,8 +22,6 @@ import Span from '../../trace/span/Span';
 import DummySpan from '../../trace/span/DummySpan';
 import Segment from '../../trace/context/Segment';
 import { SpanType } from '../../proto/language-agent/Tracing_pb';
-import Snapshot from '../../trace/context/Snapshot';
-import ID from '../../trace/ID';
 import { ContextCarrier } from './ContextCarrier';
 
 export default class DummyContext implements Context {
@@ -67,17 +65,4 @@ export default class DummyContext implements Context {
   currentSpan(): Span {
     throw new Error('DummyContext.currentSpan() should never be called!');
   }
-
-  capture(): Snapshot {
-    return {
-      parentEndpoint: '',
-      segmentId: new ID(),
-      spanId: 0,
-      traceId: new ID(),
-    };
-  }
-
-  restore(snapshot: Snapshot) {
-    return;
-  }
 }
diff --git a/src/trace/context/SegmentRef.ts b/src/trace/context/SegmentRef.ts
index 2cc8cad..430579e 100644
--- a/src/trace/context/SegmentRef.ts
+++ b/src/trace/context/SegmentRef.ts
@@ -17,9 +17,7 @@
  *
  */
 
-import Snapshot from '../../trace/context/Snapshot';
 import ID from '../../trace/ID';
-import config from '../../config/AgentConfig';
 import { ContextCarrier } from './ContextCarrier';
 
 export default class SegmentRef {
@@ -54,17 +52,4 @@ export default class SegmentRef {
       carrier.clientAddress!,
     );
   }
-
-  static fromSnapshot(snapshot: Snapshot): SegmentRef {
-    return new SegmentRef(
-      'CrossThread',
-      new ID(snapshot.traceId.toString()),
-      new ID(snapshot.segmentId.toString()),
-      snapshot.spanId,
-      config.serviceName,
-      config.serviceInstance,
-      snapshot.parentEndpoint,
-      '',
-    );
-  }
 }
diff --git a/src/trace/context/Snapshot.ts b/src/trace/context/Snapshot.ts
deleted file mode 100644
index e5de84b..0000000
--- a/src/trace/context/Snapshot.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-/*!
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import ID from '../../trace/ID';
-
-export default interface Snapshot {
-  segmentId: ID;
-  spanId: number;
-  traceId: ID;
-  parentEndpoint: string;
-}
diff --git a/src/trace/context/SpanContext.ts b/src/trace/context/SpanContext.ts
index fab8305..f466dd1 100644
--- a/src/trace/context/SpanContext.ts
+++ b/src/trace/context/SpanContext.ts
@@ -26,8 +26,6 @@ import LocalSpan from '../../trace/span/LocalSpan';
 import buffer from '../../agent/Buffer';
 import { createLogger } from '../../logging';
 import { executionAsyncId } from 'async_hooks';
-import Snapshot from '../../trace/context/Snapshot';
-import SegmentRef from '../../trace/context/SegmentRef';
 import { ContextCarrier } from './ContextCarrier';
 import ContextManager from './ContextManager';
 
@@ -131,7 +129,7 @@ export default class SpanContext implements Context {
       }
     }
 
-    if (--this.nSpans == 0) {
+    if (--this.nSpans === 0) {
       buffer.put(this.segment);
       ContextManager.clear();
       return true;
@@ -149,7 +147,8 @@ export default class SpanContext implements Context {
       ContextManager.spans.splice(idx, 1);
     }
 
-    if (this.nSpans === 1) {  // this will pass the context to child async task so it doesn't mess with other tasks here
+    if (this.nSpans === 1) {
+      // this will pass the context to child async task so it doesn't mess with other tasks here
       ContextManager.clear();
     }
   }
@@ -167,20 +166,4 @@ export default class SpanContext implements Context {
   currentSpan(): Span | undefined {
     return ContextManager.spans[ContextManager.spans.length - 1];
   }
-
-  capture(): Snapshot {
-    return {
-      segmentId: this.segment.segmentId,
-      spanId: this.currentSpan()?.id ?? -1,
-      traceId: this.segment.relatedTraces[0],
-      parentEndpoint: ContextManager.spans[0].operation,
-    };
-  }
-
-  restore(snapshot: Snapshot) {
-    const ref = SegmentRef.fromSnapshot(snapshot);
-    this.segment.refer(ref);
-    this.currentSpan()?.refer(ref);
-    this.segment.relate(ref.traceId);
-  }
 }
diff --git a/src/trace/span/Span.ts b/src/trace/span/Span.ts
index d854e9a..a7f73ba 100644
--- a/src/trace/span/Span.ts
+++ b/src/trace/span/Span.ts
@@ -80,9 +80,6 @@ export default abstract class Span {
 
   stop(): this {
     logger.debug(`Stopping span ${this.operation}`, this);
-    if (this.operation === '/test') {
-      console.info('kkkkkkkkkkkkkkkkkkkkkkkkkl')
-    }
     this.context.stop(this);
     return this;
   }
diff --git a/tests/plugins/http/server.ts b/tests/plugins/http/server.ts
index b9cbc2f..31891ba 100644
--- a/tests/plugins/http/server.ts
+++ b/tests/plugins/http/server.ts
@@ -36,3 +36,4 @@ const server = http.createServer((req, res) => {
 });
 
 server.listen(5000, () => console.info('Listening on port 5000...'));
+