Skip to content

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

Open
pingxin403 wants to merge 5 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 5 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

  • Bug Fixes
    • Task detail trend charts now consistently render when chart data is available, with placeholders shown only when data is missing.
    • Monitoring metrics for Ascend workloads now use correct device-scoped PromQL queries, with accurate compute/memory handling and safer clearing of chart data on query failures.
  • Tests
    • Expanded automated coverage for Ascend metric generation and conversions, including empty-result scenarios and updated raw-bytes memory semantics.

@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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Prometheus-backed Ascend task compute and memory metrics with conversion tests, and updates task admin trend charts to render from available data while clearing failed requests.

Changes

Ascend NPU metrics

Layer / File(s) Summary
Ascend metric query and conversion implementation
server/internal/exporter/exporter.go
Adds explicit Ascend compute and memory handling, queries Prometheus for utilization and HBM usage, and preserves byte-based memory semantics for downstream conversion.
Ascend metric and conversion tests
server/internal/exporter/exporter_test.go
Adds a fake Prometheus server and tests for query results, empty vectors, raw memory values, and core and memory conversions.

Trend chart rendering simplification

Layer / File(s) Summary
Trend data rendering and failure handling
packages/web/projects/vgpu/views/task/admin/Detail.vue
Renders VChart when trend-row data exists, shows el-empty for empty data, and clears row data when range-vector requests fail.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested labels: enhancement

Poem

I hop where Ascend numbers glow,
Prometheus tells the charts to show,
Empty paths now clear with care,
Bright trend lines bloom everywhere,
🐇✨ Metrics dance through the air.

🚥 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 is concise and accurately summarizes the Ascend exporter fix and chart display changes.
Linked Issues check ✅ Passed The backend changes add Ascend PromQL queries and remove the zero-return paths required by issue #86.
Out of Scope Changes check ✅ Passed The frontend chart and empty-state changes align with the stated objectives 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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/web/projects/vgpu/views/task/admin/Detail.vue

Parsing error: Cannot find module '@vue/babel-plugin-jsx'
Require stack:

  • /node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/lib/config/files/plugins.js
  • /node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/lib/config/files/index.js
  • /node_modules/.pnpm/@babel+core@7.28.5/node_modules/@babel/core/lib/index.js
  • /node_modules/.pnpm/@babel+eslint-parser@7.28.5_@babel+core@7.28.5_eslint@8.56.0/node_modules/@babel/eslint-parser/lib/worker/babel-core.cjs
  • /node_modules/.pnpm/@babel+eslint-parser@7.28.5_@babel+core@7.28.5_eslint@8.56.0/node_modules/@babel/eslint-parser/lib/worker/handle-message.cjs
  • /node_modules/.pnpm/@babel+eslint-parser@7.28.5_@babel+core@7.28.5_eslint@8.56.0/node_modules/@babel/eslint-parser/lib/client.cjs
  • /node_modules/.pnpm/@babel+eslint-parser@7.28.5_@babel+core@7.28.5_eslint@8.56.0/node_modules/@babel/eslint-parser/lib/index.cjs
  • /node_modules/.pnpm/vue-eslint-parser@8.3.0_eslint@8.56.0/node_modules/vue-eslint-parser/index.js
  • /node_modules/.pnpm/eslint-plugin-vue@8.7.1_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/utils/index.js
  • /node_modules/.pnpm/eslint-plugin-vue@8.7.1_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/rules/array-bracket-newline.js
  • /node_modules/.pnpm/eslint-plugin-vue@8.7.1_eslint@8.56.0/node_modules/eslint-plugin-vue/lib/index.js
  • /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs

Make sure that all the Babel plugins and presets you are using
are defined as dependencies or devDependencies in your package.json
file. It's possible that the missing plugin is loaded by a preset
you are using that forgot to add the plugin to its dependencies: you
can workaround this problem by explicitly adding the missing package
to your top-level package.json.


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.

❤️ Share

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>
… 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 <52284317+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
- Fix gofmt indentation error in Ascend/SGPU/Default case labels
- Fix memory unit semantics: npu_chip_info_hbm_used_memory returns bytes,
  not MB; remove incorrect *1000*1000 MB-to-bytes conversion
- Add device-scoped limitation comments for Ascend PromQL queries
  (taskCoreUsed, taskMemoryUsed) noting they return whole-device values
- Add conversion tests: deviceMemUsed, memory bytes→MiB, core util math
- Fix frontend empty-chart regression: guard VChart with data.length > 0,
  show el-empty fallback when no data, add .catch() for API failures

Signed-off-by: Fixer <fixer@users.noreply.github.com>
Signed-off-by: pingxin403 <pingxin403@users.noreply.github.com>
…WebUI into feat/ascend-npu-metrics

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

# Conflicts:
#	server/internal/exporter/exporter.go
#	server/internal/exporter/exporter_test.go
@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 25, 2026

@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 (2)
server/internal/exporter/exporter_test.go (2)

119-167: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

Exercise the production conversion path.

These tests duplicate the formulas from GenerateContainerMetrics locally, so a regression in the Ascend core or memory switch branches would still pass. Drive GenerateContainerMetrics with fake devices/containers and assert the emitted metrics, or extract the shared conversion logic into a helper and test that helper directly.

🤖 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 119 - 167, Update
TestMetricsGenerator_AscendMemoryConversion and
TestMetricsGenerator_AscendCoreConversion to exercise GenerateContainerMetrics
rather than duplicating its conversion formulas locally. Configure fake Ascend
devices and containers, invoke GenerateContainerMetrics, and assert the emitted
memory, core-used, and utilization metrics; alternatively extract the shared
conversion logic into a helper and test that helper directly.

23-38: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the actual PromQL request.

The fake handler ignores the query and returns the configured value for every request, so these tests would pass even if the implementation used the wrong metric or omitted the vdie_id selector. Accept an expected query per test and compare it with the request’s query parameter/body.

🤖 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 23 - 38, Update
testPromHandler to accept an expected PromQL query and assert it against the
request’s query parameter or POST body before returning the configured response.
Update each test using testPromHandler to provide the expected metric query,
including the required vdie_id selector, so incorrect or missing queries fail.
🤖 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 119-167: Update TestMetricsGenerator_AscendMemoryConversion and
TestMetricsGenerator_AscendCoreConversion to exercise GenerateContainerMetrics
rather than duplicating its conversion formulas locally. Configure fake Ascend
devices and containers, invoke GenerateContainerMetrics, and assert the emitted
memory, core-used, and utilization metrics; alternatively extract the shared
conversion logic into a helper and test that helper directly.
- Around line 23-38: Update testPromHandler to accept an expected PromQL query
and assert it against the request’s query parameter or POST body before
returning the configured response. Update each test using testPromHandler to
provide the expected metric query, including the required vdie_id selector, so
incorrect or missing queries fail.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86f8ae8d-9ad2-4202-ac00-3b61b343e747

📥 Commits

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

📒 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
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/projects/vgpu/views/task/admin/Detail.vue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant