From 1c818bd3b021c8e660d64f9054e02d06424a3c59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 21 May 2024 22:11:51 +0200 Subject: [PATCH] fix: fix performance statistics storage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package.json | 4 +- pnpm-lock.yaml | 97 +++++++++++++----------- src/performance/PerformanceStatistics.ts | 3 +- src/types/Statistics.ts | 2 +- src/utils/Constants.ts | 2 +- src/utils/MessageChannelUtils.ts | 21 ++++- 6 files changed, 75 insertions(+), 54 deletions(-) diff --git a/package.json b/package.json index 102fd444..01a471c2 100644 --- a/package.json +++ b/package.json @@ -144,9 +144,9 @@ "eslint-plugin-simple-import-sort": "^12.1.0", "eslint-plugin-tsdoc": "^0.2.17", "expect": "^29.7.0", - "glob": "^10.3.15", + "glob": "^10.3.16", "husky": "^9.0.11", - "lint-staged": "^15.2.2", + "lint-staged": "^15.2.4", "prettier": "^3.2.5", "release-it": "^17.3.0", "rimraf": "^5.0.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8d2df1b7..43972d4e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -164,14 +164,14 @@ importers: specifier: ^29.7.0 version: 29.7.0 glob: - specifier: ^10.3.15 - version: 10.3.15 + specifier: ^10.3.16 + version: 10.3.16 husky: specifier: ^9.0.11 version: 9.0.11 lint-staged: - specifier: ^15.2.2 - version: 15.2.2 + specifier: ^15.2.4 + version: 15.2.4 prettier: specifier: ^3.2.5 version: 3.2.5 @@ -182,7 +182,7 @@ importers: specifier: ^5.0.7 version: 5.0.7 semver: - specifier: ^7.5.3 + specifier: ^7.6.2 version: 7.6.2 ts-node: specifier: ^10.9.2 @@ -2071,9 +2071,9 @@ packages: resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} engines: {node: '>=14'} - commander@11.1.0: - resolution: {integrity: sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==} - engines: {node: '>=16'} + commander@12.1.0: + resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} + engines: {node: '>=18'} commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} @@ -2543,8 +2543,8 @@ packages: ee-first@1.1.1: resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} - electron-to-chromium@1.4.776: - resolution: {integrity: sha512-s694bi3+gUzlliqxjPHpa9NRTlhzTgB34aan+pVKZmOTGy2xoZXl+8E1B8i5p5rtev3PKMK/H4asgNejC+YHNg==} + electron-to-chromium@1.4.777: + resolution: {integrity: sha512-n02NCwLJ3wexLfK/yQeqfywCblZqLcXphzmid5e8yVPdtEcida7li0A5WQKghHNG0FeOMCzeFOzEbtAh5riXFw==} elliptic@6.5.5: resolution: {integrity: sha512-7EjbcmUm17NQFu4Pmgmq2olYMj8nwMnpcddByChSUjArp8F5DQWcIcpriwO4ZToLNAJig0yiyjswfyGNje/ixw==} @@ -3195,8 +3195,8 @@ packages: resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==} engines: {node: '>=10.13.0'} - glob@10.3.15: - resolution: {integrity: sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==} + glob@10.3.16: + resolution: {integrity: sha512-JDKXl1DiuuHJ6fVS2FXjownaavciiHNUU4mOvV/B793RLh05vZL1rcPnCSaOgv1hDT6RDlY7AB7ZUvFYAtPgAw==} engines: {node: '>=16 || 14 >=14.18'} hasBin: true @@ -3816,8 +3816,8 @@ packages: iterate-value@1.0.2: resolution: {integrity: sha512-A6fMAio4D2ot2r/TYzr4yUWrmwNdsN5xL7+HUiyACE4DXm+q8HtPcnFTp+NnW3k4N05tZ7FVYFFb2CR13NxyHQ==} - jackspeak@2.3.6: - resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} + jackspeak@3.1.2: + resolution: {integrity: sha512-kWmLKn2tRtfYMF/BakihVVRzBKOxz4gJMiL2Rj91WnAB5TPZumSH99R/Yf1qE1u4uRimvCSJfm6hnxohXeEXjQ==} engines: {node: '>=14'} jest-diff@29.7.0: @@ -3996,20 +3996,20 @@ packages: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} - lilconfig@3.0.0: - resolution: {integrity: sha512-K2U4W2Ff5ibV7j7ydLr+zLAkIg5JJ4lPn1Ltsdt+Tz/IjQ8buJ55pZAxoP34lqIiwtF9iAvtLv3JGv7CAyAg+g==} + lilconfig@3.1.1: + resolution: {integrity: sha512-O18pf7nyvHTckunPWCV1XUNXU1piu01y2b7ATJ0ppkUkk8ocqVWBrYjJBCwHDjD/ZWcfyrA0P4gKhzWGi5EINQ==} engines: {node: '>=14'} lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} - lint-staged@15.2.2: - resolution: {integrity: sha512-TiTt93OPh1OZOsb5B7k96A/ATl2AjIZo+vnzFZ6oHK5FuTk63ByDtxGQpHm+kFETjEWqgkF95M8FRXKR/LEBcw==} + lint-staged@15.2.4: + resolution: {integrity: sha512-3F9KRQIS2fVDGtCkBp4Bx0jswjX7zUcKx6OF0ZeY1prksUyKPRIIUqZhIUYAstJfvj6i48VFs4dwVIbCYwvTYQ==} engines: {node: '>=18.12.0'} hasBin: true - listr2@8.0.1: - resolution: {integrity: sha512-ovJXBXkKGfq+CwmKTjluEqFi3p4h8xvkxGQQAQan22YCgef4KZ1mKGjzfGh6PL6AW5Csw0QiQPNuQyH+6Xk3hA==} + listr2@8.2.1: + resolution: {integrity: sha512-irTfvpib/rNiD637xeevjO2l3Z5loZmuaRi0L0YE5LfijwVY96oyVn0DFD3o/teAok7nfobMG1THvvcHh/BP6g==} engines: {node: '>=18.0.0'} local-pkg@0.5.0: @@ -4198,8 +4198,8 @@ packages: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} - micromatch@4.0.5: - resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} + micromatch@4.0.6: + resolution: {integrity: sha512-Y4Ypn3oujJYxJcMacVgcs92wofTHxp9FzfDpQON4msDefoC0lb3ETvQLOdLcbhSwU1bz8HrL/1sygfBIHudrkQ==} engines: {node: '>=8.6'} mikro-orm@6.2.7: @@ -4847,6 +4847,10 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} + pidtree@0.6.0: resolution: {integrity: sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==} engines: {node: '>=0.10'} @@ -6259,9 +6263,10 @@ packages: resolution: {integrity: sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==} engines: {node: '>=18'} - yaml@2.3.4: - resolution: {integrity: sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==} + yaml@2.4.2: + resolution: {integrity: sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA==} engines: {node: '>= 14'} + hasBin: true yargs-parser@15.0.3: resolution: {integrity: sha512-/MVEVjTXy/cGAjdtQf8dW3V9b97bPN7rNn8ETj6BmAQL7ibC7O1Q9SPJbGjgh3SlwoBNXMzj/ZGIj8mBgl12YA==} @@ -8138,7 +8143,7 @@ snapshots: browserslist@4.23.0: dependencies: caniuse-lite: 1.0.30001620 - electron-to-chromium: 1.4.776 + electron-to-chromium: 1.4.777 node-releases: 2.0.14 update-browserslist-db: 1.0.16(browserslist@4.23.0) @@ -8447,7 +8452,7 @@ snapshots: commander@10.0.1: {} - commander@11.1.0: {} + commander@12.1.0: {} commander@2.20.3: {} @@ -8952,7 +8957,7 @@ snapshots: ee-first@1.1.1: {} - electron-to-chromium@1.4.776: {} + electron-to-chromium@1.4.777: {} elliptic@6.5.5: dependencies: @@ -9576,7 +9581,7 @@ snapshots: '@nodelib/fs.walk': 1.2.8 glob-parent: 5.1.2 merge2: 1.4.1 - micromatch: 4.0.5 + micromatch: 4.0.6 fast-json-stable-stringify@2.1.0: {} @@ -9830,10 +9835,10 @@ snapshots: dependencies: is-glob: 4.0.3 - glob@10.3.15: + glob@10.3.16: dependencies: foreground-child: 3.1.1 - jackspeak: 2.3.6 + jackspeak: 3.1.2 minimatch: 9.0.4 minipass: 7.1.1 path-scurry: 1.11.1 @@ -10459,7 +10464,7 @@ snapshots: es-get-iterator: 1.1.3 iterate-iterator: 1.0.2 - jackspeak@2.3.6: + jackspeak@3.1.2: dependencies: '@isaacs/cliui': 8.0.2 optionalDependencies: @@ -10488,7 +10493,7 @@ snapshots: '@types/stack-utils': 2.0.3 chalk: 4.1.2 graceful-fs: 4.2.11 - micromatch: 4.0.5 + micromatch: 4.0.6 pretty-format: 29.7.0 slash: 3.0.0 stack-utils: 2.0.6 @@ -10510,7 +10515,7 @@ snapshots: dependencies: config-chain: 1.1.13 editorconfig: 1.0.4 - glob: 10.3.15 + glob: 10.3.16 js-cookie: 3.0.5 nopt: 7.2.1 @@ -10655,26 +10660,26 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 - lilconfig@3.0.0: {} + lilconfig@3.1.1: {} lines-and-columns@1.2.4: {} - lint-staged@15.2.2: + lint-staged@15.2.4: dependencies: chalk: 5.3.0 - commander: 11.1.0 + commander: 12.1.0 debug: 4.3.4 execa: 8.0.1 - lilconfig: 3.0.0 - listr2: 8.0.1 - micromatch: 4.0.5 + lilconfig: 3.1.1 + listr2: 8.2.1 + micromatch: 4.0.6 pidtree: 0.6.0 string-argv: 0.3.2 - yaml: 2.3.4 + yaml: 2.4.2 transitivePeerDependencies: - supports-color - listr2@8.0.1: + listr2@8.2.1: dependencies: cli-truncate: 4.0.0 colorette: 2.0.20 @@ -10878,10 +10883,10 @@ snapshots: merge2@1.4.1: {} - micromatch@4.0.5: + micromatch@4.0.6: dependencies: braces: 3.0.3 - picomatch: 2.3.1 + picomatch: 4.0.2 mikro-orm@6.2.7: {} @@ -11560,6 +11565,8 @@ snapshots: picomatch@2.3.1: {} + picomatch@4.0.2: {} + pidtree@0.6.0: {} pify@2.3.0: {} @@ -11953,7 +11960,7 @@ snapshots: rimraf@5.0.7: dependencies: - glob: 10.3.15 + glob: 10.3.16 ripemd160@2.0.2: dependencies: @@ -13172,7 +13179,7 @@ snapshots: yallist@5.0.0: {} - yaml@2.3.4: {} + yaml@2.4.2: {} yargs-parser@15.0.3: dependencies: diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 07893578..864446c6 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -296,7 +296,8 @@ export class PerformanceStatistics { }) const timeMeasurementValues = extractTimeSeriesValues( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.statistics.statisticsData.get(entry.name)!.measurementTimeSeries! + this.statistics.statisticsData.get(entry.name)! + .measurementTimeSeries as CircularBuffer ) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.statistics.statisticsData.get(entry.name)!.avgTimeMeasurement = mean(timeMeasurementValues) diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 89511b02..9601a90c 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -13,7 +13,7 @@ export type StatisticsData = Partial<{ responseCount: number errorCount: number timeMeasurementCount: number - measurementTimeSeries: CircularBuffer + measurementTimeSeries: CircularBuffer | TimestampedData[] currentTimeMeasurement: number minTimeMeasurement: number maxTimeMeasurement: number diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 8103b474..2d666598 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -67,7 +67,7 @@ export class Constants { stopAbsoluteDuration: false }) - static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 385 + static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = 386 static readonly DEFAULT_HASH_ALGORITHM = 'sha384' diff --git a/src/utils/MessageChannelUtils.ts b/src/utils/MessageChannelUtils.ts index 2fb95256..bd7036ac 100644 --- a/src/utils/MessageChannelUtils.ts +++ b/src/utils/MessageChannelUtils.ts @@ -1,11 +1,12 @@ -import { clone } from 'rambda' +import type { CircularBuffer } from 'mnemonist' import type { ChargingStation } from '../charging-station/index.js' import { type ChargingStationData, type ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents, - type Statistics + type Statistics, + type TimestampedData } from '../types/index.js' import { buildChargingStationAutomaticTransactionGeneratorConfiguration, @@ -62,10 +63,22 @@ export const buildUpdatedMessage = ( export const buildPerformanceStatisticsMessage = ( statistics: Statistics ): ChargingStationWorkerMessage => { + const statisticsData = [...statistics.statisticsData].map(([key, value]) => { + value.measurementTimeSeries = ( + value.measurementTimeSeries as CircularBuffer + ).toArray() as TimestampedData[] + return [key, value] + }) return { event: ChargingStationWorkerMessageEvents.performanceStatistics, - // FIXME: CircularBuffer is not structured-cloneable, rambda clone strips the whole statisticsData Map - data: clone(statistics) + data: { + id: statistics.id, + name: statistics.name, + uri: statistics.uri, + createdAt: statistics.createdAt, + updatedAt: statistics.updatedAt, + statisticsData + } } } -- 2.34.1