@platformatic/control 1.26.0 → 1.28.0

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/help/logs.txt CHANGED
@@ -10,7 +10,7 @@ Options:
10
10
  * `-n, --name <string>` - The name of the runtime.
11
11
  * `-l, --level <string>` - The pino log level to stream. Default is `info`.
12
12
  * `-s, --service <string>` - The name of the service to stream logs from.
13
- * `--pretty` <boolean> - Pretty print the logs. Default is `true`.
13
+ * `--pretty <boolean>` - Pretty print the logs. Default is `true`.
14
14
 
15
15
  If `--service` is not specified, the command will stream logs from all services.
16
16
 
package/lib/errors.js CHANGED
@@ -17,5 +17,7 @@ module.exports = {
17
17
  FailedToStopRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_STOP_RUNTIME`, 'Failed to stop the runtime %s.'),
18
18
  FailedToReloadRuntime: createError(`${ERROR_PREFIX}_FAILED_TO_RELOAD_RUNTIME`, 'Failed to reload the runtime %s.'),
19
19
  FailedToGetRuntimeConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_CONFIG`, 'Failed to get runtime config %s.'),
20
- FailedToGetRuntimeServiceConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`, 'Failed to get runtime service config %s.')
20
+ FailedToGetRuntimeServiceConfig: createError(`${ERROR_PREFIX}_FAILED_TO_GET_RUNTIME_SERVICE_CONFIG`, 'Failed to get runtime service config %s.'),
21
+ FailedToGetRuntimeHistoryLogs: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS`, 'Failed to get history logs %s.'),
22
+ FailedToGetRuntimeLogIndexes: createError(`${ERROR_PREFIX}_FAILED_TO_GET_HISTORY_LOGS_COUNT`, 'Failed to get history logs count %s.')
21
23
  }
package/lib/ps.js CHANGED
@@ -55,7 +55,7 @@ function formatRuntimeTime (timeSeconds) {
55
55
  const tableConfig = {
56
56
  border: getBorderCharacters('void'),
57
57
  columnDefault: {
58
- paddingLeft: 1,
58
+ paddingLeft: 0,
59
59
  paddingRight: 1
60
60
  },
61
61
  drawHorizontalLine: () => false
@@ -181,28 +181,62 @@ class RuntimeApiClient {
181
181
  }
182
182
  }
183
183
 
184
- getRuntimeLiveLogsStream (pid) {
184
+ getRuntimeLiveMetricsStream (pid) {
185
185
  const socketPath = this.#getSocketPathFromPid(pid)
186
186
 
187
187
  const protocol = platform() === 'win32' ? 'ws+unix:' : 'ws+unix://'
188
- const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live'
188
+ const webSocketUrl = protocol + socketPath + ':/api/v1/metrics/live'
189
189
  const webSocketStream = new WebSocketStream(webSocketUrl)
190
190
  this.#webSockets.add(webSocketStream.ws)
191
191
 
192
192
  return webSocketStream
193
193
  }
194
194
 
195
- getRuntimeHistoryLogsStream (pid) {
195
+ getRuntimeLiveLogsStream (pid, startLogIndex) {
196
196
  const socketPath = this.#getSocketPathFromPid(pid)
197
197
 
198
198
  const protocol = platform() === 'win32' ? 'ws+unix:' : 'ws+unix://'
199
- const webSocketUrl = protocol + socketPath + ':/api/v1/logs/history'
199
+ const query = startLogIndex ? `?start=${startLogIndex}` : ''
200
+ const webSocketUrl = protocol + socketPath + ':/api/v1/logs/live' + query
200
201
  const webSocketStream = new WebSocketStream(webSocketUrl)
201
202
  this.#webSockets.add(webSocketStream.ws)
202
203
 
203
204
  return webSocketStream
204
205
  }
205
206
 
207
+ async getRuntimeLogsStream (pid, logsId) {
208
+ const client = this.#getUndiciClient(pid)
209
+
210
+ const { statusCode, body } = await client.request({
211
+ path: '/api/v1/logs/' + logsId,
212
+ method: 'GET'
213
+ })
214
+
215
+ if (statusCode !== 200) {
216
+ const error = await body.text()
217
+ throw new errors.FailedToGetRuntimeHistoryLogs(error)
218
+ }
219
+
220
+ return body
221
+ }
222
+
223
+ async getRuntimeLogIndexes (pid) {
224
+ const client = this.#getUndiciClient(pid)
225
+
226
+ const { statusCode, body } = await client.request({
227
+ path: '/api/v1/logs/indexes',
228
+ method: 'GET'
229
+ })
230
+
231
+ if (statusCode !== 200) {
232
+ const error = await body.text()
233
+ throw new errors.FailedToGetRuntimeLogIndexes(error)
234
+ }
235
+
236
+ const { indexes } = await body.json()
237
+ return indexes
238
+ }
239
+
206
240
  async injectRuntime (pid, serviceId, options) {
207
241
  const client = this.#getUndiciClient(pid)
208
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/control",
3
- "version": "1.26.0",
3
+ "version": "1.28.0",
4
4
  "description": "Platformatic Control",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -17,23 +17,23 @@
17
17
  },
18
18
  "homepage": "https://github.com/platformatic/platformatic#readme",
19
19
  "devDependencies": {
20
- "borp": "^0.9.0",
21
- "desm": "^1.3.0",
20
+ "borp": "^0.10.0",
21
+ "desm": "^1.3.1",
22
22
  "execa": "^8.0.1",
23
23
  "snazzy": "^9.0.0",
24
24
  "split2": "^4.2.0",
25
25
  "standard": "^17.1.0",
26
- "tsd": "^0.30.4",
27
- "@platformatic/runtime": "1.26.0"
26
+ "tsd": "^0.30.7",
27
+ "@platformatic/runtime": "1.28.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "@fastify/error": "^3.4.1",
31
31
  "commist": "^3.2.0",
32
32
  "help-me": "^5.0.0",
33
- "pino": "^8.17.2",
33
+ "pino": "^8.19.0",
34
34
  "pino-pretty": "^10.3.1",
35
35
  "table": "^6.8.1",
36
- "undici": "^6.6.0",
36
+ "undici": "^6.9.0",
37
37
  "ws": "^8.16.0"
38
38
  },
39
39
  "scripts": {