@jacebenson/jsn 4.3.7-dev.12 → 4.3.7
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 +0 -6
- package/src/commands/transactions.js +0 -78
package/package.json
CHANGED
package/src/commands/perf.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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';
|
|
4
3
|
import { paginatedSearch } from '../paginated-search.js';
|
|
5
4
|
|
|
6
5
|
function pickerEnabled(app) {
|
|
@@ -108,11 +107,6 @@ export function perfCmd(wrap) {
|
|
|
108
107
|
});
|
|
109
108
|
}),
|
|
110
109
|
})
|
|
111
|
-
.command({
|
|
112
|
-
command: 'transactions [subcommand]',
|
|
113
|
-
describe: 'Inspect Client Transaction Timings',
|
|
114
|
-
builder: (b) => b.command(topTransactionsCmd(wrap)),
|
|
115
|
-
})
|
|
116
110
|
.command({
|
|
117
111
|
command: 'compare [baseline] [new]',
|
|
118
112
|
describe: 'Compare exactly two saved captures',
|
|
@@ -39,7 +39,6 @@ export function classifyTransactionType(type, url = '') {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function numericValue(value) {
|
|
42
|
-
if (value == null || String(value).trim() === '') return null;
|
|
43
42
|
const n = Number(String(value ?? '').replaceAll(',', ''));
|
|
44
43
|
return Number.isFinite(n) ? n : null;
|
|
45
44
|
}
|
|
@@ -66,83 +65,6 @@ function summarizeGroup(group) {
|
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
67
|
|
|
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
|
-
|
|
146
68
|
export function transactionsCmd(wrap) {
|
|
147
69
|
return {
|
|
148
70
|
command: 'transactions',
|