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
267 changes: 160 additions & 107 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 @@ -7,9 +7,9 @@
"start": "wattpm start"
},
"dependencies": {
"@platformatic/composer": "^2.30.1",
"@platformatic/runtime": "^2.30.1",
"wattpm": "^2.30.1"
"@platformatic/composer": "^2.30.2",
"@platformatic/runtime": "^2.30.2",
"wattpm": "^2.30.2"
},
"workspaces": [
"web/*",
Expand Down
2 changes: 1 addition & 1 deletion watt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://schemas.platformatic.dev/wattpm/2.30.1.json",
"$schema": "https://schemas.platformatic.dev/wattpm/2.30.2.json",
"server": {
"hostname": "127.0.0.1",
"port": 3042
Expand Down
11 changes: 10 additions & 1 deletion web/backend/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { FastifyInstance } from 'fastify'
import { PlatformaticApp, PlatformaticServiceConfig } from '@platformatic/service'
import { MetricValue } from '@platformatic/control'

declare module 'fastify' {
interface FastifyInstance {
platformatic: PlatformaticApp<PlatformaticServiceConfig>
metricsInterval: NodeJS.Timeout
mappedMetrics: any // FIXME: use proper type once we add it to `@platformatic/control`
mappedMetrics: Record<number, {
name: string,
time: Date,
type: string,
aggregator: string,
values: MetricValue[],
serviceId: string,
pid: number
}[]>
}
}
7 changes: 4 additions & 3 deletions web/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
},
"devDependencies": {
"@fastify/type-provider-json-schema-to-ts": "^5.0.0",
"fastify-tsconfig": "^2.0.0",
"borp": "^0.19.0",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"neostandard": "^0.12.0",
"typescript": "^5.5.4",
"wattpm": "^2.30.1"
"wattpm": "^2.30.2"
},
"dependencies": {
"@platformatic/control": "^2.30.1",
"@platformatic/service": "^2.30.1"
"@platformatic/control": "^2.30.2",
"@platformatic/service": "^2.30.2"
}
}
2 changes: 1 addition & 1 deletion web/backend/platformatic.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.30.1.json",
"$schema": "https://schemas.platformatic.dev/@platformatic/service/2.30.2.json",
"service": {
"openapi": true
},
Expand Down
5 changes: 2 additions & 3 deletions web/backend/plugins/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export default async function (fastify: FastifyInstance, opts: FastifyPluginOpti
const runtimes = await api.getRuntimes()
for (const { pid } of runtimes) {
try {
// TODO: add more strict types into `@platformatic/control` to avoid casting to `any`
const runtimeMetrics: any = await api.getRuntimeMetrics(pid, { format: 'json' })
const runtimeMetrics = await api.getRuntimeMetrics(pid, { format: 'json' })

for (const { name, type, aggregator, values } of runtimeMetrics) {
if (!fastify.mappedMetrics[pid]) {
Expand All @@ -33,7 +32,7 @@ export default async function (fastify: FastifyInstance, opts: FastifyPluginOpti
fastify.decorate('metricsInterval', metricsInterval)

fastify.addHook('onClose', async () => {
// FIXME: this is an issue on wattpm, since graceful shutdown time of 10s isn't considered (https://github.com/platformatic/platformatic/issues/3751)
// FIXME: there is currently an issue on wattpm => `onClose` hook is not called (https://github.com/platformatic/platformatic/issues/3751)
fastify.log.info('Closing the backend...')
clearInterval(fastify.metricsInterval)
})
Expand Down
3 changes: 1 addition & 2 deletions web/backend/routes/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default async function (fastify: FastifyInstance, opts: FastifyPluginOpti
params: { type: 'object', properties: { pid: { type: 'number' }, serviceId: { type: 'string' } }, required: ['pid', 'serviceId'] }
}
}, async ({ params: { pid, serviceId } }, reply) => {
// TODO: add more strict types into `@platformatic/control` to avoid casting to `any`
return typedFastify.mappedMetrics[pid]?.filter((value: any) => value.serviceId === serviceId)
return typedFastify.mappedMetrics[pid]?.filter((value) => value.serviceId === serviceId)
})

typedFastify.get('/runtimes/:pid/services', {
Expand Down
7 changes: 4 additions & 3 deletions web/backend/test/plugins/metrics.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'node:test'
import assert from 'node:assert'
import { getServer, startWatt } from '../helper'
import { Metric } from '@platformatic/control'

const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

Expand All @@ -18,8 +19,9 @@ test('metrics with runtime', async (t) => {
await wait(1200)
const metricsKeys = Object.keys(server.mappedMetrics)
const [pid] = metricsKeys
const servicePID = parseInt(pid)
assert.ok(metricsKeys.length > 0, 'mapped metrics are defined, and contain values')
assert.strictEqual(server.mappedMetrics[pid][0].pid, parseInt(pid))
assert.strictEqual(server.mappedMetrics[servicePID][0].pid, servicePID)

const res = await server.inject({
method: 'GET',
Expand Down Expand Up @@ -65,8 +67,7 @@ test('metrics with runtime', async (t) => {
'http_cache_miss_count'
]
expectedNames.forEach(expectedName => {
// TODO: remove cast to any
const exists = metrics.some((metric: any) => metric.name === expectedName)
const exists = metrics.some((metric: Metric) => metric.name === expectedName)
assert.ok(exists, `Expected metric: ${expectedName}`)
})
})
8 changes: 2 additions & 6 deletions web/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"extends": "fastify-tsconfig",
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es2020",
"sourceMap": true,
"pretty": true,
"noEmitOnError": true,
"incremental": true,
"strict": true,
"outDir": "dist",
"skipLibCheck": true
"outDir": "dist"
},
"watchOptions": {
"watchFile": "fixedPollingInterval",
Expand Down
2 changes: 1 addition & 1 deletion web/composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"typescript": "^5.5.4"
},
"dependencies": {
"@platformatic/composer": "^2.30.1"
"@platformatic/composer": "^2.30.2"
}
}
2 changes: 1 addition & 1 deletion web/composer/platformatic.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://schemas.platformatic.dev/@platformatic/composer/2.30.1.json",
"$schema": "https://schemas.platformatic.dev/@platformatic/composer/2.30.2.json",
"composer": {
"services": [
{
Expand Down
2 changes: 1 addition & 1 deletion web/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"@platformatic/vite": "^2.30.1"
"@platformatic/vite": "^2.30.2"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
Expand Down
2 changes: 1 addition & 1 deletion web/frontend/watt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://schemas.platformatic.dev/@platformatic/vite/2.30.1.json",
"$schema": "https://schemas.platformatic.dev/@platformatic/vite/2.30.2.json",
"application": {
"basePath": "/admin"
}
Expand Down