Skip to content

Commit 07be570

Browse files
committed
update vitest assertions and prettier formatting for avg_response_time ms conversion
Signed-off-by: Shoumi <shoumimukherjee@gmail.com>
1 parent ddf6b1a commit 07be570

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

mcpgateway/static/admin.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,12 +2842,16 @@ function createTopPerformersTable(entityType, data, isActive) {
28422842
);
28432843
row.appendChild(execCell);
28442844

2845-
// Avg Response Time (API returns seconds; convert to ms for display)
2845+
// Avg Response Time
28462846
const avgTimeCell = document.createElement("td");
28472847
avgTimeCell.className =
28482848
"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-300 sm:px-6 sm:py-4";
28492849
const avgTime = item.avg_response_time ?? item.avgResponseTime;
2850-
avgTimeCell.textContent = avgTime != null ? `${Math.round(Number(avgTime) * 1000)}ms` : "N/A";
2850+
if (avgTime != null) {
2851+
avgTimeCell.textContent = `${Math.round(Number(avgTime) * 1000)}ms`;
2852+
} else {
2853+
avgTimeCell.textContent = "N/A";
2854+
}
28512855
row.appendChild(avgTimeCell);
28522856

28532857
// Success Rate
@@ -3192,12 +3196,16 @@ function updateTableRows(tbody, entityType, data, page, perPage) {
31923196
);
31933197
row.appendChild(execCell);
31943198

3195-
// Avg Response Time (API returns seconds; convert to ms for display)
3199+
// Avg Response Time
31963200
const avgTimeCell = document.createElement("td");
31973201
avgTimeCell.className =
31983202
"px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-300 sm:px-6 sm:py-4";
31993203
const avgTime = item.avg_response_time ?? item.avgResponseTime;
3200-
avgTimeCell.textContent = avgTime != null ? `${Math.round(Number(avgTime) * 1000)}ms` : "N/A";
3204+
if (avgTime != null) {
3205+
avgTimeCell.textContent = `${Math.round(Number(avgTime) * 1000)}ms`;
3206+
} else {
3207+
avgTimeCell.textContent = "N/A";
3208+
}
32013209
row.appendChild(avgTimeCell);
32023210

32033211
// Success Rate
@@ -3250,6 +3258,12 @@ function exportMetricsToCSV(topData) {
32503258
["tools", "resources", "prompts", "gateways", "servers"].forEach((type) => {
32513259
if (topData[type] && Array.isArray(topData[type])) {
32523260
topData[type].forEach((item, index) => {
3261+
const avgRespRaw =
3262+
item.avg_response_time ?? item.avgResponseTime;
3263+
const avgRespDisplay =
3264+
avgRespRaw != null
3265+
? `${Math.round(Number(avgRespRaw) * 1000)}ms`
3266+
: "N/A";
32533267
rows.push([
32543268
type,
32553269
index + 1,
@@ -3260,9 +3274,7 @@ function exportMetricsToCSV(topData) {
32603274
item.executions ||
32613275
0,
32623276
),
3263-
item.avg_response_time ?? item.avgResponseTime
3264-
? `${Math.round((item.avg_response_time ?? item.avgResponseTime) * 1000)}ms`
3265-
: "N/A",
3277+
avgRespDisplay,
32663278
`${calculateSuccessRate(item)}%`,
32673279
formatLastUsed(item.last_execution || item.lastExecution),
32683280
]);
@@ -3482,20 +3494,16 @@ function createMetricsCard(title, metrics) {
34823494

34833495
const valueSpan = document.createElement("span");
34843496
valueSpan.className = "font-medium dark:text-gray-200";
3485-
let displayValue;
3486-
if (value === "N/A") {
3487-
displayValue = "N/A";
3488-
} else if (metric.key === "avgResponseTime") {
3489-
const ms = Number(value);
3490-
displayValue = isNaN(ms) ? "N/A" : `${(ms * 1000).toFixed(1)} ms`;
3491-
} else if (metric.key === "lastExecutionTime") {
3492-
displayValue = typeof value === "string" && value.includes("T")
3493-
? value.slice(0, 16).replace("T", " ")
3494-
: String(value);
3497+
if (metric.key === "avgResponseTime" && value !== "N/A") {
3498+
valueSpan.textContent = `${(Number(value) * 1000).toFixed(1)}ms`;
3499+
} else if (metric.key === "lastExecutionTime" && value !== "N/A") {
3500+
valueSpan.textContent =
3501+
typeof value === "string"
3502+
? value.slice(0, 16).replace("T", " ")
3503+
: String(value);
34953504
} else {
3496-
displayValue = String(value);
3505+
valueSpan.textContent = value === "N/A" ? "N/A" : String(value);
34973506
}
3498-
valueSpan.textContent = displayValue;
34993507

35003508
metricRow.appendChild(label);
35013509
metricRow.appendChild(valueSpan);

tests/js/admin-parsing.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("extractKPIData", () => {
296296
expect(result.totalExecutions).toBe(100);
297297
expect(result.successRate).toBe(90);
298298
expect(result.errorRate).toBe(10);
299-
expect(result.avgResponseTime).toBeCloseTo(1.5, 1);
299+
expect(result.avgResponseTime).toBeCloseTo(1500, 1);
300300
});
301301

302302
test("aggregates across multiple categories", () => {
@@ -386,8 +386,8 @@ describe("extractKPIData", () => {
386386
},
387387
};
388388
const result = f()(data);
389-
// Weighted avg = (100*2.0 + 100*4.0) / 200 = 3.0
390-
expect(result.avgResponseTime).toBeCloseTo(3.0, 1);
389+
// Weighted avg = (100*2.0 + 100*4.0) / 200 = 3.0s = 3000ms
390+
expect(result.avgResponseTime).toBeCloseTo(3000, 1);
391391
});
392392

393393
test("ignores N/A response time values", () => {

0 commit comments

Comments
 (0)