adonisjs-server-stats 1.9.0 → 1.10.3
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/README.md +23 -14
- package/dist/core/config-utils.d.ts +8 -0
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/dashboard-data-controller.d.ts +16 -0
- package/dist/core/dashboard-data-helpers.d.ts +12 -0
- package/dist/core/debug-data-controller.d.ts +4 -0
- package/dist/core/define-config-helpers.d.ts +25 -0
- package/dist/core/feature-detect-helpers.d.ts +36 -0
- package/dist/core/formatters-helpers.d.ts +23 -0
- package/dist/core/index.js +596 -509
- package/dist/core/log-utils-helpers.d.ts +13 -0
- package/dist/core/metrics.d.ts +3 -28
- package/dist/core/pagination.d.ts +0 -9
- package/dist/core/server-stats-controller.d.ts +6 -0
- package/dist/core/split-pane.d.ts +18 -0
- package/dist/core/trace-utils.d.ts +5 -0
- package/dist/core/transmit-helpers.d.ts +7 -0
- package/dist/core/types-dashboard.d.ts +178 -0
- package/dist/core/types-diagnostics.d.ts +85 -0
- package/dist/core/types.d.ts +11 -443
- package/dist/react/{CacheSection-xH75hwXu.js → CacheSection-baMZotSn.js} +2 -2
- package/dist/react/CacheTab-2cw_rMzj.js +117 -0
- package/dist/react/{ConfigSection-D8BO1Ry9.js → ConfigSection-DGgqjAal.js} +1 -1
- package/dist/react/{ConfigTab-CcN-tfjv.js → ConfigTab-H3OnYqmK.js} +1 -1
- package/dist/react/CustomPaneTab-B6r7ha0u.js +98 -0
- package/dist/react/{EmailsSection-BzlsTdPs.js → EmailsSection-C-UZISG-.js} +2 -2
- package/dist/react/EmailsTab-DbK4Eobn.js +139 -0
- package/dist/react/{EventsSection-CGQWiIdV.js → EventsSection-C7RQW_LY.js} +2 -2
- package/dist/react/EventsTab-CfVr7AiM.js +57 -0
- package/dist/react/{FilterBar-DQRXpWrb.js → FilterBar-CQ7bD669.js} +15 -15
- package/dist/react/{JobsSection-D7AHQmZi.js → JobsSection-CQHNK_Ls.js} +2 -2
- package/dist/react/{JobsTab-B3Lfdqed.js → JobsTab-znzf6jzk.js} +54 -42
- package/dist/react/{LogsSection-Cly1dpvS.js → LogsSection-Dmm3rE2B.js} +9 -3
- package/dist/react/LogsTab-D8unMV5P.js +108 -0
- package/dist/react/{OverviewSection-CkBGFEWq.js → OverviewSection-ABP9ueBo.js} +1 -1
- package/dist/react/{QueriesSection-CfCpnNUD.js → QueriesSection-CnmSkznA.js} +2 -2
- package/dist/react/{QueriesTab-DbBmAqzO.js → QueriesTab-BQzcxEiW.js} +37 -40
- package/dist/react/RelatedLogs-3A8RuGKH.js +52 -0
- package/dist/react/RequestsSection-kW79_M7k.js +341 -0
- package/dist/react/{RoutesSection-CRqF-cNM.js → RoutesSection-BRhxrtjZ.js} +2 -2
- package/dist/react/RoutesTab-CpYH5lUw.js +68 -0
- package/dist/react/TimelineTab-DjLR35Ce.js +214 -0
- package/dist/react/index-CsImORX6.js +1121 -0
- package/dist/react/index.js +1 -1
- package/dist/react/react/components/{Dashboard/shared → shared}/FilterBar.d.ts +4 -3
- package/dist/react/react/components/shared/RelatedLogs.d.ts +7 -0
- package/dist/react/react/hooks/useDashboardData.d.ts +4 -8
- package/dist/react/style.css +1 -1
- package/dist/src/collectors/app_collector.d.ts +0 -8
- package/dist/src/collectors/app_collector.js +45 -52
- package/dist/src/collectors/auto_detect.d.ts +0 -23
- package/dist/src/collectors/auto_detect.js +33 -55
- package/dist/src/collectors/db_pool_collector.d.ts +14 -16
- package/dist/src/collectors/db_pool_collector.js +72 -57
- package/dist/src/collectors/log_collector.d.ts +0 -47
- package/dist/src/collectors/log_collector.js +36 -65
- package/dist/src/collectors/queue_collector.d.ts +0 -20
- package/dist/src/collectors/queue_collector.js +60 -76
- package/dist/src/collectors/redis_collector.d.ts +10 -10
- package/dist/src/collectors/redis_collector.js +69 -66
- package/dist/src/config/deprecation_migration.d.ts +7 -0
- package/dist/src/config/deprecation_migration.js +201 -0
- package/dist/src/controller/debug_controller.d.ts +1 -1
- package/dist/src/controller/debug_controller.js +87 -81
- package/dist/src/dashboard/cache_handlers.d.ts +14 -0
- package/dist/src/dashboard/cache_handlers.js +52 -0
- package/dist/src/dashboard/chart_aggregator.d.ts +0 -7
- package/dist/src/dashboard/chart_aggregator.js +68 -50
- package/dist/src/dashboard/coalesce_cache.d.ts +25 -0
- package/dist/src/dashboard/coalesce_cache.js +47 -0
- package/dist/src/dashboard/dashboard_controller.d.ts +11 -37
- package/dist/src/dashboard/dashboard_controller.js +52 -532
- package/dist/src/dashboard/dashboard_page_assets.d.ts +17 -0
- package/dist/src/dashboard/dashboard_page_assets.js +51 -0
- package/dist/src/dashboard/dashboard_store.d.ts +19 -217
- package/dist/src/dashboard/dashboard_store.js +115 -1069
- package/dist/src/dashboard/dashboard_types.d.ts +83 -0
- package/dist/src/dashboard/dashboard_types.js +4 -0
- package/dist/src/dashboard/detail_queries.d.ts +19 -0
- package/dist/src/dashboard/detail_queries.js +98 -0
- package/dist/src/dashboard/email_event_builder.d.ts +8 -0
- package/dist/src/dashboard/email_event_builder.js +65 -0
- package/dist/src/dashboard/explain_query.d.ts +8 -0
- package/dist/src/dashboard/explain_query.js +22 -0
- package/dist/src/dashboard/filter_handlers.d.ts +23 -0
- package/dist/src/dashboard/filter_handlers.js +56 -0
- package/dist/src/dashboard/filtered_queries.d.ts +15 -0
- package/dist/src/dashboard/filtered_queries.js +155 -0
- package/dist/src/dashboard/flush_manager.d.ts +25 -0
- package/dist/src/dashboard/flush_manager.js +107 -0
- package/dist/src/dashboard/format_helpers.d.ts +126 -0
- package/dist/src/dashboard/format_helpers.js +140 -0
- package/dist/src/dashboard/inspector_manager.d.ts +36 -0
- package/dist/src/dashboard/inspector_manager.js +102 -0
- package/dist/src/dashboard/integrations/config_inspector.js +11 -13
- package/dist/src/dashboard/integrations/queue_inspector.d.ts +3 -3
- package/dist/src/dashboard/integrations/queue_inspector.js +13 -10
- package/dist/src/dashboard/jobs_handlers.d.ts +14 -0
- package/dist/src/dashboard/jobs_handlers.js +61 -0
- package/dist/src/dashboard/knex_factory.d.ts +18 -0
- package/dist/src/dashboard/knex_factory.js +91 -0
- package/dist/src/dashboard/migrator.js +30 -153
- package/dist/src/dashboard/migrator_tables.d.ts +19 -0
- package/dist/src/dashboard/migrator_tables.js +153 -0
- package/dist/src/dashboard/overview_queries.d.ts +66 -0
- package/dist/src/dashboard/overview_queries.js +155 -0
- package/dist/src/dashboard/overview_query_runners.d.ts +25 -0
- package/dist/src/dashboard/overview_query_runners.js +84 -0
- package/dist/src/dashboard/overview_store_queries.d.ts +40 -0
- package/dist/src/dashboard/overview_store_queries.js +69 -0
- package/dist/src/dashboard/paginate_helper.d.ts +12 -0
- package/dist/src/dashboard/paginate_helper.js +33 -0
- package/dist/src/dashboard/query_explain_handler.d.ts +10 -0
- package/dist/src/dashboard/query_explain_handler.js +80 -0
- package/dist/src/dashboard/read_queries.d.ts +32 -0
- package/dist/src/dashboard/read_queries.js +107 -0
- package/dist/src/dashboard/saved_filter_queries.d.ts +10 -0
- package/dist/src/dashboard/saved_filter_queries.js +24 -0
- package/dist/src/dashboard/storage_stats.d.ts +41 -0
- package/dist/src/dashboard/storage_stats.js +81 -0
- package/dist/src/dashboard/write_queue.d.ts +106 -0
- package/dist/src/dashboard/write_queue.js +225 -0
- package/dist/src/data/data_access.d.ts +6 -36
- package/dist/src/data/data_access.js +43 -188
- package/dist/src/data/data_access_helpers.d.ts +130 -0
- package/dist/src/data/data_access_helpers.js +212 -0
- package/dist/src/debug/debug_store.js +37 -32
- package/dist/src/debug/email_collector.d.ts +1 -10
- package/dist/src/debug/email_collector.js +78 -81
- package/dist/src/debug/event_collector.d.ts +0 -9
- package/dist/src/debug/event_collector.js +79 -62
- package/dist/src/debug/query_collector.js +23 -19
- package/dist/src/debug/route_inspector.d.ts +1 -5
- package/dist/src/debug/route_inspector.js +50 -51
- package/dist/src/debug/trace_collector.d.ts +10 -2
- package/dist/src/debug/trace_collector.js +23 -16
- package/dist/src/debug/types.d.ts +5 -1
- package/dist/src/define_config.d.ts +0 -65
- package/dist/src/define_config.js +93 -333
- package/dist/src/edge/client/dashboard.js +2 -2
- package/dist/src/edge/client/debug-panel-deferred.js +1 -1
- package/dist/src/edge/client/stats-bar.js +1 -1
- package/dist/src/edge/client-vue/dashboard.js +5 -5
- package/dist/src/edge/client-vue/debug-panel-deferred.js +3 -3
- package/dist/src/edge/client-vue/stats-bar.js +3 -3
- package/dist/src/edge/plugin.d.ts +0 -16
- package/dist/src/edge/plugin.js +57 -64
- package/dist/src/engine/request_metrics.d.ts +1 -0
- package/dist/src/engine/request_metrics.js +32 -42
- package/dist/src/middleware/request_tracking_middleware.d.ts +3 -8
- package/dist/src/middleware/request_tracking_middleware.js +65 -91
- package/dist/src/provider/auth_middleware_detector.d.ts +16 -0
- package/dist/src/provider/auth_middleware_detector.js +97 -0
- package/dist/src/provider/boot_helpers.d.ts +20 -0
- package/dist/src/provider/boot_helpers.js +91 -0
- package/dist/src/provider/boot_initializer.d.ts +28 -0
- package/dist/src/provider/boot_initializer.js +35 -0
- package/dist/src/provider/dashboard_init.d.ts +30 -0
- package/dist/src/provider/dashboard_init.js +138 -0
- package/dist/src/provider/dashboard_setup.d.ts +25 -0
- package/dist/src/provider/dashboard_setup.js +78 -0
- package/dist/src/provider/diagnostics.d.ts +134 -0
- package/dist/src/provider/diagnostics.js +127 -0
- package/dist/src/provider/email_bridge.d.ts +43 -0
- package/dist/src/provider/email_bridge.js +80 -0
- package/dist/src/provider/email_helpers.d.ts +13 -0
- package/dist/src/provider/email_helpers.js +68 -0
- package/dist/src/provider/pino_hook.d.ts +17 -0
- package/dist/src/provider/pino_hook.js +35 -0
- package/dist/src/provider/provider_helpers_extra.d.ts +47 -0
- package/dist/src/provider/provider_helpers_extra.js +177 -0
- package/dist/src/provider/server_stats_provider.d.ts +39 -85
- package/dist/src/provider/server_stats_provider.js +131 -936
- package/dist/src/provider/shutdown_helpers.d.ts +43 -0
- package/dist/src/provider/shutdown_helpers.js +70 -0
- package/dist/src/provider/toolbar_setup.d.ts +57 -0
- package/dist/src/provider/toolbar_setup.js +141 -0
- package/dist/src/routes/dashboard_routes.d.ts +14 -0
- package/dist/src/routes/dashboard_routes.js +197 -0
- package/dist/src/routes/debug_routes.d.ts +14 -0
- package/dist/src/routes/debug_routes.js +101 -0
- package/dist/src/routes/register_routes.d.ts +0 -78
- package/dist/src/routes/register_routes.js +22 -347
- package/dist/src/routes/stats_routes.d.ts +5 -0
- package/dist/src/routes/stats_routes.js +14 -0
- package/dist/src/styles/components.css +177 -0
- package/dist/src/styles/dashboard.css +8 -90
- package/dist/src/styles/debug-panel.css +10 -31
- package/dist/src/types.d.ts +306 -15
- package/dist/vue/{CacheSection-Cx-hj09X.js → CacheSection-ITqvpfH5.js} +1 -1
- package/dist/vue/{ConfigSection-CMXyryf6.js → ConfigSection-DTn3GslE.js} +1 -1
- package/dist/vue/{EmailsSection-DgKl9xGT.js → EmailsSection-DtLJ4XoS.js} +1 -1
- package/dist/vue/{EventsSection-BNMCAim1.js → EventsSection-BOYYz0Ty.js} +1 -1
- package/dist/vue/{JobsSection-CCMgMlxd.js → JobsSection-BazTxcJL.js} +1 -1
- package/dist/vue/{LogsSection-CvOnTxUu.js → LogsSection-D55PjTKX.js} +9 -3
- package/dist/vue/{LogsTab-Bg3o0Mm6.js → LogsTab-47zEK7jL.js} +4 -1
- package/dist/vue/{OverviewSection-CHgaKtUR.js → OverviewSection-1uBKo-Tu.js} +1 -1
- package/dist/vue/{QueriesSection-BnHRD98z.js → QueriesSection-rpoZ4ogd.js} +1 -1
- package/dist/vue/RelatedLogs.vue_vue_type_script_setup_true_lang-CB2_TzYW.js +84 -0
- package/dist/vue/RequestsSection-x7LvT0MC.js +401 -0
- package/dist/vue/{RoutesSection-BrceOcKQ.js → RoutesSection-CCD0zZqQ.js} +1 -1
- package/dist/vue/TimelineTab-zj5Z5OdT.js +338 -0
- package/dist/vue/components/Dashboard/sections/RequestsSection.vue.d.ts +4 -0
- package/dist/vue/components/DebugPanel/tabs/TimelineTab.vue.d.ts +4 -0
- package/dist/vue/components/{Dashboard/sections/TimelineSection.vue.d.ts → shared/RelatedLogs.vue.d.ts} +5 -6
- package/dist/vue/composables/useDashboardData.d.ts +12 -23
- package/dist/vue/index-C8MxnS7Q.js +1232 -0
- package/dist/vue/index.js +1 -1
- package/dist/vue/style.css +1 -1
- package/package.json +1 -1
- package/dist/react/CacheTab-DYmsZJJ1.js +0 -123
- package/dist/react/CustomPaneTab-D7_o3Ec6.js +0 -104
- package/dist/react/EmailsTab-Uh2CQY3o.js +0 -153
- package/dist/react/EventsTab-CC6DQzEm.js +0 -63
- package/dist/react/LogsTab-BbYK-iyh.js +0 -103
- package/dist/react/RequestsSection-Cb5a6MlT.js +0 -209
- package/dist/react/RoutesTab-Bwreij3e.js +0 -74
- package/dist/react/TimelineSection-B2y06kRE.js +0 -158
- package/dist/react/TimelineTab-6hthfdBB.js +0 -193
- package/dist/react/WaterfallChart-Cj73WdfM.js +0 -100
- package/dist/react/index-CecA4IdQ.js +0 -1075
- package/dist/react/react/components/Dashboard/sections/TimelineSection.d.ts +0 -8
- package/dist/vue/RequestsSection-B-uSlM0f.js +0 -243
- package/dist/vue/TimelineSection-CfvnA2Oo.js +0 -186
- package/dist/vue/TimelineTab-Db6lKKsD.js +0 -250
- package/dist/vue/WaterfallChart.vue_vue_type_script_setup_true_lang-tZ13cNj1.js +0 -118
- package/dist/vue/index-oLxS08vN.js +0 -1235
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { log, dim, bold } from '../utils/logger.js';
|
|
2
|
+
import { detectGlobalAuthMiddleware, buildAuthMiddlewareWarning, } from './auth_middleware_detector.js';
|
|
3
|
+
export function deriveEndpointPaths(endpoint, devToolbar) {
|
|
4
|
+
const statsEndpoint = typeof endpoint === 'string' ? endpoint : false;
|
|
5
|
+
const debugEndpoint = devToolbar?.enabled
|
|
6
|
+
? (devToolbar.debugEndpoint ?? '/admin/api/debug')
|
|
7
|
+
: undefined;
|
|
8
|
+
return { statsEndpoint, debugEndpoint };
|
|
9
|
+
}
|
|
10
|
+
export function computeDashboardPath(devToolbar, depsAvailable) {
|
|
11
|
+
if (!devToolbar?.enabled || !devToolbar.dashboard || !depsAvailable)
|
|
12
|
+
return undefined;
|
|
13
|
+
return devToolbar.dashboardPath ?? '/__stats';
|
|
14
|
+
}
|
|
15
|
+
export function collectRegisteredPaths(statsEndpoint, debugEndpoint, dashboardPath) {
|
|
16
|
+
const paths = [];
|
|
17
|
+
if (typeof statsEndpoint === 'string')
|
|
18
|
+
paths.push(statsEndpoint);
|
|
19
|
+
if (debugEndpoint)
|
|
20
|
+
paths.push(debugEndpoint + '/*');
|
|
21
|
+
if (dashboardPath)
|
|
22
|
+
paths.push(dashboardPath + '/*');
|
|
23
|
+
return paths;
|
|
24
|
+
}
|
|
25
|
+
export async function checkDashboardDeps(appImport) {
|
|
26
|
+
const missing = [];
|
|
27
|
+
try {
|
|
28
|
+
await appImport('knex');
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
missing.push('knex');
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
await appImport('better-sqlite3');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
missing.push('better-sqlite3');
|
|
38
|
+
}
|
|
39
|
+
return missing;
|
|
40
|
+
}
|
|
41
|
+
export function logMissingDeps(missing) {
|
|
42
|
+
if (missing.length === 0)
|
|
43
|
+
return;
|
|
44
|
+
log.block(`Dashboard requires ${missing.join(' and ')}. Install with:`, [
|
|
45
|
+
'',
|
|
46
|
+
bold(`npm install ${missing.join(' ')}`),
|
|
47
|
+
'',
|
|
48
|
+
dim('Dashboard routes have been skipped for now.'),
|
|
49
|
+
dim('Everything else (stats bar, debug panel) works without it.'),
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
export function warnAboutAuthMiddleware(config, makePath) {
|
|
53
|
+
if (config.shouldShow)
|
|
54
|
+
return;
|
|
55
|
+
const found = detectGlobalAuthMiddleware(makePath);
|
|
56
|
+
if (found.length === 0)
|
|
57
|
+
return;
|
|
58
|
+
log.block(bold('found global auth middleware that will run on every poll:'), buildAuthMiddlewareWarning(found, dim, bold));
|
|
59
|
+
}
|
|
60
|
+
export function logDashboardError(category, err) {
|
|
61
|
+
if (category === 'missing-dep') {
|
|
62
|
+
log.block('Dashboard could not start — missing dependencies. Install with:', [
|
|
63
|
+
'',
|
|
64
|
+
bold('npm install knex better-sqlite3'),
|
|
65
|
+
'',
|
|
66
|
+
dim('Dashboard has been disabled for this session.'),
|
|
67
|
+
dim('Everything else (stats bar, debug panel) works without it.'),
|
|
68
|
+
]);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (category === 'timeout') {
|
|
72
|
+
log.block('Dashboard initialization timed out', [
|
|
73
|
+
dim('SQLite setup took too long — this usually means a wrong native'),
|
|
74
|
+
dim('binary was loaded (common with symlinked/file: dependencies).'),
|
|
75
|
+
'',
|
|
76
|
+
dim('Try running:'),
|
|
77
|
+
' ' + bold('npm install knex better-sqlite3'),
|
|
78
|
+
dim('in your app directory to ensure the correct copies are used.'),
|
|
79
|
+
'',
|
|
80
|
+
dim('Dashboard has been disabled for this session.'),
|
|
81
|
+
dim('Everything else (stats bar, debug panel) works without it.'),
|
|
82
|
+
]);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
log.warn('Dashboard could not start: ' +
|
|
86
|
+
(err?.message ?? '') +
|
|
87
|
+
'\n ' +
|
|
88
|
+
dim('Dashboard has been disabled for this session.'));
|
|
89
|
+
if (err?.stack)
|
|
90
|
+
console.error(err.stack);
|
|
91
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot initialization helpers for ServerStatsProvider.
|
|
3
|
+
* Pure functions for endpoint derivation, dashboard path computation, and route path collection.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Derive stats and debug endpoint paths from config.
|
|
7
|
+
*/
|
|
8
|
+
export declare function deriveEndpointPaths(endpoint: string | false | undefined, devToolbar?: {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
debugEndpoint?: string;
|
|
11
|
+
dashboard?: boolean;
|
|
12
|
+
dashboardPath?: string;
|
|
13
|
+
}): {
|
|
14
|
+
statsEndpoint: string | false;
|
|
15
|
+
debugEndpoint: string | undefined;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Compute the dashboard path from toolbar config and dependency availability.
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeDashboardPath(devToolbar?: {
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
dashboard?: boolean;
|
|
23
|
+
dashboardPath?: string;
|
|
24
|
+
}, depsAvailable?: boolean): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Collect registered route paths for logging.
|
|
27
|
+
*/
|
|
28
|
+
export declare function collectRegisteredPaths(statsEndpoint: string | false, debugEndpoint?: string, dashboardPath?: string): string[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot initialization helpers for ServerStatsProvider.
|
|
3
|
+
* Pure functions for endpoint derivation, dashboard path computation, and route path collection.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Derive stats and debug endpoint paths from config.
|
|
7
|
+
*/
|
|
8
|
+
export function deriveEndpointPaths(endpoint, devToolbar) {
|
|
9
|
+
const statsEndpoint = typeof endpoint === 'string' ? endpoint : false;
|
|
10
|
+
const debugEndpoint = devToolbar?.enabled
|
|
11
|
+
? (devToolbar.debugEndpoint ?? '/admin/api/debug')
|
|
12
|
+
: undefined;
|
|
13
|
+
return { statsEndpoint, debugEndpoint };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compute the dashboard path from toolbar config and dependency availability.
|
|
17
|
+
*/
|
|
18
|
+
export function computeDashboardPath(devToolbar, depsAvailable) {
|
|
19
|
+
if (!devToolbar?.enabled || !devToolbar.dashboard || !depsAvailable)
|
|
20
|
+
return undefined;
|
|
21
|
+
return devToolbar.dashboardPath ?? '/__stats';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Collect registered route paths for logging.
|
|
25
|
+
*/
|
|
26
|
+
export function collectRegisteredPaths(statsEndpoint, debugEndpoint, dashboardPath) {
|
|
27
|
+
const paths = [];
|
|
28
|
+
if (typeof statsEndpoint === 'string')
|
|
29
|
+
paths.push(statsEndpoint);
|
|
30
|
+
if (debugEndpoint)
|
|
31
|
+
paths.push(debugEndpoint + '/*');
|
|
32
|
+
if (dashboardPath)
|
|
33
|
+
paths.push(dashboardPath + '/*');
|
|
34
|
+
return paths;
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard initialization helpers extracted from toolbar_setup.
|
|
3
|
+
* Handles SQLite store creation, log piping, request piping, and broadcasting.
|
|
4
|
+
*/
|
|
5
|
+
import { LogStreamService } from '../log_stream/log_stream_service.js';
|
|
6
|
+
import type DashboardController from '../dashboard/dashboard_controller.js';
|
|
7
|
+
import type { DashboardStore } from '../dashboard/dashboard_store.js';
|
|
8
|
+
import type { DebugStore } from '../debug/debug_store.js';
|
|
9
|
+
import type { DevToolbarConfig } from '../debug/types.js';
|
|
10
|
+
import type { StatsEngine } from '../engine/stats_engine.js';
|
|
11
|
+
import type { ApplicationService } from '@adonisjs/core/types';
|
|
12
|
+
interface DashboardResult {
|
|
13
|
+
dashboardStore: DashboardStore | null;
|
|
14
|
+
dashboardController: DashboardController | null;
|
|
15
|
+
dashboardLogStream: LogStreamService | null;
|
|
16
|
+
dashboardBroadcastTimer: ReturnType<typeof setInterval> | null;
|
|
17
|
+
}
|
|
18
|
+
interface DashboardStoreOptions {
|
|
19
|
+
tc: DevToolbarConfig;
|
|
20
|
+
emitter: unknown;
|
|
21
|
+
app: ApplicationService;
|
|
22
|
+
debugStore: DebugStore;
|
|
23
|
+
engine: StatsEngine;
|
|
24
|
+
pinoHookActive: boolean;
|
|
25
|
+
transmitChannels: string[];
|
|
26
|
+
onResult: (r: DashboardResult) => void;
|
|
27
|
+
}
|
|
28
|
+
/** Initialize the full-page dashboard: SQLite store, controller, log piping, broadcasting. */
|
|
29
|
+
export declare function initDashboardStore(opts: DashboardStoreOptions): Promise<void>;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dashboard initialization helpers extracted from toolbar_setup.
|
|
3
|
+
* Handles SQLite store creation, log piping, request piping, and broadcasting.
|
|
4
|
+
*/
|
|
5
|
+
import { getLogStreamService } from '../collectors/log_collector.js';
|
|
6
|
+
import { LogStreamService } from '../log_stream/log_stream_service.js';
|
|
7
|
+
import { setDashboardPath, setOnRequestComplete, } from '../middleware/request_tracking_middleware.js';
|
|
8
|
+
import { log, dim, bold } from '../utils/logger.js';
|
|
9
|
+
import { classifyDashboardError, createStartTimeout } from './dashboard_setup.js';
|
|
10
|
+
/** Initialize the full-page dashboard: SQLite store, controller, log piping, broadcasting. */
|
|
11
|
+
export async function initDashboardStore(opts) {
|
|
12
|
+
const { tc, emitter, app, debugStore, engine, pinoHookActive, transmitChannels, onResult } = opts;
|
|
13
|
+
log.info('dashboard: initializing SQLite store...');
|
|
14
|
+
const { DashboardStore: DSC } = await import('../dashboard/dashboard_store.js');
|
|
15
|
+
const dashboardStore = new DSC(tc);
|
|
16
|
+
try {
|
|
17
|
+
await createStartTimeout(dashboardStore.start(null, emitter, app.makePath('')), 15_000);
|
|
18
|
+
log.info('dashboard: SQLite store ready');
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
logDashboardStartError(err);
|
|
22
|
+
onResult({
|
|
23
|
+
dashboardStore: null,
|
|
24
|
+
dashboardController: null,
|
|
25
|
+
dashboardLogStream: null,
|
|
26
|
+
dashboardBroadcastTimer: null,
|
|
27
|
+
});
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const container = app.container;
|
|
31
|
+
container.singleton('dashboard.store', () => dashboardStore);
|
|
32
|
+
setDashboardPath(tc.dashboardPath);
|
|
33
|
+
const DCC = (await import('../dashboard/dashboard_controller.js')).default;
|
|
34
|
+
const dashboardController = new DCC(dashboardStore, app);
|
|
35
|
+
const dashboardLogStream = pipeDashLogs(pinoHookActive, dashboardStore, app.makePath.bind(app));
|
|
36
|
+
pipeDashRequests(debugStore, dashboardStore);
|
|
37
|
+
const dashboardBroadcastTimer = await setupDashBroadcast({
|
|
38
|
+
container,
|
|
39
|
+
dashboardStore,
|
|
40
|
+
engine,
|
|
41
|
+
debugStore,
|
|
42
|
+
transmitChannels,
|
|
43
|
+
});
|
|
44
|
+
onResult({ dashboardStore, dashboardController, dashboardLogStream, dashboardBroadcastTimer });
|
|
45
|
+
}
|
|
46
|
+
async function setupDashBroadcast(deps) {
|
|
47
|
+
const { container, dashboardStore, engine, debugStore, transmitChannels } = deps;
|
|
48
|
+
let transmit = null;
|
|
49
|
+
try {
|
|
50
|
+
transmit = await container.make('transmit');
|
|
51
|
+
}
|
|
52
|
+
catch { }
|
|
53
|
+
if (!transmit)
|
|
54
|
+
return null;
|
|
55
|
+
const ch = 'server-stats/dashboard';
|
|
56
|
+
if (!transmitChannels.includes(ch))
|
|
57
|
+
transmitChannels.push(ch);
|
|
58
|
+
return setInterval(async () => {
|
|
59
|
+
try {
|
|
60
|
+
if (!dashboardStore.isReady())
|
|
61
|
+
return;
|
|
62
|
+
const o = await dashboardStore.getOverviewMetrics('1h');
|
|
63
|
+
transmit.broadcast(ch, {
|
|
64
|
+
...o,
|
|
65
|
+
diagnostics: {
|
|
66
|
+
collectors: engine.getCollectorHealth(),
|
|
67
|
+
buffers: debugStore.getBufferStats(),
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
}, 30_000);
|
|
73
|
+
}
|
|
74
|
+
function pipeDashLogs(pinoHookActive, dashboardStore, makePath) {
|
|
75
|
+
const existing = getLogStreamService();
|
|
76
|
+
if (pinoHookActive && existing && !existing['logPath']) {
|
|
77
|
+
const orig = existing['onEntry'];
|
|
78
|
+
existing['onEntry'] = (entry) => {
|
|
79
|
+
orig?.(entry);
|
|
80
|
+
dashboardStore.recordLog(entry);
|
|
81
|
+
};
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const service = new LogStreamService(makePath('logs', 'adonisjs.log'), (entry) => {
|
|
85
|
+
dashboardStore.recordLog(entry);
|
|
86
|
+
});
|
|
87
|
+
service.start().catch(() => { });
|
|
88
|
+
return service;
|
|
89
|
+
}
|
|
90
|
+
function pipeDashRequests(debugStore, dashboardStore) {
|
|
91
|
+
let lastQueryId = 0;
|
|
92
|
+
setOnRequestComplete(({ method, url, statusCode, duration, trace, httpRequestId }) => {
|
|
93
|
+
if (!dashboardStore.isReady())
|
|
94
|
+
return;
|
|
95
|
+
const q = debugStore.queries.getQueriesSince(lastQueryId);
|
|
96
|
+
if (q.length > 0)
|
|
97
|
+
lastQueryId = q[q.length - 1].id;
|
|
98
|
+
dashboardStore.persistRequest({
|
|
99
|
+
method,
|
|
100
|
+
url,
|
|
101
|
+
statusCode,
|
|
102
|
+
duration,
|
|
103
|
+
queries: q,
|
|
104
|
+
trace: trace ?? null,
|
|
105
|
+
httpRequestId: httpRequestId ?? null,
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function logDashboardStartError(err) {
|
|
110
|
+
const c = classifyDashboardError(err);
|
|
111
|
+
if (c === 'missing-dep') {
|
|
112
|
+
log.block('Dashboard could not start — missing dependencies. Install with:', [
|
|
113
|
+
'',
|
|
114
|
+
bold('npm install knex better-sqlite3'),
|
|
115
|
+
'',
|
|
116
|
+
dim('Dashboard has been disabled for this session.'),
|
|
117
|
+
dim('Everything else (stats bar, debug panel) works without it.'),
|
|
118
|
+
]);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (c === 'timeout') {
|
|
122
|
+
log.block('Dashboard initialization timed out', [
|
|
123
|
+
dim('SQLite setup took too long — this usually means a wrong native'),
|
|
124
|
+
dim('binary was loaded (common with symlinked/file: dependencies).'),
|
|
125
|
+
'',
|
|
126
|
+
dim('Try running:'),
|
|
127
|
+
` ${bold('npm install knex better-sqlite3')}`,
|
|
128
|
+
dim('in your app directory to ensure the correct copies are used.'),
|
|
129
|
+
'',
|
|
130
|
+
dim('Dashboard has been disabled for this session.'),
|
|
131
|
+
dim('Everything else (stats bar, debug panel) works without it.'),
|
|
132
|
+
]);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
log.warn(`Dashboard could not start: ${err?.message ?? ''}\n ${dim('Dashboard has been disabled for this session.')}`);
|
|
136
|
+
if (err?.stack)
|
|
137
|
+
console.error(err.stack);
|
|
138
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helper functions for dashboard setup and configuration.
|
|
3
|
+
*/
|
|
4
|
+
import type { DevToolbarConfig } from '../debug/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Classify a dashboard start() error into a category.
|
|
7
|
+
*/
|
|
8
|
+
export declare function classifyDashboardError(err: unknown): 'missing-dep' | 'timeout' | 'unknown';
|
|
9
|
+
/**
|
|
10
|
+
* Race a promise against a timeout.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createStartTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Build the list of URL prefixes to exclude from tracing.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildExcludedPrefixes(toolbarConfig: {
|
|
17
|
+
debugEndpoint?: string;
|
|
18
|
+
excludeFromTracing?: string[];
|
|
19
|
+
}, statsEndpoint: string | false): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Resolve a partial DevToolbarConfig by filling in all defaults.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveToolbarConfig(partial: Partial<DevToolbarConfig> & {
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
}): DevToolbarConfig;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helper functions for dashboard setup and configuration.
|
|
3
|
+
*/
|
|
4
|
+
const MISSING_DEP_MARKERS = ['better-sqlite3', 'knex', 'Cannot find module', 'Cannot find package'];
|
|
5
|
+
const MISSING_DEP_CODES = new Set(['ERR_MODULE_NOT_FOUND', 'MODULE_NOT_FOUND']);
|
|
6
|
+
function isMissingDependencyError(msg, code) {
|
|
7
|
+
if (MISSING_DEP_CODES.has(code))
|
|
8
|
+
return true;
|
|
9
|
+
return MISSING_DEP_MARKERS.some((marker) => msg.includes(marker));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Classify a dashboard start() error into a category.
|
|
13
|
+
*/
|
|
14
|
+
export function classifyDashboardError(err) {
|
|
15
|
+
if (!err)
|
|
16
|
+
return 'unknown';
|
|
17
|
+
const errObj = err;
|
|
18
|
+
const msg = typeof errObj.message === 'string' ? errObj.message : '';
|
|
19
|
+
const code = typeof errObj.code === 'string' ? errObj.code : '';
|
|
20
|
+
if (isMissingDependencyError(msg, code))
|
|
21
|
+
return 'missing-dep';
|
|
22
|
+
if (msg.includes('timed out'))
|
|
23
|
+
return 'timeout';
|
|
24
|
+
return 'unknown';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Race a promise against a timeout.
|
|
28
|
+
*/
|
|
29
|
+
export function createStartTimeout(promise, timeoutMs) {
|
|
30
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
31
|
+
setTimeout(() => reject(new Error(`Dashboard SQLite initialization timed out after ${timeoutMs / 1000}s`)), timeoutMs);
|
|
32
|
+
});
|
|
33
|
+
return Promise.race([promise, timeoutPromise]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the list of URL prefixes to exclude from tracing.
|
|
37
|
+
*/
|
|
38
|
+
export function buildExcludedPrefixes(toolbarConfig, statsEndpoint) {
|
|
39
|
+
const debugEndpoint = toolbarConfig.debugEndpoint ?? '/admin/api/debug';
|
|
40
|
+
const defaultExcludes = [debugEndpoint, statsEndpoint].filter((p) => typeof p === 'string');
|
|
41
|
+
const prefixes = [...(toolbarConfig.excludeFromTracing ?? defaultExcludes)];
|
|
42
|
+
if (typeof statsEndpoint === 'string' && !prefixes.includes(statsEndpoint)) {
|
|
43
|
+
prefixes.push(statsEndpoint);
|
|
44
|
+
}
|
|
45
|
+
return prefixes;
|
|
46
|
+
}
|
|
47
|
+
const TOOLBAR_DEFAULTS = {
|
|
48
|
+
maxQueries: 500,
|
|
49
|
+
maxEvents: 200,
|
|
50
|
+
maxEmails: 100,
|
|
51
|
+
slowQueryThresholdMs: 100,
|
|
52
|
+
persistDebugData: false,
|
|
53
|
+
tracing: true,
|
|
54
|
+
maxTraces: 200,
|
|
55
|
+
dashboard: false,
|
|
56
|
+
dashboardPath: '/__stats',
|
|
57
|
+
retentionDays: 7,
|
|
58
|
+
dbPath: '.adonisjs/server-stats/dashboard.sqlite3',
|
|
59
|
+
debugEndpoint: '/admin/api/debug',
|
|
60
|
+
};
|
|
61
|
+
function stripUndefined(obj) {
|
|
62
|
+
const result = {};
|
|
63
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
64
|
+
if (value !== undefined)
|
|
65
|
+
result[key] = value;
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a partial DevToolbarConfig by filling in all defaults.
|
|
71
|
+
*/
|
|
72
|
+
export function resolveToolbarConfig(partial) {
|
|
73
|
+
return {
|
|
74
|
+
...TOOLBAR_DEFAULTS,
|
|
75
|
+
...stripUndefined(partial),
|
|
76
|
+
enabled: partial.enabled,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure function to build the diagnostics object for the Internals endpoint.
|
|
3
|
+
* Extracted from ServerStatsProvider to reduce complexity.
|
|
4
|
+
*/
|
|
5
|
+
/** Minimal collector shape for diagnostics. */
|
|
6
|
+
interface CollectorRef {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
/** Input data for building diagnostics. */
|
|
10
|
+
export interface DiagnosticsInput {
|
|
11
|
+
intervalId: ReturnType<typeof setInterval> | null;
|
|
12
|
+
dashboardBroadcastTimer: ReturnType<typeof setInterval> | null;
|
|
13
|
+
debugBroadcastTimer: ReturnType<typeof setTimeout> | null;
|
|
14
|
+
flushTimer: ReturnType<typeof setInterval> | null;
|
|
15
|
+
dashboardStoreReady: boolean;
|
|
16
|
+
transmitAvailable: boolean;
|
|
17
|
+
transmitChannels: string[];
|
|
18
|
+
prometheusActive: boolean;
|
|
19
|
+
pinoHookActive: boolean;
|
|
20
|
+
edgePluginActive: boolean;
|
|
21
|
+
emailBridgeActive: boolean;
|
|
22
|
+
hasCacheCollector?: boolean;
|
|
23
|
+
hasQueueCollector?: boolean;
|
|
24
|
+
resolvedCollectors?: CollectorRef[];
|
|
25
|
+
config: DiagnosticsConfig | null;
|
|
26
|
+
}
|
|
27
|
+
interface DiagnosticsConfig {
|
|
28
|
+
intervalMs: number;
|
|
29
|
+
transport: string;
|
|
30
|
+
channelName: string;
|
|
31
|
+
endpoint: string | false;
|
|
32
|
+
skipInTest: boolean;
|
|
33
|
+
onStats?: unknown;
|
|
34
|
+
shouldShow?: unknown;
|
|
35
|
+
devToolbar?: DiagnosticsToolbar;
|
|
36
|
+
}
|
|
37
|
+
interface DiagnosticsToolbar {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
maxQueries?: number;
|
|
40
|
+
maxEvents?: number;
|
|
41
|
+
maxEmails?: number;
|
|
42
|
+
maxTraces?: number;
|
|
43
|
+
slowQueryThresholdMs?: number;
|
|
44
|
+
tracing?: boolean;
|
|
45
|
+
dashboard?: boolean;
|
|
46
|
+
dashboardPath?: string;
|
|
47
|
+
retentionDays?: number;
|
|
48
|
+
dbPath?: string;
|
|
49
|
+
persistDebugData?: boolean | string;
|
|
50
|
+
debugEndpoint?: string;
|
|
51
|
+
renderer?: string;
|
|
52
|
+
excludeFromTracing?: string[];
|
|
53
|
+
panes?: unknown[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Build the full diagnostics object from provider state.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildDiagnostics(input: DiagnosticsInput): {
|
|
59
|
+
timers: {
|
|
60
|
+
collectionInterval: {
|
|
61
|
+
active: boolean;
|
|
62
|
+
intervalMs: number;
|
|
63
|
+
};
|
|
64
|
+
dashboardBroadcast: {
|
|
65
|
+
active: boolean;
|
|
66
|
+
intervalMs: number;
|
|
67
|
+
};
|
|
68
|
+
debugBroadcast: {
|
|
69
|
+
active: boolean;
|
|
70
|
+
debounceMs: number;
|
|
71
|
+
};
|
|
72
|
+
persistFlush: {
|
|
73
|
+
active: boolean;
|
|
74
|
+
intervalMs: number;
|
|
75
|
+
};
|
|
76
|
+
retentionCleanup: {
|
|
77
|
+
active: boolean;
|
|
78
|
+
intervalMs: number;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
transmit: {
|
|
82
|
+
available: boolean;
|
|
83
|
+
channels: string[];
|
|
84
|
+
};
|
|
85
|
+
integrations: {
|
|
86
|
+
prometheus: {
|
|
87
|
+
active: boolean;
|
|
88
|
+
};
|
|
89
|
+
pinoHook: {
|
|
90
|
+
active: boolean;
|
|
91
|
+
mode: string;
|
|
92
|
+
};
|
|
93
|
+
edgePlugin: {
|
|
94
|
+
active: boolean;
|
|
95
|
+
};
|
|
96
|
+
emailBridge: {
|
|
97
|
+
active: boolean;
|
|
98
|
+
};
|
|
99
|
+
cacheInspector: {
|
|
100
|
+
available: boolean;
|
|
101
|
+
};
|
|
102
|
+
queueInspector: {
|
|
103
|
+
available: boolean;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
config: {
|
|
107
|
+
intervalMs: number;
|
|
108
|
+
transport: string;
|
|
109
|
+
channelName: string;
|
|
110
|
+
endpoint: string | false;
|
|
111
|
+
skipInTest: boolean;
|
|
112
|
+
hasOnStatsCallback: boolean;
|
|
113
|
+
hasShouldShowCallback: boolean;
|
|
114
|
+
};
|
|
115
|
+
devToolbar: {
|
|
116
|
+
tracing: boolean;
|
|
117
|
+
dashboard: boolean;
|
|
118
|
+
retentionDays: number;
|
|
119
|
+
persistDebugData: string | boolean;
|
|
120
|
+
renderer: string;
|
|
121
|
+
excludeFromTracing: string[];
|
|
122
|
+
customPaneCount: number;
|
|
123
|
+
dashboardPath: string;
|
|
124
|
+
debugEndpoint: string;
|
|
125
|
+
dbPath: string;
|
|
126
|
+
maxQueries: number;
|
|
127
|
+
maxEvents: number;
|
|
128
|
+
maxEmails: number;
|
|
129
|
+
maxTraces: number;
|
|
130
|
+
slowQueryThresholdMs: number;
|
|
131
|
+
enabled: boolean;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure function to build the diagnostics object for the Internals endpoint.
|
|
3
|
+
* Extracted from ServerStatsProvider to reduce complexity.
|
|
4
|
+
*/
|
|
5
|
+
function buildTimersDiagnostics(input) {
|
|
6
|
+
return {
|
|
7
|
+
collectionInterval: {
|
|
8
|
+
active: input.intervalId !== null,
|
|
9
|
+
intervalMs: input.config?.intervalMs ?? 0,
|
|
10
|
+
},
|
|
11
|
+
dashboardBroadcast: {
|
|
12
|
+
active: input.dashboardBroadcastTimer !== null,
|
|
13
|
+
intervalMs: 30_000,
|
|
14
|
+
},
|
|
15
|
+
debugBroadcast: {
|
|
16
|
+
active: input.debugBroadcastTimer !== null,
|
|
17
|
+
debounceMs: 200,
|
|
18
|
+
},
|
|
19
|
+
persistFlush: {
|
|
20
|
+
active: input.flushTimer !== null,
|
|
21
|
+
intervalMs: 30_000,
|
|
22
|
+
},
|
|
23
|
+
retentionCleanup: {
|
|
24
|
+
active: input.dashboardStoreReady,
|
|
25
|
+
intervalMs: 60 * 60 * 1000,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function buildIntegrationsDiagnostics(input) {
|
|
30
|
+
const collectors = input.resolvedCollectors ?? [];
|
|
31
|
+
const hasCache = input.hasCacheCollector ?? collectors.some((c) => c.name === 'redis');
|
|
32
|
+
const hasQueue = input.hasQueueCollector ?? collectors.some((c) => c.name === 'queue');
|
|
33
|
+
return {
|
|
34
|
+
prometheus: { active: input.prometheusActive },
|
|
35
|
+
pinoHook: {
|
|
36
|
+
active: input.pinoHookActive,
|
|
37
|
+
mode: input.pinoHookActive ? 'stream' : 'none',
|
|
38
|
+
},
|
|
39
|
+
edgePlugin: { active: input.edgePluginActive },
|
|
40
|
+
emailBridge: { active: input.emailBridgeActive },
|
|
41
|
+
cacheInspector: { available: hasCache },
|
|
42
|
+
queueInspector: { available: hasQueue },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function buildConfigDiagnostics(config) {
|
|
46
|
+
if (!config) {
|
|
47
|
+
return {
|
|
48
|
+
intervalMs: 0,
|
|
49
|
+
transport: 'none',
|
|
50
|
+
channelName: '',
|
|
51
|
+
endpoint: false,
|
|
52
|
+
skipInTest: true,
|
|
53
|
+
hasOnStatsCallback: false,
|
|
54
|
+
hasShouldShowCallback: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
intervalMs: config.intervalMs,
|
|
59
|
+
transport: config.transport,
|
|
60
|
+
channelName: config.channelName,
|
|
61
|
+
endpoint: config.endpoint,
|
|
62
|
+
skipInTest: config.skipInTest !== false,
|
|
63
|
+
hasOnStatsCallback: typeof config.onStats === 'function',
|
|
64
|
+
hasShouldShowCallback: typeof config.shouldShow === 'function',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function pickToolbarLimits(tb) {
|
|
68
|
+
return {
|
|
69
|
+
maxQueries: tb.maxQueries ?? 500,
|
|
70
|
+
maxEvents: tb.maxEvents ?? 200,
|
|
71
|
+
maxEmails: tb.maxEmails ?? 100,
|
|
72
|
+
maxTraces: tb.maxTraces ?? 200,
|
|
73
|
+
slowQueryThresholdMs: tb.slowQueryThresholdMs ?? 100,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function pickToolbarPaths(tb) {
|
|
77
|
+
return {
|
|
78
|
+
dashboardPath: tb.dashboardPath ?? '/__stats',
|
|
79
|
+
debugEndpoint: tb.debugEndpoint ?? '/admin/api/debug',
|
|
80
|
+
dbPath: tb.dbPath ?? '.adonisjs/server-stats/dashboard.sqlite3',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function pickToolbarFeatures(tb) {
|
|
84
|
+
return {
|
|
85
|
+
tracing: tb.tracing ?? true,
|
|
86
|
+
dashboard: tb.dashboard ?? false,
|
|
87
|
+
retentionDays: tb.retentionDays ?? 7,
|
|
88
|
+
persistDebugData: tb.persistDebugData ?? false,
|
|
89
|
+
renderer: tb.renderer ?? 'preact',
|
|
90
|
+
excludeFromTracing: tb.excludeFromTracing ?? [],
|
|
91
|
+
customPaneCount: tb.panes?.length ?? 0,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function defaultToolbarDiagnostics() {
|
|
95
|
+
return {
|
|
96
|
+
enabled: false,
|
|
97
|
+
...pickToolbarLimits({}),
|
|
98
|
+
...pickToolbarPaths({}),
|
|
99
|
+
...pickToolbarFeatures({}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function buildDevToolbarDiagnostics(config) {
|
|
103
|
+
const tb = config?.devToolbar;
|
|
104
|
+
if (!tb)
|
|
105
|
+
return defaultToolbarDiagnostics();
|
|
106
|
+
return {
|
|
107
|
+
enabled: !!tb.enabled,
|
|
108
|
+
...pickToolbarLimits(tb),
|
|
109
|
+
...pickToolbarPaths(tb),
|
|
110
|
+
...pickToolbarFeatures(tb),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build the full diagnostics object from provider state.
|
|
115
|
+
*/
|
|
116
|
+
export function buildDiagnostics(input) {
|
|
117
|
+
return {
|
|
118
|
+
timers: buildTimersDiagnostics(input),
|
|
119
|
+
transmit: {
|
|
120
|
+
available: input.transmitAvailable,
|
|
121
|
+
channels: input.transmitChannels,
|
|
122
|
+
},
|
|
123
|
+
integrations: buildIntegrationsDiagnostics(input),
|
|
124
|
+
config: buildConfigDiagnostics(input.config),
|
|
125
|
+
devToolbar: buildDevToolbarDiagnostics(input.config),
|
|
126
|
+
};
|
|
127
|
+
}
|