-
Notifications
You must be signed in to change notification settings - Fork 2
chore(test): add runtime and metrics tests #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mcollina
merged 10 commits into
platformatic:main
from
rozzilla:chore/test/add-runtime-and-metrics-tests
Jan 7, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1d35e53
chore(test): add runtime and metrics tests
rozzilla 32f8cae
chore(lint): exclude fixtures
rozzilla 376168f
fix(test): apply changes
rozzilla ff58cd2
fix
rozzilla c6d5896
update
rozzilla 3256f81
chore(deps): update package lock
rozzilla 56cca68
chore(test): remove fixtures
rozzilla 633eb60
chore(test): update metrics test
rozzilla 0fe7b7a
chore(test): update listener on test
rozzilla 1f68c3f
updaet(deps
rozzilla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| 'use strict' | ||
|
|
||
| module.exports = require('neostandard')({ ignores: ['dist', 'node_modules'], ts: true }) | ||
| module.exports = require('neostandard')({ | ||
| ignores: ['dist', 'node_modules'], ts: true | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,72 @@ | ||
| import test from 'node:test' | ||
| import assert from 'node:assert' | ||
| import { getServer } from '../helper' | ||
| import { getServer, startWatt } from '../helper' | ||
|
|
||
| // TODO: add setup and test on a up & running wattpm instance | ||
| test('metrics plugin', async (t) => { | ||
| const server = await getServer(t) | ||
| const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
|
||
| test('metrics without runtime', async (t) => { | ||
| const server = await getServer(t) | ||
| assert.ok('_idleTimeout' in server.metricsInterval, 'interval for metrics are defined') | ||
| assert.deepEqual(server.mappedMetrics, {}, 'mapped metrics are defined') | ||
| const metricsKeys = Object.keys(server.mappedMetrics) | ||
| assert.ok(metricsKeys.length === 0, 'mapped metrics are defined, and are empty') | ||
| }) | ||
|
|
||
| test('metrics with runtime', async (t) => { | ||
| await startWatt(t) | ||
| const server = await getServer(t) | ||
|
|
||
| await wait(1200) | ||
| const metricsKeys = Object.keys(server.mappedMetrics) | ||
| const [pid] = metricsKeys | ||
| assert.ok(metricsKeys.length > 0, 'mapped metrics are defined, and contain values') | ||
| assert.strictEqual(server.mappedMetrics[pid][0].pid, parseInt(pid)) | ||
|
|
||
| const res = await server.inject({ | ||
| method: 'GET', | ||
| url: `/runtimes/${pid}/metrics` | ||
| }) | ||
| assert.strictEqual(res.statusCode, 200) | ||
|
|
||
| const metrics = res.json() | ||
| const expectedNames = [ | ||
| 'process_cpu_user_seconds_total', | ||
| 'process_cpu_system_seconds_total', | ||
| 'process_cpu_seconds_total', | ||
| 'process_start_time_seconds', | ||
| 'process_resident_memory_bytes', | ||
| 'nodejs_eventloop_lag_seconds', | ||
| 'nodejs_eventloop_lag_min_seconds', | ||
| 'nodejs_eventloop_lag_max_seconds', | ||
| 'nodejs_eventloop_lag_mean_seconds', | ||
| 'nodejs_eventloop_lag_stddev_seconds', | ||
| 'nodejs_eventloop_lag_p50_seconds', | ||
| 'nodejs_eventloop_lag_p90_seconds', | ||
| 'nodejs_eventloop_lag_p99_seconds', | ||
| 'nodejs_active_resources', | ||
| 'nodejs_active_resources_total', | ||
| 'nodejs_active_handles', | ||
| 'nodejs_active_handles_total', | ||
| 'nodejs_active_requests_total', | ||
| 'nodejs_heap_size_total_bytes', | ||
| 'nodejs_heap_size_used_bytes', | ||
| 'nodejs_external_memory_bytes', | ||
| 'nodejs_heap_space_size_total_bytes', | ||
| 'nodejs_heap_space_size_used_bytes', | ||
| 'nodejs_heap_space_size_available_bytes', | ||
| 'nodejs_version_info', | ||
| 'nodejs_gc_duration_seconds', | ||
| 'nodejs_eventloop_utilization', | ||
| 'process_cpu_percent_usage', | ||
| 'thread_cpu_user_system_seconds_total', | ||
| 'thread_cpu_system_seconds_total', | ||
| 'thread_cpu_percent_usage', | ||
| 'thread_cpu_seconds_total', | ||
| 'http_cache_hit_count', | ||
| 'http_cache_miss_count' | ||
| ] | ||
| expectedNames.forEach(expectedName => { | ||
| // TODO: remove cast to any | ||
| const exists = metrics.some((metric: any) => metric.name === expectedName) | ||
| assert.ok(exists, `Expected metric: ${expectedName}`) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,27 @@ | ||
| import test from 'node:test' | ||
| import assert from 'node:assert' | ||
| import { getServer } from '../helper' | ||
| import { getServer, startWatt } from '../helper' | ||
|
|
||
| // TODO: add setup and test on a up & running wattpm instance | ||
| test('root', async (t) => { | ||
| test('no runtime running', async (t) => { | ||
| const server = await getServer(t) | ||
| const res = await server.inject({ | ||
| method: 'GET', | ||
| url: '/runtimes' | ||
| }) | ||
| assert.strictEqual(res.statusCode, 200) | ||
| assert.deepStrictEqual(res.json(), [], 'with no runtime running') | ||
| }) | ||
|
|
||
| test('runtime is running', async (t) => { | ||
| await startWatt(t) | ||
| const server = await getServer(t) | ||
| const res = await server.inject({ | ||
| method: 'GET', | ||
| url: '/runtimes' | ||
| }) | ||
| assert.strictEqual(res.statusCode, 200) | ||
| assert.deepStrictEqual(res.json(), []) | ||
| const [runtime] = res.json() | ||
| assert.strictEqual(typeof runtime.packageName, 'string') | ||
| assert.strictEqual(typeof runtime.pid, 'number') | ||
| assert.strictEqual(runtime.packageVersion, null) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.