2042 bugsysmon metrics not available from sysmon vm collection (#2045) #2498

Merged
mfreeman451 merged 1 commit from refs/pull/2498/head into bug/sysmon-vm_svc_not_starting 2025-12-03 04:11:03 +00:00
mfreeman451 commented 2025-12-03 04:10:29 +00:00 (Migrated from github.com)
Owner

Imported from GitHub pull request.

Original GitHub pull request: #2046
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/2046
Original created: 2025-12-03T04:10:29Z
Original updated: 2025-12-03T04:11:17Z
Original head: carverauto/serviceradar:main
Original base: bug/sysmon-vm_svc_not_starting
Original merged: 2025-12-03T04:11:03Z by @mfreeman451

User description

  • fix(sysmon): gate sysmonvm to darwin-only and fix metrics availability
  • Add target_compatible_with = ["@platforms//os:macos"] to sysmonvm targets to prevent build failures on Linux remote execution
  • Add missing @com_github_shirou_gopsutil_v3//mem dependency
  • Add sysmon stall detection and logging in core metrics processing
  • Add memory metrics support from sysmon-vm collector
  • Improve sysmon metrics flush logging for debugging
  • Update web API routes for device/poller sysmon metrics

🤖 Generated with Claude Code

  • fix(db): properly read batch results to detect insert errors

The sendCNPG function was calling br.Close() without reading individual query results, which silently discarded any errors from INSERT statements. Now properly calls br.Exec() for each queued command to surface errors.

🤖 Generated with Claude Code

  • debug: add logging to cnpgInsertCPUMetrics

  • fixed cpu metrics for sysmon-vm

  • fix(db): use explicit public schema for metrics tables

The Apache AGE extension adds ag_catalog to the search_path, causing INSERT statements to go to ag_catalog.cpu_metrics instead of the intended public.cpu_metrics table. This fixes the issue by explicitly qualifying all metrics table names with the public schema.

Also fixes linter errors:

  • Handle br.Close() error in sendCNPG
  • Replace useless uint64 >= 0 assertions in sysmonvm tests

🤖 Generated with Claude Code

  • fix(api): use explicit public schema in sysmon metric queries

The SELECT queries for device-centric sysmon metrics were using unqualified table names, causing them to read from ag_catalog schema instead of public schema where the data is now being inserted.

This fixes the UI not showing CPU/memory/disk/process metrics.

🤖 Generated with Claude Code


IMPORTANT: Please sign the Developer Certificate of Origin

Thank you for your contribution to ServiceRadar. Please note, when contributing, the developer must include
a DCO sign-off statement indicating the DCO acceptance in one commit message. Here
is an example DCO Signed-off-by line in a commit message:

Signed-off-by: J. Doe <j.doe@domain.com>

Describe your changes

Code checklist before requesting a review

  • I have signed the DCO?
  • The build completes without errors?
  • All tests are passing when running make test?

PR Type

Bug fix


Description

  • Explicitly qualify metrics table names with public schema in SELECT queries

  • Fix UI not showing CPU/memory/disk/process metrics from sysmon collection

  • Resolve Apache AGE extension search_path conflict causing wrong schema reads


File Walkthrough

Relevant files
Bug fix
sysmon.go
Add explicit public schema to metrics table queries           

pkg/core/api/sysmon.go

  • Qualify cpu_metrics table with public schema in getCPUMetricsForDevice
  • Qualify cpu_cluster_metrics table with public schema in
    getCPUMetricsForDevice
  • Qualify memory_metrics table with public schema in
    getMemoryMetricsForDevice
  • Qualify disk_metrics table with public schema in
    getDiskMetricsForDevice
  • Qualify process_metrics table with public schema in
    getProcessMetricsForDevice
+5/-5     

Imported from GitHub pull request. Original GitHub pull request: #2046 Original author: @mfreeman451 Original URL: https://github.com/carverauto/serviceradar/pull/2046 Original created: 2025-12-03T04:10:29Z Original updated: 2025-12-03T04:11:17Z Original head: carverauto/serviceradar:main Original base: bug/sysmon-vm_svc_not_starting Original merged: 2025-12-03T04:11:03Z by @mfreeman451 --- ### **User description** * fix(sysmon): gate sysmonvm to darwin-only and fix metrics availability - Add target_compatible_with = ["@platforms//os:macos"] to sysmonvm targets to prevent build failures on Linux remote execution - Add missing @com_github_shirou_gopsutil_v3//mem dependency - Add sysmon stall detection and logging in core metrics processing - Add memory metrics support from sysmon-vm collector - Improve sysmon metrics flush logging for debugging - Update web API routes for device/poller sysmon metrics 🤖 Generated with [Claude Code](https://claude.com/claude-code) * fix(db): properly read batch results to detect insert errors The sendCNPG function was calling br.Close() without reading individual query results, which silently discarded any errors from INSERT statements. Now properly calls br.Exec() for each queued command to surface errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) * debug: add logging to cnpgInsertCPUMetrics * fixed cpu metrics for sysmon-vm * fix(db): use explicit public schema for metrics tables The Apache AGE extension adds ag_catalog to the search_path, causing INSERT statements to go to ag_catalog.cpu_metrics instead of the intended public.cpu_metrics table. This fixes the issue by explicitly qualifying all metrics table names with the public schema. Also fixes linter errors: - Handle br.Close() error in sendCNPG - Replace useless uint64 >= 0 assertions in sysmonvm tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) * fix(api): use explicit public schema in sysmon metric queries The SELECT queries for device-centric sysmon metrics were using unqualified table names, causing them to read from ag_catalog schema instead of public schema where the data is now being inserted. This fixes the UI not showing CPU/memory/disk/process metrics. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- ## IMPORTANT: Please sign the Developer Certificate of Origin Thank you for your contribution to ServiceRadar. Please note, when contributing, the developer must include a [DCO sign-off statement]( https://developercertificate.org/) indicating the DCO acceptance in one commit message. Here is an example DCO Signed-off-by line in a commit message: ``` Signed-off-by: J. Doe <j.doe@domain.com> ``` ## Describe your changes ## Issue ticket number and link ## Code checklist before requesting a review - [ ] I have signed the DCO? - [ ] The build completes without errors? - [ ] All tests are passing when running make test? ___ ### **PR Type** Bug fix ___ ### **Description** - Explicitly qualify metrics table names with public schema in SELECT queries - Fix UI not showing CPU/memory/disk/process metrics from sysmon collection - Resolve Apache AGE extension search_path conflict causing wrong schema reads ___ <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>sysmon.go</strong><dd><code>Add explicit public schema to metrics table queries</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> pkg/core/api/sysmon.go <ul><li>Qualify <code>cpu_metrics</code> table with <code>public</code> schema in getCPUMetricsForDevice<br> <li> Qualify <code>cpu_cluster_metrics</code> table with <code>public</code> schema in <br>getCPUMetricsForDevice<br> <li> Qualify <code>memory_metrics</code> table with <code>public</code> schema in <br>getMemoryMetricsForDevice<br> <li> Qualify <code>disk_metrics</code> table with <code>public</code> schema in <br>getDiskMetricsForDevice<br> <li> Qualify <code>process_metrics</code> table with <code>public</code> schema in <br>getProcessMetricsForDevice</ul> </details> </td> <td><a href="https://github.com/carverauto/serviceradar/pull/2046/files#diff-4879e8b367ee55413c6cb006f23bb912261df5310c640d3af352033cf97ffc84">+5/-5</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
qodo-code-review[bot] commented 2025-12-03 04:10:47 +00:00 (Migrated from github.com)
Author
Owner

Imported GitHub PR comment.

Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2046#issuecomment-3605011553
Original created: 2025-12-03T04:10:47Z

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Audit logging: The added SQL queries do not include any audit logging of access to potentially sensitive
metrics data, and it is unclear whether higher-level logging captures these reads.

Referred Code
func (s *APIServer) getCPUMetricsForDevice(
	ctx context.Context, _ db.SysmonMetricsProvider, deviceID string, start, end time.Time) (interface{}, error) {
	// Query cpu_metrics table directly for per-core data by device_id
	const cpuQuery = `
		SELECT timestamp, agent_id, host_id, core_id, usage_percent, frequency_hz, label, cluster
		FROM public.cpu_metrics
		WHERE device_id = $1 AND timestamp BETWEEN $2 AND $3
		ORDER BY timestamp DESC, core_id ASC`

	rows, err := s.dbService.(*db.DB).QueryCNPGRows(ctx, cpuQuery, deviceID, start.UTC(), end.UTC())
	if err != nil {
		return nil, fmt.Errorf("failed to query CPU metrics for device %s: %w", deviceID, err)
	}
	defer func() {
		if err := rows.Close(); err != nil {
			slog.Error("failed to close rows", "error", err)
		}
	}()

	data := make(map[time.Time][]models.CPUMetric)
	clusterData := make(map[time.Time][]models.CPUClusterMetric)


 ... (clipped 230 lines)

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status:
Error detail level: Errors wrap internal query operation details and device identifiers which may be
propagated to clients depending on calling context; verify these are not user-facing.

Referred Code
if err := rows.Err(); err != nil {
	return nil, fmt.Errorf("error iterating CPU metrics rows for device %s: %w", deviceID, err)
}

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
- Requires Further Human Verification
🏷️ - Compliance label
Imported GitHub PR comment. Original author: @qodo-code-review[bot] Original URL: https://github.com/carverauto/serviceradar/pull/2046#issuecomment-3605011553 Original created: 2025-12-03T04:10:47Z --- ## PR Compliance Guide 🔍 <!-- https://github.com/carverauto/serviceradar/commit/7b6bf645c465d30b562c07ca3ef572d5df95d60e --> Below is a summary of compliance checks for this PR:<br> <table><tbody><tr><td colspan='2'><strong>Security Compliance</strong></td></tr> <tr><td>🟢</td><td><details><summary><strong>No security concerns identified</strong></summary> No security vulnerabilities detected by AI analysis. Human verification advised for critical code. </details></td></tr> <tr><td colspan='2'><strong>Ticket Compliance</strong></td></tr> <tr><td>⚪</td><td><details><summary>🎫 <strong>No ticket provided </strong></summary> - [ ] Create ticket/issue <!-- /create_ticket --create_ticket=true --> </details></td></tr> <tr><td colspan='2'><strong>Codebase Duplication Compliance</strong></td></tr> <tr><td>⚪</td><td><details><summary><strong>Codebase context is not defined </strong></summary> Follow the <a href='https://qodo-merge-docs.qodo.ai/core-abilities/rag_context_enrichment/'>guide</a> to enable codebase context checks. </details></td></tr> <tr><td colspan='2'><strong>Custom Compliance</strong></td></tr> <tr><td rowspan=4>🟢</td><td> <details><summary><strong>Generic: Meaningful Naming and Self-Documenting Code</strong></summary><br> **Objective:** Ensure all identifiers clearly express their purpose and intent, making code <br>self-documenting<br> **Status:** Passed<br> > Learn more about managing compliance <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#configuration-options'>generic rules</a> or creating your own <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#custom-compliance'>custom rules</a> </details></td></tr> <tr><td> <details><summary><strong>Generic: Robust Error Handling and Edge Case Management</strong></summary><br> **Objective:** Ensure comprehensive error handling that provides meaningful context and graceful <br>degradation<br> **Status:** Passed<br> > Learn more about managing compliance <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#configuration-options'>generic rules</a> or creating your own <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#custom-compliance'>custom rules</a> </details></td></tr> <tr><td> <details><summary><strong>Generic: Secure Logging Practices</strong></summary><br> **Objective:** To ensure logs are useful for debugging and auditing without exposing sensitive <br>information like PII, PHI, or cardholder data.<br> **Status:** Passed<br> > Learn more about managing compliance <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#configuration-options'>generic rules</a> or creating your own <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#custom-compliance'>custom rules</a> </details></td></tr> <tr><td> <details><summary><strong>Generic: Security-First Input Validation and Data Handling</strong></summary><br> **Objective:** Ensure all data inputs are validated, sanitized, and handled securely to prevent <br>vulnerabilities<br> **Status:** Passed<br> > Learn more about managing compliance <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#configuration-options'>generic rules</a> or creating your own <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#custom-compliance'>custom rules</a> </details></td></tr> <tr><td rowspan=2>⚪</td> <td><details> <summary><strong>Generic: Comprehensive Audit Trails</strong></summary><br> **Objective:** To create a detailed and reliable record of critical system actions for security analysis <br>and compliance.<br> **Status:** <br><a href='https://github.com/carverauto/serviceradar/pull/2046/files#diff-4879e8b367ee55413c6cb006f23bb912261df5310c640d3af352033cf97ffc84R392-R642'><strong>Audit logging</strong></a>: The added SQL queries do not include any audit logging of access to potentially sensitive <br>metrics data, and it is unclear whether higher-level logging captures these reads.<br> <details open><summary>Referred Code</summary> ```go func (s *APIServer) getCPUMetricsForDevice( ctx context.Context, _ db.SysmonMetricsProvider, deviceID string, start, end time.Time) (interface{}, error) { // Query cpu_metrics table directly for per-core data by device_id const cpuQuery = ` SELECT timestamp, agent_id, host_id, core_id, usage_percent, frequency_hz, label, cluster FROM public.cpu_metrics WHERE device_id = $1 AND timestamp BETWEEN $2 AND $3 ORDER BY timestamp DESC, core_id ASC` rows, err := s.dbService.(*db.DB).QueryCNPGRows(ctx, cpuQuery, deviceID, start.UTC(), end.UTC()) if err != nil { return nil, fmt.Errorf("failed to query CPU metrics for device %s: %w", deviceID, err) } defer func() { if err := rows.Close(); err != nil { slog.Error("failed to close rows", "error", err) } }() data := make(map[time.Time][]models.CPUMetric) clusterData := make(map[time.Time][]models.CPUClusterMetric) ... (clipped 230 lines) ``` </details> > Learn more about managing compliance <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#configuration-options'>generic rules</a> or creating your own <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#custom-compliance'>custom rules</a> </details></td></tr> <tr><td><details> <summary><strong>Generic: Secure Error Handling</strong></summary><br> **Objective:** To prevent the leakage of sensitive system information through error messages while <br>providing sufficient detail for internal debugging.<br> **Status:** <br><a href='https://github.com/carverauto/serviceradar/pull/2046/files#diff-4879e8b367ee55413c6cb006f23bb912261df5310c640d3af352033cf97ffc84R447-R449'><strong>Error detail level</strong></a>: Errors wrap internal query operation details and device identifiers which may be <br>propagated to clients depending on calling context; verify these are not user-facing.<br> <details open><summary>Referred Code</summary> ```go if err := rows.Err(); err != nil { return nil, fmt.Errorf("error iterating CPU metrics rows for device %s: %w", deviceID, err) } ``` </details> > Learn more about managing compliance <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#configuration-options'>generic rules</a> or creating your own <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/#custom-compliance'>custom rules</a> </details></td></tr> <tr><td align="center" colspan="2"> <!-- placeholder --> <!-- /compliance --update_compliance=true --> </td></tr></tbody></table> <details><summary>Compliance status legend</summary> 🟢 - Fully Compliant<br> 🟡 - Partial Compliant<br> 🔴 - Not Compliant<br> ⚪ - Requires Further Human Verification<br> 🏷️ - Compliance label<br> </details>
qodo-code-review[bot] commented 2025-12-03 04:11:17 +00:00 (Migrated from github.com)
Author
Owner

Imported GitHub PR comment.

Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/2046#issuecomment-3605012370
Original created: 2025-12-03T04:11:17Z

PR Code Suggestions

No code suggestions found for the PR.

Imported GitHub PR comment. Original author: @qodo-code-review[bot] Original URL: https://github.com/carverauto/serviceradar/pull/2046#issuecomment-3605012370 Original created: 2025-12-03T04:11:17Z --- ## PR Code Suggestions ✨ No code suggestions found for the PR.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
carverauto/serviceradar!2498
No description provided.