Skip to content

Comments

feat: implement buildMonitoringResources function and add tests for resource extraction#3761

Open
Darkace01 wants to merge 2 commits intoDokploy:canaryfrom
Darkace01:feat/monitoring-project-filters
Open

feat: implement buildMonitoringResources function and add tests for resource extraction#3761
Darkace01 wants to merge 2 commits intoDokploy:canaryfrom
Darkace01:feat/monitoring-project-filters

Conversation

@Darkace01
Copy link

@Darkace01 Darkace01 commented Feb 20, 2026

What is this PR about?

feat: implement buildMonitoringResources function and add tests for resource extraction

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Issues related (if applicable)

closes #2316

Screenshots (if applicable)

Greptile Summary

This PR adds resource filtering functionality to the monitoring page, allowing users to select specific projects and resources (applications, compose services, databases) to monitor. The implementation includes a new utility function buildMonitoringResources that extracts all monitorable resources from projects and their environments, comprehensive tests, and UI updates with dropdown selectors.

Major changes:

  • New utility function buildMonitoringResources extracts applications, compose services, and all database types (postgres, redis, mysql, mongo, mariadb) into a flat list of monitoring resources
  • Added comprehensive tests covering null/undefined inputs and resource extraction logic
  • Updated monitoring page with project and resource selectors using memoized computations
  • Filters resources by project selection and properly resets resource selection when project changes

Issues found:

  • Critical: WebSocket dependency array missing appType in ContainerFreeMonitoring component will prevent reconnection when resource type changes

Confidence Score: 3/5

  • This PR is mostly safe but contains a critical WebSocket reconnection bug
  • The implementation is well-structured with good tests, but the missing dependency in the WebSocket effect will cause monitoring to display incorrect data when switching between resources of different types (e.g., from application to compose). The logic is sound otherwise.
  • Pay special attention to apps/dokploy/components/dashboard/monitoring/free/container/show-free-container-monitoring.tsx - the WebSocket dependency issue must be fixed before merging

Last reviewed commit: 321d29e

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

Copilot AI review requested due to automatic review settings February 20, 2026 12:23
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 20, 2026

Additional Comments (1)

apps/dokploy/components/dashboard/monitoring/free/container/show-free-container-monitoring.tsx
appType is missing from dependency array - WebSocket won't reconnect when appType changes

	}, [appName, appType]);

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements a utility to derive “monitoring resources” (apps/compose/databases) from the project.all API response and wires it into the monitoring dashboard to let users scope free monitoring to a selected project/resource (issue #2316).

Changes:

  • Added buildMonitoringResources() to flatten projects/environments/services into a single resource list.
  • Updated /dashboard/monitoring (free path) to include Project + Resource selectors and pass appName/appType into ContainerFreeMonitoring.
  • Added Vitest coverage for the new resource extraction utility.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
apps/dokploy/utils/monitoring-resources.ts New resource-extraction helper used by the monitoring UI.
apps/dokploy/pages/dashboard/monitoring.tsx Adds project/resource selection UI and feeds selected resource into free monitoring view.
apps/dokploy/test/monitoring-resources.test.ts Unit tests for resource extraction behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +14
compose: Array<{
composeId: string;
appName?: string;
name: string;
composeType?: string;
}>;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

composeType is typed as a generic string and then cast to MonitoringResource["appType"] later, which defeats type-safety and can allow invalid values to flow into the monitoring UI/WebSocket query params. Type composeType as the real union ("docker-compose" | "stack") and derive appType without a cast (or validate against the allowed set).

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +41
export function buildMonitoringResources(
projects?: ProjectShape[] | null,
): MonitoringResource[] {
if (!projects) return [];
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

buildMonitoringResources defines local ProjectShape / ProjectEnvironment interfaces for the api.project.all response. This is prone to drifting from the actual tRPC output shape. Consider typing the argument as RouterOutputs["project"]["all"] | null | undefined (type-only import) so this utility stays aligned with the API contract.

Copilot uses AI. Check for mistakes.
Comment on lines +130 to +131

export default buildMonitoringResources;
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

This is the only file under apps/dokploy/utils using a default export; the other utils use named exports. Consider dropping the default export and importing buildMonitoringResources by name for consistency across the utils layer.

Suggested change
export default buildMonitoringResources;

Copilot uses AI. Check for mistakes.

const { data: monitoring, isLoading } = api.user.getMetricsToken.useQuery();
const { data: projects } = api.project.all.useQuery(undefined, {
refetchOnWindowFocus: false,
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

api.project.all returns a fairly heavy graph (projects + environments + services). This query currently runs even when toggleMonitoring is true (paid monitoring path), where the data isn't used. Consider adding enabled: !toggleMonitoring (or moving the query into the free-monitoring branch) to avoid unnecessary network/load.

Suggested change
refetchOnWindowFocus: false,
refetchOnWindowFocus: false,
enabled: !toggleMonitoring,

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +60

expect(appResource?.label).toBe("App A");
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The last assertion duplicates an earlier check (appResource?.label is already asserted). Consider removing the redundant expectation to keep the test focused.

Suggested change
expect(appResource?.label).toBe("App A");

Copilot uses AI. Check for mistakes.
- Only fetch projects if paid monitoring is not active.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

monitoring for cpu/mem usage for each of container in table with overview data

1 participant