Skip to content

fix: enable Ascend NPU container-level metrics in exporter and chart display#111

Open
pingxin403 wants to merge 2 commits into
Project-HAMi:mainfrom
pingxin403:feat/ascend-npu-metrics
Open

fix: enable Ascend NPU container-level metrics in exporter and chart display#111
pingxin403 wants to merge 2 commits into
Project-HAMi:mainfrom
pingxin403:feat/ascend-npu-metrics

Conversation

@pingxin403

@pingxin403 pingxin403 commented Jul 5, 2026

Copy link
Copy Markdown

Description

Fix Ascend NPU container metrics always returning 0 in exporter, and enable monitoring charts for non-NVIDIA/MXC vendors.

Backend changes

  • taskCoreUsed: replace return 0, nil with npu_chip_info_utilization PromQL query
  • taskMemoryUsed: replace return 0, nil with npu_chip_info_hbm_used_memory PromQL query
  • GenerateContainerMetrics: add AscendGPUDevice case for core unit conversion
  • Unit tests for Ascend exporter paths

Frontend changes

  • Remove NVIDIA/MXC type guards in trend-time-filter and chart display
  • All vendors now show monitoring charts (data depends on Prometheus availability)

Closes #86

Summary by CodeRabbit

  • New Features
    • Task detail pages now always render the trend chart when a task type is set.
  • Bug Fixes
    • Improved monitoring metrics for Ascend GPU workloads: compute utilization and memory usage are now queried correctly, with correct handling for empty results and proper unit conversion for memory.
  • Tests
    • Added automated coverage for Ascend metric generation, including empty monitoring response handling.

@hami-robot

hami-robot Bot commented Jul 5, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pingxin403

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot hami-robot Bot added the size/L label Jul 5, 2026
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b46c2924-63ca-4c9b-b564-d1a7a9c58a9f

📥 Commits

Reviewing files that changed from the base of the PR and between 8516305 and 2d2366e.

📒 Files selected for processing (2)
  • server/internal/exporter/exporter.go
  • server/internal/exporter/exporter_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • server/internal/exporter/exporter.go
  • server/internal/exporter/exporter_test.go

📝 Walkthrough

Walkthrough

Adds Ascend task metric queries in the exporter, with tests covering core, memory, and empty-result behavior, and updates the task admin trend chart to render the chart whenever a task type is present.

Changes

Ascend NPU metrics

Layer / File(s) Summary
Ascend metric query implementation
server/internal/exporter/exporter.go
Handles biz.AscendGPUDevice explicitly in GenerateContainerMetrics and replaces Ascend stub returns in taskCoreUsed and taskMemoryUsed with PromQL queries.
Ascend metric tests
server/internal/exporter/exporter_test.go
Adds a fake Prometheus handler, generator setup helper, and tests for Ascend core usage, memory usage, and empty query results.

Trend chart rendering simplification

Layer / File(s) Summary
Always render VChart for present detail type
packages/web/projects/vgpu/views/task/admin/Detail.vue
Removes the el-empty fallback for non-NVIDIA/MXC types so VChart now renders whenever detail.type is truthy.

Estimated code review effort: 2 (Simple) | ~12 minutes

Related Issues: #86

Suggested labels: exporter, ascend, frontend

Suggested reviewers: none identified from the provided context

Poem

I hop where metrics start to bloom,
No more zeros lingering in the room,
Ascend counts now rise and sing,
Charts show truth for every thing,
🐇✨ A tidy PR, a brighter view!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the Ascend metrics exporter fix and chart display change.
Linked Issues check ✅ Passed Ascend container compute and memory paths now run PromQL queries instead of returning zero, matching #86.
Out of Scope Changes check ✅ Passed The frontend chart update and tests are aligned with the stated Ascend metrics fix and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@server/internal/exporter/exporter.go`:
- Around line 566-570: The Ascend GPU branch in GenerateContainerMetrics is
returning HBM usage in MB from npu_chip_info_hbm_used_memory, but the later
memory metrics path still assumes bytes and divides again, so the reported
values are far too small. Update the AscendGPUDevice handling in exporter.go to
convert the queried HBM value from MB to bytes before it is assigned to
taskMemoryUsed and used by HamiContainerMemoryUsed/HamiContainerMemoryUtil,
keeping the behavior consistent with the other device branches.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ae090b7c-497b-4471-b580-29aa33ebadc9

📥 Commits

Reviewing files that changed from the base of the PR and between c59f776 and 51a399e.

📒 Files selected for processing (3)
  • packages/web/projects/vgpu/views/task/admin/Detail.vue
  • server/internal/exporter/exporter.go
  • server/internal/exporter/exporter_test.go

Comment thread server/internal/exporter/exporter.go
…display

Replace hardcoded return 0, nil with real PromQL queries (npu_chip_info_utilization,
npu_chip_info_hbm_used_memory) for Ascend taskCoreUsed/taskMemoryUsed.
Add AscendGPUDevice case to GenerateContainerMetrics switch for core unit conversion.
Remove NVIDIA/MXC type guards in task detail view so all vendors show trend charts.

Closes Project-HAMi#86

Signed-off-by: pingxin403 <pingxin403@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
server/internal/exporter/exporter_test.go (3)

1-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider asserting the outgoing PromQL query in testPromHandler.

The fake handler (per description) only checks HTTP method/path, not the query string sent by the client. Asserting that the request's query parameter matches the expected Ascend PromQL (metric name, vdie_id label) would guard against regressions like a typo in the metric name that would otherwise silently still return a valid-looking response.

🤖 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 `@server/internal/exporter/exporter_test.go` around lines 1 - 38, Update
testPromHandler in exporter_test.go to also verify the outgoing PromQL query,
not just the method and /api/v1/query path. Read the request's query parameter
and assert it matches the expected Ascend query shape used by the exporter,
including the metric name and vdie_id label. Keep the fake response behavior the
same so the existing tests still exercise the client through the exporter code
paths.

90-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a matching empty-result test for taskMemoryUsed.

An empty-result test exists for taskCoreUsed but not for taskMemoryUsed, even though both share the same queryInstantVal empty-vector fallback path. Adding the symmetric case improves coverage consistency.

🤖 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 `@server/internal/exporter/exporter_test.go` around lines 90 - 101, Add a
symmetric empty-result test for taskMemoryUsed in exporter_test.go to match
TestMetricsGenerator_taskCoreUsed_Ascend_EmptyResult. Reuse newTestGenerator and
testPromHandler with an empty response, then call gen.taskMemoryUsed with the
same AscendGPUDevice-style arguments and assert it returns 0 with no error. Keep
the test alongside the existing taskCoreUsed empty-result case so the shared
queryInstantVal fallback path is covered consistently.

1-101: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add an Ascend GenerateContainerMetrics test
server/internal/exporter/exporter_test.go only covers taskCoreUsed/taskMemoryUsed; it doesn’t assert the final HamiContainerMemoryUsed value from GenerateContainerMetrics for biz.AscendGPUDevice. Add a case that feeds MB-sized HBM data and checks the exported MiB value after the *1000*1000/1024/1024 conversion.

🤖 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 `@server/internal/exporter/exporter_test.go` around lines 1 - 101, Add a test
for GenerateContainerMetrics on biz.AscendGPUDevice that verifies the final
HamiContainerMemoryUsed output, not just taskMemoryUsed. Reuse the existing
exporter test setup in MetricsGenerator/newTestGenerator with a fake Prometheus
response that returns MB-sized HBM data, then call GenerateContainerMetrics and
assert the exported memory value reflects the expected MiB conversion from the
underlying *1000*1000 to /1024/1024 path. Use the existing taskMemoryUsed and
GenerateContainerMetrics symbols to locate the relevant code.
🤖 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.

Nitpick comments:
In `@server/internal/exporter/exporter_test.go`:
- Around line 1-38: Update testPromHandler in exporter_test.go to also verify
the outgoing PromQL query, not just the method and /api/v1/query path. Read the
request's query parameter and assert it matches the expected Ascend query shape
used by the exporter, including the metric name and vdie_id label. Keep the fake
response behavior the same so the existing tests still exercise the client
through the exporter code paths.
- Around line 90-101: Add a symmetric empty-result test for taskMemoryUsed in
exporter_test.go to match TestMetricsGenerator_taskCoreUsed_Ascend_EmptyResult.
Reuse newTestGenerator and testPromHandler with an empty response, then call
gen.taskMemoryUsed with the same AscendGPUDevice-style arguments and assert it
returns 0 with no error. Keep the test alongside the existing taskCoreUsed
empty-result case so the shared queryInstantVal fallback path is covered
consistently.
- Around line 1-101: Add a test for GenerateContainerMetrics on
biz.AscendGPUDevice that verifies the final HamiContainerMemoryUsed output, not
just taskMemoryUsed. Reuse the existing exporter test setup in
MetricsGenerator/newTestGenerator with a fake Prometheus response that returns
MB-sized HBM data, then call GenerateContainerMetrics and assert the exported
memory value reflects the expected MiB conversion from the underlying *1000*1000
to /1024/1024 path. Use the existing taskMemoryUsed and GenerateContainerMetrics
symbols to locate the relevant code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 872df6dc-8540-4bbd-9609-09a7529451ef

📥 Commits

Reviewing files that changed from the base of the PR and between ef1240b and 8516305.

📒 Files selected for processing (2)
  • server/internal/exporter/exporter.go
  • server/internal/exporter/exporter_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/internal/exporter/exporter.go

… metrics

npu_chip_info_hbm_used_memory returns MB (megabytes, 10^6 bytes), not bytes.
The downstream /1024/1024 conversion expects bytes input for MiB output.
Fix: multiply by 1000*1000 to convert MB to bytes before the division.

Address CodeRabbit review comment on MB vs byte unit mismatch.
Signed-off-by: pingxin403 <pingxin403@users.noreply.github.com>
@pingxin403 pingxin403 force-pushed the feat/ascend-npu-metrics branch from 8516305 to 2d2366e Compare July 7, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

昇腾 npu 的容器内算力和显存使用率,没有执行查询,而是直接返回0.

1 participant