@justair/justair-library 4.8.10 → 4.8.13
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/.github/workflows/publish.yml +28 -0
- package/package.json +1 -1
- package/src/config/logger.js +135 -37
- package/src/models/networkMetrics.js +2 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- 'JA-*'
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write # Required for OIDC
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- uses: actions/setup-node@v4
|
|
19
|
+
with:
|
|
20
|
+
node-version: '20'
|
|
21
|
+
registry-url: 'https://registry.npmjs.org'
|
|
22
|
+
|
|
23
|
+
# Ensure npm 11.5.1 or later is installed
|
|
24
|
+
- name: Update npm
|
|
25
|
+
run: npm install -g npm@latest
|
|
26
|
+
- run: npm ci
|
|
27
|
+
- run: npm run build --if-present
|
|
28
|
+
- run: npm publish
|
package/package.json
CHANGED
package/src/config/logger.js
CHANGED
|
@@ -2,44 +2,142 @@ import { createLogger, format, transports, config } from 'winston';
|
|
|
2
2
|
const { combine, timestamp, json, errors, prettyPrint } = format;
|
|
3
3
|
|
|
4
4
|
class CustomLogger {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
5
|
+
constructor({ DATADOG_API_KEY, APPLICATION_NAME }) {
|
|
6
|
+
this.DATADOG_API_KEY = DATADOG_API_KEY;
|
|
7
|
+
this.APPLICATION_NAME = APPLICATION_NAME;
|
|
8
|
+
this.logger = this._createLogger();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_createLogger() {
|
|
12
|
+
const httpTransportOptions = {
|
|
13
|
+
host: 'http-intake.logs.us5.datadoghq.com',
|
|
14
|
+
path: `/api/v2/logs?dd-api-key=${this.DATADOG_API_KEY}&ddsource=nodejs&service=${this.APPLICATION_NAME}`,
|
|
15
|
+
ssl: true
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return createLogger({
|
|
19
|
+
levels: config.syslog.levels,
|
|
20
|
+
exitOnError: false,
|
|
21
|
+
format: combine(
|
|
22
|
+
errors({ stack: true }),
|
|
23
|
+
timestamp({
|
|
24
|
+
format: 'YYYY-MM-DD HH:mm:ss'
|
|
25
|
+
}),
|
|
26
|
+
json(),
|
|
27
|
+
prettyPrint()
|
|
28
|
+
),
|
|
29
|
+
transports: [
|
|
30
|
+
new transports.Console(),
|
|
31
|
+
new transports.Http(httpTransportOptions),
|
|
32
|
+
],
|
|
33
|
+
exceptionHandlers: [
|
|
34
|
+
new transports.Console(),
|
|
35
|
+
new transports.Http(httpTransportOptions)
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getLogger() {
|
|
41
|
+
return this.logger;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_getServiceMetadata() {
|
|
45
|
+
return {
|
|
46
|
+
service: this.APPLICATION_NAME,
|
|
47
|
+
env: process.env.NODE_ENV || 'production',
|
|
48
|
+
version: process.env.K_REVISION || process.env.npm_package_version || 'unknown',
|
|
49
|
+
k_service: process.env.K_SERVICE,
|
|
50
|
+
k_revision: process.env.K_REVISION,
|
|
51
|
+
k_configuration: process.env.K_CONFIGURATION,
|
|
52
|
+
pod: process.env.HOSTNAME || process.env.POD_NAME,
|
|
53
|
+
namespace: process.env.NAMESPACE,
|
|
54
|
+
node: process.env.NODE_NAME,
|
|
55
|
+
pid: process.pid,
|
|
56
|
+
nodeVersion: process.version,
|
|
57
|
+
platform: process.platform,
|
|
58
|
+
timestamp: new Date().toISOString()
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
logServiceStartup(metadata = {}) {
|
|
63
|
+
this.logger.info('Service startup', {
|
|
64
|
+
event: 'service.startup',
|
|
65
|
+
...this._getServiceMetadata(),
|
|
66
|
+
...metadata
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
logGracefulShutdown(signal, metadata = {}) {
|
|
71
|
+
this.logger.info('Graceful shutdown initiated', {
|
|
72
|
+
event: 'service.shutdown.graceful',
|
|
73
|
+
signal,
|
|
74
|
+
...this._getServiceMetadata(),
|
|
75
|
+
...metadata
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
logCrash(error, source, metadata = {}) {
|
|
80
|
+
this.logger.error('Service crash detected', {
|
|
81
|
+
event: 'service.crash',
|
|
82
|
+
source,
|
|
83
|
+
error: {
|
|
84
|
+
message: error.message,
|
|
85
|
+
stack: error.stack,
|
|
86
|
+
name: error.name
|
|
87
|
+
},
|
|
88
|
+
...this._getServiceMetadata(),
|
|
89
|
+
...metadata
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
logExit(code, metadata = {}) {
|
|
94
|
+
this.logger.info('Service exit', {
|
|
95
|
+
event: 'service.exit',
|
|
96
|
+
exitCode: code,
|
|
97
|
+
...this._getServiceMetadata(),
|
|
98
|
+
...metadata
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
setupLifecycleHooks() {
|
|
103
|
+
// Startup
|
|
104
|
+
this.logServiceStartup();
|
|
105
|
+
|
|
106
|
+
// Graceful shutdown signals
|
|
107
|
+
const shutdownHandler = (signal) => {
|
|
108
|
+
this.logGracefulShutdown(signal);
|
|
109
|
+
// Allow logs to flush before exiting
|
|
110
|
+
setTimeout(() => process.exit(0), 1000);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
process.on('SIGTERM', () => shutdownHandler('SIGTERM'));
|
|
114
|
+
process.on('SIGINT', () => shutdownHandler('SIGINT'));
|
|
115
|
+
|
|
116
|
+
// Crash handlers
|
|
117
|
+
process.on('uncaughtException', (error) => {
|
|
118
|
+
this.logCrash(error, 'uncaughtException');
|
|
119
|
+
// Allow logs to flush before exiting
|
|
120
|
+
setTimeout(() => process.exit(1), 1000);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
124
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
125
|
+
this.logCrash(error, 'unhandledRejection', { promise: String(promise) });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Exit events
|
|
129
|
+
process.on('beforeExit', (code) => {
|
|
130
|
+
this.logger.info('Before exit', {
|
|
131
|
+
event: 'service.beforeExit',
|
|
132
|
+
exitCode: code,
|
|
133
|
+
...this._getServiceMetadata()
|
|
37
134
|
});
|
|
38
|
-
}
|
|
135
|
+
});
|
|
39
136
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
137
|
+
process.on('exit', (code) => {
|
|
138
|
+
this.logExit(code);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
43
141
|
}
|
|
44
142
|
|
|
45
|
-
export default CustomLogger;
|
|
143
|
+
export default CustomLogger;
|
|
@@ -5,9 +5,9 @@ const networkMetricsSchema = mongoose.Schema({
|
|
|
5
5
|
orgId: { type: mongoose.Types.ObjectId, ref: "Organizations" },
|
|
6
6
|
parameter: String,
|
|
7
7
|
parameterValue: Number,
|
|
8
|
-
|
|
8
|
+
networkMedian: Number,
|
|
9
9
|
networkMonitorCount: Number,
|
|
10
|
-
|
|
10
|
+
percentDeviationFromMedian: Number,
|
|
11
11
|
measurementsStartTime: Date,
|
|
12
12
|
measurementsEndTime: Date,
|
|
13
13
|
flags: Object
|