Add read-only network metrics API#2003
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds GraphQL types and a root query for static network interfaces, implements NetworkMetrics collection (polling + pubsub), exposes metrics in ChangesNetwork Metrics and Interface Exposure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 920977ff70
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @Injectable() | ||
| export class NetworkMetricsService { | ||
| async getNetworkMetrics(): Promise<NetworkMetrics[]> { | ||
| const [stats, interfaces] = await Promise.all([networkStats(), networkInterfaces()]); |
There was a problem hiding this comment.
Return stats for all interfaces
On hosts with more than one interface, networkStats() without an argument only returns the first/default external interface; the systeminformation docs state to pass '*' for all interfaces (https://systeminformation.io/network.html). Since this API is exposed as metrics.network / systemMetricsNetwork for all interfaces and the service already builds speeds for every interface, Unraid interfaces such as br0, bond0, VLANs, or secondary NICs are silently omitted. Use networkStats('*') or pass the collected interface names here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/src/unraid-api/graph/resolvers/info/network/network.service.ts (1)
53-53:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winReplace
aswithsatisfiesfor structural type validation.Lines 53 and 100 use
as InfoNetworkInterfacewhich bypasses TypeScript's type checking. Usesatisfies InfoNetworkInterfaceinstead to enforce structural compatibility while preserving inferred types, providing stricter guardrails and better alignment with the coding guideline to avoid casting.Suggested change
- } as InfoNetworkInterface; + } satisfies InfoNetworkInterface; ... - } as InfoNetworkInterface; + } satisfies InfoNetworkInterface;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/src/unraid-api/graph/resolvers/info/network/network.service.ts` at line 53, Replace the two non-type-safe casts that use "as InfoNetworkInterface" with the TypeScript "satisfies InfoNetworkInterface" operator so the objects are structurally validated while keeping inferred types; update the object expressions that currently end with "as InfoNetworkInterface" (occurrences around the object returned in the network service — the expression at the line shown and the second occurrence near line 100) to use "satisfies InfoNetworkInterface" instead, ensuring your tsconfig/TS version supports the satisfies operator.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/src/unraid-api/graph/resolvers/info/network/network.service.ts`:
- Around line 111-113: The parseIpv6PrefixLength function currently converts
subnet strings via Number(subnet) which treats empty string as 0; update
parseIpv6PrefixLength to first guard against empty or non-numeric subnet (e.g.,
check subnet == null or subnet.trim() === '' or use a /^\d+$/ test) before
calling Number/parseInt, and only return a numeric prefix when the input is a
valid integer in the expected range (0–128); reference function name
parseIpv6PrefixLength and parameter subnet when making this change.
---
Outside diff comments:
In `@api/src/unraid-api/graph/resolvers/info/network/network.service.ts`:
- Line 53: Replace the two non-type-safe casts that use "as
InfoNetworkInterface" with the TypeScript "satisfies InfoNetworkInterface"
operator so the objects are structurally validated while keeping inferred types;
update the object expressions that currently end with "as InfoNetworkInterface"
(occurrences around the object returned in the network service — the expression
at the line shown and the second occurrence near line 100) to use "satisfies
InfoNetworkInterface" instead, ensuring your tsconfig/TS version supports the
satisfies operator.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e3f927f4-c9be-475b-b5d5-8c88456925fe
📒 Files selected for processing (14)
api/generated-schema.graphqlapi/src/unraid-api/graph/resolvers/info/network/network.model.tsapi/src/unraid-api/graph/resolvers/info/network/network.resolver.tsapi/src/unraid-api/graph/resolvers/info/network/network.service.tsapi/src/unraid-api/graph/resolvers/metrics/metrics.model.tsapi/src/unraid-api/graph/resolvers/metrics/metrics.module.tsapi/src/unraid-api/graph/resolvers/metrics/metrics.resolver.integration.spec.tsapi/src/unraid-api/graph/resolvers/metrics/metrics.resolver.spec.tsapi/src/unraid-api/graph/resolvers/metrics/metrics.resolver.tsapi/src/unraid-api/graph/resolvers/metrics/network/network.model.tsapi/src/unraid-api/graph/resolvers/metrics/network/network.service.spec.tsapi/src/unraid-api/graph/resolvers/metrics/network/network.service.tsapi/src/unraid-api/graph/resolvers/metrics/temperature/temperature.resolver.integration.spec.tspackages/unraid-shared/src/pubsub/graphql.pubsub.ts
Summary
Fixes #1602
Testing
Notes
A broader pnpm --dir api test run executed 1,976 passing tests and failed only src/test/core/utils/pm2/unraid-api-running.integration.test.ts, where the PM2 process detection returned false in this local environment.
Summary by CodeRabbit