Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions server/src/db/mongo/modules/monitorModuleQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$cond: [
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Contextual Comment]
This comment refers to code near real line 428. Anchored to nearest_changed(429) line 429.


P1 | Confidence: High

The change replaces a division by 1000 with division by 1 in network metric calculations. While the PR description states the data is already in seconds, this change fundamentally alters the rate calculation from bytes-per-millisecond to bytes-per-second. However, there's a critical inconsistency: the change was applied to only 5 of 6 similar metric calculations (deltaBytesSent, deltaBytesRecv, deltaPacketsSent, deltaPacketsRecv, deltaErrIn), but deltaErrOut remains unchanged. This creates inconsistent units across related metrics, potentially causing misleading visualizations where 5 metrics use bytes/second while deltaErrOut uses bytes/millisecond (1000x larger). The frontend likely expects consistent units across all network metrics.

Code Suggestion:

$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],

{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 | Confidence: High

Division by 1 is a redundant operation that adds cognitive load without value. The expression { $divide: [X, 1] } is equivalent to X. Removing this unnecessary operation would simplify the aggregation pipeline and improve readability without changing behavior.

Suggested change
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
$divide: [{ $subtract: ["$$last", "$$first"] }, { $subtract: ["$$tLast", "$$tFirst"] }]

},
Comment on lines +432 to 433
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Patch-ready diff (revert the five denominators back to seconds)

If updatedAt is a Date (milliseconds), apply this diff to fix all five changed spots:

@@
-        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
+        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
@@
-        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
+        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
@@
-        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
+        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
@@
-        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
+        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
@@
-        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
+        $divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],

Also applies to: 471-472, 510-511, 565-566, 601-602

🤖 Prompt for AI Agents
In server/src/db/mongo/modules/monitorModuleQueries.js around lines 432-433 (and
also update the same pattern at 471-472, 510-511, 565-566, 601-602), the
aggregation is dividing the millisecond timestamp difference by 1 which treats
updatedAt as seconds; change the denominator back to 1000 so the expression
becomes { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] } (apply this
exact replacement at all five locations).

0,
],
Expand Down Expand Up @@ -468,7 +468,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
},
0,
],
Expand Down Expand Up @@ -507,7 +507,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
},
0,
],
Expand Down Expand Up @@ -562,7 +562,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
},
0,
],
Expand Down Expand Up @@ -598,7 +598,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => {
$cond: [
{ $gt: [{ $subtract: ["$$tLast", "$$tFirst"] }, 0] },
{
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1000] }],
$divide: [{ $subtract: ["$$last", "$$first"] }, { $divide: [{ $subtract: ["$$tLast", "$$tFirst"] }, 1] }],
},
0,
],
Expand Down