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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"typescript": "^5.5.4",
"neostandard": "^0.12.1",
"@platformatic/client-cli": "^2.58.0",
"@platformatic/ui-components": "^0.13.1",
"@platformatic/ui-components": "^0.13.5",
"@types/d3": "^7.4.3",
"@types/react-dom": "^19.0.4",
"@vitejs/plugin-react": "^4.3.3",
Expand Down
4 changes: 2 additions & 2 deletions web/backend/test/fixtures/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1630,12 +1630,12 @@ export const metricFixtures: Metric[] = [
}
},
{
value: 0,
value: 2,
metricName: 'http_request_duration_seconds_count',
labels: {
method: 'GET',
route: '/__empty_metrics',
status_code: 404,
status_code: 200,
serviceId: 'composer'
}
},
Expand Down
4 changes: 2 additions & 2 deletions web/backend/test/utils/calc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ test('calculateMetrics collects and aggregates metrics correctly', async () => {
assert.strictEqual(aggregatedMem.oldSpace, 285.08)

const aggregatedReq = mockedMetrics.aggregated.dataReq[0]
assert.strictEqual(aggregatedReq.count, 5)
assert.strictEqual(aggregatedReq.rps, 5)
assert.strictEqual(aggregatedReq.count, 7)
assert.strictEqual(aggregatedReq.rps, 7)

assert.ok(metricService1.dataMem.length <= 20)
assert.ok(metricService1.dataCpu.length <= 20)
Expand Down
7 changes: 5 additions & 2 deletions web/backend/utils/calc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ export const calculateMetrics = async ({ mappedMetrics, log }: FastifyInstance):
}

if (metric.name === 'http_request_duration_seconds') {
const alreadyIteratedRoutes: Record<string, boolean> = {}
const count = metric.values.reduce((acc, { metricName, value, labels }) => {
const lastRouteChar = labels.route?.slice(-1)
if (metricName === 'http_request_duration_seconds_count' && lastRouteChar !== '/') {
const routeLabel = labels.route || ''
const cleanRouteLabel = routeLabel?.endsWith('/') ? routeLabel.slice(0, -1) : routeLabel
if (metricName === 'http_request_duration_seconds_count' && !alreadyIteratedRoutes[cleanRouteLabel]) {
/*
TODO: The check above is to avoid duplicated data returned from `@platformatic/control`. For instance, we may received values like:

Expand Down Expand Up @@ -215,6 +217,7 @@ export const calculateMetrics = async ({ mappedMetrics, log }: FastifyInstance):
Evaluate if this approach is correct (on `@platformatic/control`) and update this code accordingly in case of an update from the lib itself.
*/
acc += value
alreadyIteratedRoutes[cleanRouteLabel] = true
}
return acc
}, 0)
Expand Down
2 changes: 1 addition & 1 deletion web/frontend/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module '*.module.css' {
export default classes
}

// FIXME: add following types directly on the `@platformatic/ui-components` package
// FIXME: wait for newer version of `@platformatic/ui-components` package to remove following types definition
declare module '@platformatic/ui-components' {
import { ComponentType } from 'react'

Expand Down
Loading