@yolo-croket-dev/core 1.9.7-slowquery.16 → 1.9.7-slowquery.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decorators/index.d.ts +0 -1
- package/decorators/index.js +0 -1
- package/interceptors/logging-service.interceptor.js +26 -19
- package/package.json +1 -1
- package/util.d.ts +0 -2
- package/util.js +1 -7
- package/decorators/grpc-param.decorator.d.ts +0 -1
- package/decorators/grpc-param.decorator.js +0 -12
- package/filters/grpc-exception.filter.d.ts +0 -11
- package/filters/grpc-exception.filter.js +0 -136
- package/filters/index.d.ts +0 -1
- package/filters/index.js +0 -17
package/decorators/index.d.ts
CHANGED
package/decorators/index.js
CHANGED
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./rpc-interceptor-scope.decorator"), exports);
|
|
18
18
|
__exportStar(require("./rpc-transform.decorator"), exports);
|
|
19
|
-
__exportStar(require("./grpc-param.decorator"), exports);
|
|
@@ -41,6 +41,12 @@ const operators_1 = require("rxjs/operators");
|
|
|
41
41
|
const dd_trace_1 = __importDefault(require("dd-trace"));
|
|
42
42
|
const { SERVER_NAME } = process.env;
|
|
43
43
|
const msaLogger = new msa_logger_1.default(msa_logger_1.ServerTypeEnum.SERVICE);
|
|
44
|
+
// interface IContent {
|
|
45
|
+
// pattern: string;
|
|
46
|
+
// data: IRequest;
|
|
47
|
+
// /** 무슨 아이디인지 모르겠음 */
|
|
48
|
+
// id: string;
|
|
49
|
+
// }
|
|
44
50
|
const MAX_CUT_LENGTH = 500;
|
|
45
51
|
dd_trace_1.default.init();
|
|
46
52
|
let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
@@ -81,45 +87,46 @@ let LoggingServiceInterceptor = class LoggingServiceInterceptor {
|
|
|
81
87
|
const rmqContext = rpcContext.getContext();
|
|
82
88
|
const data = rpcContext.getData();
|
|
83
89
|
const metadata = args[1];
|
|
84
|
-
const isGrpc =
|
|
90
|
+
const isGrpc = rpcContext.contextType === 'rpc';
|
|
85
91
|
let param;
|
|
92
|
+
let pastFrom;
|
|
93
|
+
let pastFroms;
|
|
86
94
|
let originalMessage;
|
|
87
95
|
let pattern; /** @xxx: Grpc: path , Mq: 메시지 패턴명 */
|
|
88
96
|
let payload;
|
|
89
97
|
if (isGrpc) {
|
|
90
|
-
param =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
froms: '-',
|
|
94
|
-
},
|
|
95
|
-
});
|
|
98
|
+
param = metadata.get('param') || { param: { from: '-', froms: '-' } };
|
|
99
|
+
pastFrom = metadata.get('from') || '-';
|
|
100
|
+
pastFroms = metadata.get('froms') || [pastFrom];
|
|
96
101
|
originalMessage = args[0];
|
|
97
|
-
|
|
102
|
+
let gRPCArg = args[2];
|
|
98
103
|
pattern = gRPCArg.path;
|
|
99
104
|
payload = data;
|
|
100
105
|
}
|
|
101
106
|
else {
|
|
102
107
|
param = data.param;
|
|
108
|
+
pastFrom = param.from ? JSON.parse(JSON.stringify(param.from)) : '-';
|
|
109
|
+
pastFroms = param.froms ? JSON.parse(JSON.stringify(param.froms)) : [pastFrom];
|
|
103
110
|
originalMessage = rmqContext.getMessage();
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
payload = context.switchToHttp().getRequest().
|
|
111
|
+
pattern = originalMessage.messagePattern;
|
|
112
|
+
// const originalcontent = originalMessage.content;
|
|
113
|
+
// const content = JSON.parse(originalcontent.toString()) as IContent;
|
|
114
|
+
payload = context.switchToHttp().getRequest().data;
|
|
108
115
|
}
|
|
116
|
+
// const pastFrom = data.param.from ? JSON.parse(JSON.stringify(data.param.from)) : '-';
|
|
117
|
+
// const pastFroms = data.param.froms ? JSON.parse(JSON.stringify(data.param.froms)) : [pastFrom];
|
|
118
|
+
// const originalMessage = rmqContext.getMessage();
|
|
119
|
+
// const ctx = context.switchToHttp();
|
|
120
|
+
// const request = ctx.getRequest() as IRequest;
|
|
109
121
|
const pastParam = JSON.parse(JSON.stringify(param));
|
|
110
|
-
const pastFrom = pastParam.from || '-';
|
|
111
|
-
const pastFroms = pastParam.froms || [pastFrom];
|
|
112
122
|
const traceId = param ? param.traceId : '-';
|
|
113
123
|
/** from 변경 */
|
|
114
124
|
const tmpFrom = `${SERVER_NAME}: ${pattern}`;
|
|
115
125
|
const tmpFroms = JSON.parse(JSON.stringify(pastFroms));
|
|
116
126
|
tmpFroms.push(tmpFrom);
|
|
117
127
|
if (isGrpc) {
|
|
118
|
-
metadata.set('
|
|
119
|
-
|
|
120
|
-
from: tmpFrom,
|
|
121
|
-
froms: tmpFroms,
|
|
122
|
-
}));
|
|
128
|
+
metadata.set('from', JSON.stringify(tmpFrom));
|
|
129
|
+
metadata.set('froms', JSON.stringify(tmpFroms));
|
|
123
130
|
}
|
|
124
131
|
else {
|
|
125
132
|
data.param.from = tmpFrom;
|
package/package.json
CHANGED
package/util.d.ts
CHANGED
package/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateRandom = void 0;
|
|
4
4
|
const randomstring_1 = require("randomstring");
|
|
5
5
|
function generateRandom(length, charset) {
|
|
6
6
|
return (0, randomstring_1.generate)({
|
|
@@ -9,9 +9,3 @@ function generateRandom(length, charset) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
exports.generateRandom = generateRandom;
|
|
12
|
-
/** host에서 port를 추출합니다. */
|
|
13
|
-
function getPortFromHost(host) {
|
|
14
|
-
const port = host.split(':')[1];
|
|
15
|
-
return port ? parseInt(port, 10) : undefined;
|
|
16
|
-
}
|
|
17
|
-
exports.getPortFromHost = getPortFromHost;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const GrpcParam: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GrpcParam = void 0;
|
|
4
|
-
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.GrpcParam = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
-
const metadata = ctx.switchToRpc().getContext();
|
|
7
|
-
const param = metadata.get('param');
|
|
8
|
-
if (!param || !param[0]) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
return JSON.parse(param[0]);
|
|
12
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
|
|
2
|
-
import { BaseRpcExceptionFilter } from '@nestjs/microservices';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
export declare class GrpcExceptionFilter extends BaseRpcExceptionFilter implements ExceptionFilter {
|
|
5
|
-
private readonly CROKET_EXCEPTION_NAMES;
|
|
6
|
-
catch(exception: unknown, host: ArgumentsHost): Observable<unknown>;
|
|
7
|
-
/**
|
|
8
|
-
* HTTP Status 코드를 gRPC Status 코드로 변환
|
|
9
|
-
*/
|
|
10
|
-
private convertHttpStatusToGrpcStatus;
|
|
11
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
-
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
-
if (mod && mod.__esModule) return mod;
|
|
26
|
-
var result = {};
|
|
27
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
-
__setModuleDefault(result, mod);
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.GrpcExceptionFilter = void 0;
|
|
33
|
-
const common_1 = require("@nestjs/common");
|
|
34
|
-
const microservices_1 = require("@nestjs/microservices");
|
|
35
|
-
const grpc_js_1 = require("@grpc/grpc-js");
|
|
36
|
-
const CroketExceptions = __importStar(require("@yolo-croket-dev/core/exceptions"));
|
|
37
|
-
/**
|
|
38
|
-
* CroketExceptions에서 export된 모든 클래스의 constructor 배열 생성
|
|
39
|
-
*/
|
|
40
|
-
const getCroketExceptionClasses = () => Object.values(CroketExceptions).filter((value) => typeof value === 'function' && value.prototype && value.prototype.constructor === value);
|
|
41
|
-
const croketExceptionClasses = getCroketExceptionClasses();
|
|
42
|
-
let GrpcExceptionFilter = class GrpcExceptionFilter extends microservices_1.BaseRpcExceptionFilter {
|
|
43
|
-
constructor() {
|
|
44
|
-
super(...arguments);
|
|
45
|
-
this.CROKET_EXCEPTION_NAMES = croketExceptionClasses.map(d => d.prototype.constructor.name);
|
|
46
|
-
}
|
|
47
|
-
catch(exception, host) {
|
|
48
|
-
var _a;
|
|
49
|
-
const metadata = new grpc_js_1.Metadata();
|
|
50
|
-
let grpcStatus;
|
|
51
|
-
let errorMessage;
|
|
52
|
-
const className = ((_a = exception === null || exception === void 0 ? void 0 : exception.constructor) === null || _a === void 0 ? void 0 : _a.name) || 'Error';
|
|
53
|
-
if (this.CROKET_EXCEPTION_NAMES.includes(className)) {
|
|
54
|
-
const msaException = exception;
|
|
55
|
-
const httpStatus = exception.getStatus();
|
|
56
|
-
const errInfo = {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
errType: exception.errType,
|
|
59
|
-
type: className || exception.constructor.name,
|
|
60
|
-
message: msaException.errMessage || exception.message,
|
|
61
|
-
status: httpStatus,
|
|
62
|
-
action: msaException.errAction,
|
|
63
|
-
};
|
|
64
|
-
metadata.set('error', Buffer.from(JSON.stringify(errInfo)).toString('base64'));
|
|
65
|
-
metadata.set('status', httpStatus.toString());
|
|
66
|
-
grpcStatus = this.convertHttpStatusToGrpcStatus(httpStatus);
|
|
67
|
-
errorMessage = msaException.errMessage || exception.message;
|
|
68
|
-
}
|
|
69
|
-
else if (exception instanceof microservices_1.RpcException) {
|
|
70
|
-
const rpcError = exception.getError();
|
|
71
|
-
grpcStatus = rpcError.code || grpc_js_1.status.INTERNAL;
|
|
72
|
-
errorMessage = rpcError.message || 'Internal Server Error';
|
|
73
|
-
if (rpcError.metadata) {
|
|
74
|
-
const errorMetadata = rpcError.metadata;
|
|
75
|
-
const keys = errorMetadata.getMap();
|
|
76
|
-
Object.keys(keys).forEach((key) => {
|
|
77
|
-
const value = errorMetadata.get(key);
|
|
78
|
-
if (Array.isArray(value)) {
|
|
79
|
-
value.forEach((v) => metadata.add(key, v));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
metadata.set(key, value);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
errorMessage = (exception === null || exception === void 0 ? void 0 : exception.message) || 'Internal Server Error';
|
|
89
|
-
grpcStatus = grpc_js_1.status.INTERNAL;
|
|
90
|
-
}
|
|
91
|
-
// BaseRpcExceptionFilter의 catch 메서드를 사용하여 metadata를 포함한 RpcException 생성
|
|
92
|
-
const rpcException = new microservices_1.RpcException({
|
|
93
|
-
code: grpcStatus,
|
|
94
|
-
message: errorMessage,
|
|
95
|
-
metadata,
|
|
96
|
-
});
|
|
97
|
-
return super.catch(rpcException, host);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* HTTP Status 코드를 gRPC Status 코드로 변환
|
|
101
|
-
*/
|
|
102
|
-
convertHttpStatusToGrpcStatus(httpStatus) {
|
|
103
|
-
switch (httpStatus) {
|
|
104
|
-
case 200:
|
|
105
|
-
return grpc_js_1.status.OK;
|
|
106
|
-
case 400:
|
|
107
|
-
return grpc_js_1.status.INVALID_ARGUMENT;
|
|
108
|
-
case 401:
|
|
109
|
-
return grpc_js_1.status.UNAUTHENTICATED;
|
|
110
|
-
case 403:
|
|
111
|
-
return grpc_js_1.status.PERMISSION_DENIED;
|
|
112
|
-
case 404:
|
|
113
|
-
return grpc_js_1.status.NOT_FOUND;
|
|
114
|
-
case 409:
|
|
115
|
-
return grpc_js_1.status.ALREADY_EXISTS;
|
|
116
|
-
case 412:
|
|
117
|
-
return grpc_js_1.status.FAILED_PRECONDITION;
|
|
118
|
-
case 429:
|
|
119
|
-
return grpc_js_1.status.RESOURCE_EXHAUSTED;
|
|
120
|
-
case 500:
|
|
121
|
-
return grpc_js_1.status.INTERNAL;
|
|
122
|
-
case 501:
|
|
123
|
-
return grpc_js_1.status.UNIMPLEMENTED;
|
|
124
|
-
case 503:
|
|
125
|
-
return grpc_js_1.status.UNAVAILABLE;
|
|
126
|
-
case 504:
|
|
127
|
-
return grpc_js_1.status.DEADLINE_EXCEEDED;
|
|
128
|
-
default:
|
|
129
|
-
return grpc_js_1.status.INTERNAL;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
exports.GrpcExceptionFilter = GrpcExceptionFilter;
|
|
134
|
-
exports.GrpcExceptionFilter = GrpcExceptionFilter = __decorate([
|
|
135
|
-
(0, common_1.Catch)()
|
|
136
|
-
], GrpcExceptionFilter);
|
package/filters/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './grpc-exception.filter';
|
package/filters/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./grpc-exception.filter"), exports);
|