Skip to content
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
3 changes: 2 additions & 1 deletion dist/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Apache 2.0 licenses
The following components are provided under the Apache License. See project link for details.
The text of each license is the standard Apache 2.0 license.

grpc-node 1.10.1: https://github.com/grpc/grpc-node, Apache 2.0
grpc-node 1.4.4: https://github.com/grpc/grpc-node, Apache 2.0

========================================================================
BSD licenses
Expand Down Expand Up @@ -244,6 +244,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.

uuid 8.1.0: https://github.com/uuidjs/uuid, MIT
winston 3.2.1: https://github.com/winstonjs/winston, MIT
grpc_tools_node_protoc_ts 5.3.0: https://github.com/agreatfool/grpc_tools_node_protoc_ts, MIT

========================================================================
ISC licenses
Expand Down
21 changes: 21 additions & 0 deletions dist/licenses/LICENSE-grpc_tools_node_protoc_ts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Jonathan Dai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4,838 changes: 1,667 additions & 3,171 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"amqplib": "^0.7.0",
"axios": "^0.21.0",
"express": "^4.17.1",
"grpc-tools": "^1.10.0",
"grpc_tools_node_protoc_ts": "^4.0.0",
"grpc-tools": "^1.11.1",
"grpc_tools_node_protoc_ts": "^5.3.0",
"ioredis": "^4.27.2",
"jest": "^26.6.3",
"mongodb": "^3.6.4",
Expand All @@ -68,8 +68,8 @@
"wait-for-expect": "^3.0.2"
},
"dependencies": {
"@grpc/grpc-js": "^1.4.4",
"google-protobuf": "^3.14.0",
"grpc": "^1.10.1",
"semver": "^7.3.2",
"tslib": "^2.0.3",
"uuid": "^8.1.0",
Expand Down
6 changes: 2 additions & 4 deletions scripts/protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ mkdir -p $OUT_DIR || true
cd "${ROOT_DIR}"/protocol || exit

PROTOC_GEN_TS_PATH="${ROOT_DIR}/node_modules/.bin/protoc-gen-ts"
PROTOC_PLUGIN="${ROOT_DIR}/node_modules/.bin/grpc_tools_node_protoc_plugin"
PROTOC="${ROOT_DIR}/node_modules/.bin/grpc_tools_node_protoc"

${PROTOC} \
--js_out=import_style=commonjs,binary:$OUT_DIR \
--grpc_out=$OUT_DIR \
--plugin=protoc-gen-grpc="${PROTOC_PLUGIN}" \
--grpc_out=grpc_js:$OUT_DIR \
**/*.proto

${PROTOC} \
--plugin=protoc-gen-ts="${PROTOC_GEN_TS_PATH}" \
--ts_out=$OUT_DIR \
--ts_out=grpc_js:$OUT_DIR \
**/*.proto

23 changes: 7 additions & 16 deletions src/agent/protocol/grpc/AuthInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@
*
*/

import * as grpc from 'grpc';
import { InterceptingCall, Listener, Metadata, Requester } from 'grpc';
import * as grpc from '@grpc/grpc-js';
import config from '../../../config/AgentConfig';

type Options = { [key: string]: string | number };

export default function AuthInterceptor(options: Options, nextCall: (options: Options) => InterceptingCall) {
return new grpc.InterceptingCall(
nextCall(options),
new (class implements Requester {
// tslint:disable-next-line:ban-types
start(metadata: Metadata, listener: Listener, next: Function) {
if (config.authorization) {
metadata.add('Authentication', config.authorization);
}
next(metadata, listener);
}
})(),
);
export default function AuthInterceptor() {
const mata = new grpc.Metadata()
if (config.authorization) {
mata.add('Authentication', config.authorization);
}
return mata;
}
11 changes: 5 additions & 6 deletions src/agent/protocol/grpc/clients/HeartbeatClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*
*/

import * as grpc from 'grpc';
import { connectivityState } from 'grpc';
import * as grpc from '@grpc/grpc-js';
import { connectivityState } from '@grpc/grpc-js';

import * as packageInfo from '../../../../../package.json';
import { createLogger } from '../../../../logging';
Expand All @@ -39,8 +39,7 @@ export default class HeartbeatClient implements Client {
constructor() {
this.managementServiceClient = new ManagementServiceClient(
config.collectorAddress,
config.secure ? grpc.credentials.createSsl() : grpc.credentials.createInsecure(),
{ interceptors: [AuthInterceptor] },
config.secure ? grpc.credentials.createSsl() : grpc.credentials.createInsecure()
);
}

Expand Down Expand Up @@ -75,7 +74,7 @@ export default class HeartbeatClient implements Client {
this.heartbeatTimer = setInterval(() => {
this.managementServiceClient.reportInstanceProperties(
instanceProperties,

AuthInterceptor(),
(error, _) => {
if (error) {
logger.error('Failed to send heartbeat', error);
Expand All @@ -84,7 +83,7 @@ export default class HeartbeatClient implements Client {
);
this.managementServiceClient.keepAlive(
keepAlivePkg,

AuthInterceptor(),
(error, _) => {
if (error) {
logger.error('Failed to send heartbeat', error);
Expand Down
11 changes: 5 additions & 6 deletions src/agent/protocol/grpc/clients/TraceReportClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import config from '../../../../config/AgentConfig';
import * as grpc from 'grpc';
import { connectivityState } from 'grpc';
import * as grpc from '@grpc/grpc-js';
import { connectivityState } from '@grpc/grpc-js';
import { createLogger } from '../../../../logging';
import Client from './Client';
import { TraceSegmentReportServiceClient } from '../../../../proto/language-agent/Tracing_grpc_pb';
Expand All @@ -38,8 +38,7 @@ export default class TraceReportClient implements Client {
constructor() {
this.reporterClient = new TraceSegmentReportServiceClient(
config.collectorAddress,
config.secure ? grpc.credentials.createSsl() : grpc.credentials.createInsecure(),
{ interceptors: [AuthInterceptor] },
config.secure ? grpc.credentials.createSsl() : grpc.credentials.createInsecure()
);
emitter.on('segment-finished', (segment) => {
this.buffer.push(segment);
Expand All @@ -53,14 +52,14 @@ export default class TraceReportClient implements Client {

start() {
const reportFunction = () => {
emitter.emit('segments-sent'); // reset limiter in SpanContext
emitter.emit('segments-sent'); // reset limiter in SpanContext

try {
if (this.buffer.length === 0) {
return;
}

const stream = this.reporterClient.collect((error, _) => {
const stream = this.reporterClient.collect(AuthInterceptor(), (error, _) => {
if (error) {
logger.error('Failed to report trace data', error);
}
Expand Down