@jacebenson/jsn 4.3.6-dev.11 → 4.3.7-dev.12
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/package.json +1 -1
- package/src/commands/perf.js +6 -0
- package/src/commands/transactions.js +78 -0
package/package.json
CHANGED
package/src/commands/perf.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { errUsageHint, errUsage } from '../errors.js';
|
|
2
2
|
import { captureRun, listRuns, getRun, compareRuns, formatRunDetailed, formatRunList, formatComparisonDetailed } from '../perf.js';
|
|
3
|
+
import { topTransactionsCmd } from './transactions.js';
|
|
3
4
|
import { paginatedSearch } from '../paginated-search.js';
|
|
4
5
|
|
|
5
6
|
function pickerEnabled(app) {
|
|
@@ -107,6 +108,11 @@ export function perfCmd(wrap) {
|
|
|
107
108
|
});
|
|
108
109
|
}),
|
|
109
110
|
})
|
|
111
|
+
.command({
|
|
112
|
+
command: 'transactions [subcommand]',
|
|
113
|
+
describe: 'Inspect Client Transaction Timings',
|
|
114
|
+
builder: (b) => b.command(topTransactionsCmd(wrap)),
|
|
115
|
+
})
|
|
110
116
|
.command({
|
|
111
117
|
command: 'compare [baseline] [new]',
|
|
112
118
|
describe: 'Compare exactly two saved captures',
|
|
@@ -39,6 +39,7 @@ export function classifyTransactionType(type, url = '') {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function numericValue(value) {
|
|
42
|
+
if (value == null || String(value).trim() === '') return null;
|
|
42
43
|
const n = Number(String(value ?? '').replaceAll(',', ''));
|
|
43
44
|
return Number.isFinite(n) ? n : null;
|
|
44
45
|
}
|
|
@@ -65,6 +66,83 @@ function summarizeGroup(group) {
|
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
function topQuery(argv = {}) {
|
|
70
|
+
const parts = [];
|
|
71
|
+
if (argv.query) parts.push(String(argv.query));
|
|
72
|
+
for (const field of ['type', 'table', 'view']) if (argv[field]) parts.push(`${field}=${argv[field]}`);
|
|
73
|
+
if (argv.window != null && String(argv.window) !== '') {
|
|
74
|
+
const days = Math.max(1, Math.min(30, Number(argv.window) || 1));
|
|
75
|
+
parts.push(`sys_created_on>=javascript:gs.daysAgoStart(${days})`);
|
|
76
|
+
}
|
|
77
|
+
if (argv.since) parts.push(`sys_created_on>=${argv.since}`);
|
|
78
|
+
if (argv.until) parts.push(`sys_created_on<=${argv.until}`);
|
|
79
|
+
return normalizeTransactionQuery(parts.join('^'));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function topGroup(group) {
|
|
83
|
+
const stats = group?.stats || {};
|
|
84
|
+
return {
|
|
85
|
+
type: groupValue(group, 'type') || 'unavailable',
|
|
86
|
+
table: groupValue(group, 'table') || 'unavailable',
|
|
87
|
+
view: groupValue(group, 'view') || 'unavailable',
|
|
88
|
+
count: numericValue(stats.count) ?? 0,
|
|
89
|
+
avg_response_time_ms: metricValue(stats, 'avg', 'response_time'),
|
|
90
|
+
min_response_time_ms: metricValue(stats, 'min', 'response_time'),
|
|
91
|
+
max_response_time_ms: metricValue(stats, 'max', 'response_time'),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function formatTopTransactions(groups) {
|
|
96
|
+
const value = metric => metric == null ? 'unavailable' : `${Math.round(metric * 100) / 100} ms`;
|
|
97
|
+
const lines = [
|
|
98
|
+
'TYPE TABLE VIEW COUNT AVG MIN MAX',
|
|
99
|
+
'----------- ----------------- --------------- ----- ----------- ----------- -----------',
|
|
100
|
+
];
|
|
101
|
+
for (const row of groups) lines.push(`${String(row.type).slice(0, 11).padEnd(11)} ${String(row.table).slice(0, 17).padEnd(17)} ${String(row.view).slice(0, 15).padEnd(15)} ${String(row.count).padStart(5)} ${value(row.avg_response_time_ms).padEnd(11)} ${value(row.min_response_time_ms).padEnd(11)} ${value(row.max_response_time_ms)}`);
|
|
102
|
+
if (groups.length === 0) lines.push('(no transaction groups)');
|
|
103
|
+
return `${lines.join('\\n')}\\n`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function topTransactionsCmd(wrap) {
|
|
107
|
+
return {
|
|
108
|
+
command: 'top',
|
|
109
|
+
describe: 'Rank Client Transaction Timings by type, table, and view',
|
|
110
|
+
builder: (y) => y
|
|
111
|
+
.option('type', { type: 'string', describe: 'Filter transaction type' })
|
|
112
|
+
.option('table', { type: 'string', describe: 'Filter transaction table' })
|
|
113
|
+
.option('view', { type: 'string', describe: 'Filter transaction view' })
|
|
114
|
+
.option('query', { type: 'string', describe: 'Additional encoded query' })
|
|
115
|
+
.option('window', { type: 'number', default: 1, describe: 'Look back this many days (max 30)' })
|
|
116
|
+
.option('since', { type: 'string', describe: 'Only records on or after this timestamp' })
|
|
117
|
+
.option('until', { type: 'string', describe: 'Only records on or before this timestamp' })
|
|
118
|
+
.option('limit', { alias: 'l', type: 'number', default: 20, describe: 'Maximum groups to return' }),
|
|
119
|
+
handler: wrap(async (argv, app) => {
|
|
120
|
+
app.requireInstance();
|
|
121
|
+
const query = topQuery(argv);
|
|
122
|
+
const limit = Math.max(1, Math.min(100, Number(argv.limit) || 20));
|
|
123
|
+
const result = await app.sdk.aggregate('syslog_transaction', {
|
|
124
|
+
query,
|
|
125
|
+
groupBy: ['type', 'table', 'view'],
|
|
126
|
+
count: true,
|
|
127
|
+
averageFields: ['response_time'],
|
|
128
|
+
minimumFields: ['response_time'],
|
|
129
|
+
maximumFields: ['response_time'],
|
|
130
|
+
orderBy: 'countDESC',
|
|
131
|
+
});
|
|
132
|
+
const groups = (Array.isArray(result.groups) ? result.groups : []).map(topGroup).slice(0, limit);
|
|
133
|
+
app.ok({
|
|
134
|
+
table: 'syslog_transaction',
|
|
135
|
+
query,
|
|
136
|
+
group_by: ['type', 'table', 'view'],
|
|
137
|
+
response_time_unit: 'ms',
|
|
138
|
+
groups,
|
|
139
|
+
_formatted: formatTopTransactions(groups),
|
|
140
|
+
context: { instance_url: app.getEffectiveInstance() },
|
|
141
|
+
}, { summary: `Top transaction groups: ${groups.length}` });
|
|
142
|
+
}),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
68
146
|
export function transactionsCmd(wrap) {
|
|
69
147
|
return {
|
|
70
148
|
command: 'transactions',
|