Skip to content

refactor(metered): align metrics with dotnet/runtime#124140 API-approved spec#173

Merged
rjmurillo merged 6 commits intomainfrom
feat/align-metrics-with-124140
Mar 21, 2026
Merged

refactor(metered): align metrics with dotnet/runtime#124140 API-approved spec#173
rjmurillo merged 6 commits intomainfrom
feat/align-metrics-with-124140

Conversation

@rjmurillo
Copy link
Owner

Summary

Aligns codebase metrics with the dotnet/runtime#124140 API-approved specification for MemoryCache metrics.

Changes

Source (1 file)

Updated MeterName constant to match the API review outcome (bartonjs, 2026-03-03):

  • Before: Microsoft.Extensions.Caching.Memory
  • After: Microsoft.Extensions.Caching.Memory.MemoryCache

All 14 test references use MeteredMemoryCache.MeterName constant, so tests auto-aligned. No test changes required.

Documentation (12 files)

Updated metric name references across all documentation:

Old Name New Name Context
cache_hits_total / cache_misses_total cache.requests with cache.request.type dimension Unified per OTel conventions
CacheImplementations.MeteredMemoryCache Microsoft.Extensions.Caching.Memory.MemoryCache Meter name in AddMeter() examples
cache_evictions_total (in OTel contexts) cache.evictions Dot-separated OTel instrument name

Additional fixes from multi-round review:

  • Removed false reason tag claims on cache.evictions (tag does not exist in implementation)
  • Fixed "three types of metrics" to "four instruments"
  • Replaced invalid ExplicitBucketHistogramConfiguration on ObservableCounter with MetricStreamConfiguration
  • Fixed PromQL queries with by (cache_name) on both sum() calls
  • Added cache_estimated_size to Prometheus sample output
  • Removed trailing whitespace in PromQL blocks

Instruments (unchanged, already aligned)

Instrument Type Tags
cache.requests ObservableCounter cache.name, cache.request.type (hit/miss)
cache.evictions ObservableCounter cache.name
cache.entries ObservableUpDownCounter cache.name
cache.estimated_size ObservableGauge cache.name

Breaking Change

Consumers subscribing to the old meter name via hardcoded string "Microsoft.Extensions.Caching.Memory" will need to update to "Microsoft.Extensions.Caching.Memory.MemoryCache" or use MeteredMemoryCache.MeterName.

Validation

  • dotnet format [PASS]
  • dotnet build -c Release [PASS] (0 warnings)
  • dotnet test -c Release [PASS] (243/243)
  • Code review: 2 rounds, 8 issues found and fixed
  • Code simplification pass: 12 edits across 8 files

References

rjmurillo and others added 2 commits March 11, 2026 11:22
…view

The API review (bartonjs, 2026-03-03) approved the meter name as
Microsoft.Extensions.Caching.Memory.MemoryCache to match the type name.

Updated MeterName constant from 'Microsoft.Extensions.Caching.Memory'
to 'Microsoft.Extensions.Caching.Memory.MemoryCache'.

All test references use MeteredMemoryCache.MeterName constant so they
auto-align with this change.

Ref: dotnet/runtime#124140

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Documentation referenced stale metric names (cache_hits_total,
cache_misses_total) from before the codebase aligned with
dotnet/runtime#124140. Updated all references across 12 files:

- Replaced separate cache_hits_total/cache_misses_total with unified
  cache.requests instrument (cache.request.type dimension)
- Fixed meter name from CacheImplementations.MeteredMemoryCache to
  Microsoft.Extensions.Caching.Memory.MemoryCache
- Updated all PromQL queries to use cache_requests_total with
  cache_request_type label selector
- Updated Prometheus exposition format examples

Files: README.md, docs/ApiReference.md, docs/BestPractices.md,
docs/DocumentationReview.md, docs/FAQ.md, docs/MeteredMemoryCache.md,
docs/MigrationGuide.md, docs/MultiCacheScenarios.md,
docs/OpenTelemetryIntegration.md, docs/Troubleshooting.md,
examples/AspNetCore/docs/README-HTTP-Tests.md,
.github/copilot-instructions.md

Ref: dotnet/runtime#124140

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the metrics emitted by MeteredMemoryCache to fully align with the API-approved specification from dotnet/runtime#124140. The changes standardize metric naming and structure according to OpenTelemetry conventions, enhancing clarity and consistency for consumers. This ensures that the caching metrics are more robust and easier to integrate with modern observability platforms, providing a more accurate and comprehensive view of cache performance.

Highlights

  • Meter Name Update: The MeterName constant was updated from Microsoft.Extensions.Caching.Memory to Microsoft.Extensions.Caching.Memory.MemoryCache to align with the API-approved specification.
  • Metric Renaming and Consolidation: Cache hit and miss metrics (cache_hits_total, cache_misses_total) were consolidated into a single cache.requests ObservableCounter with a cache.request.type dimension (hit/miss), following OpenTelemetry conventions.
  • New Metrics Introduced: Two new metrics, cache.entries (ObservableUpDownCounter for current entry count) and cache.estimated_size (ObservableGauge for cache size when SizeLimit is set), were added.
  • Documentation Alignment: Documentation across 12 files was updated to reflect the new metric names, types, and Prometheus query examples. This includes removing the incorrect reason tag claim for cache.evictions.
  • OpenTelemetry Configuration Updates: OpenTelemetry integration examples were updated, including changing the AddMeter name and replacing ExplicitBucketHistogramConfiguration with MetricStreamConfiguration for cache.requests.
Changelog
  • .github/copilot-instructions.md
    • Updated TestListener and MetricCollectionHarness calls to use the new cache.requests and cache.evictions metric names.
  • README.md
    • Updated the list of exposed instruments, the AddMeter example, and the emitted metrics table to reflect the new OpenTelemetry-aligned names and types.
  • docs/ApiReference.md
    • Updated metric names in TryGetValue, CreateEntry, and Remove descriptions to cache.requests and cache.evictions.
  • docs/BestPractices.md
    • Revised Prometheus queries for hit/miss rate, operations/sec, and eviction rate to use the new cache.requests and cache.evictions metrics with appropriate tags.
  • docs/DocumentationReview.md
    • Updated the section on metric name conventions to reflect the resolved status and standardized OpenTelemetry names.
  • docs/FAQ.md
    • Updated the list of emitted instruments and Prometheus query examples to use the new metric names and structures.
  • docs/MeteredMemoryCache.md
    • Updated the emitted metrics table, clarified eviction tracking (removing the reason tag claim), and modified example code to use cache.requests with cache.request.type.
    • Updated the metric name migration table to reflect the new metric names and types.
  • docs/MigrationGuide.md
    • Updated the list of standard metrics, modified example InstrumentedMemoryCache to use cache.requests, and updated the metric name migration table.
  • docs/MultiCacheScenarios.md
    • Updated Prometheus queries for cache hit rate, top consumers, and eviction rate to align with the new metric naming.
  • docs/OpenTelemetryIntegration.md
    • Updated the Prometheus sample output, changed the AddMeter name, replaced ExplicitBucketHistogramConfiguration with MetricStreamConfiguration for cache.requests, and updated Prometheus alert and query examples.
  • docs/Troubleshooting.md
    • Updated the example MetricsTestHarness to sum cache.requests instead of separate hit/miss counters.
  • examples/AspNetCore/docs/README-HTTP-Tests.md
    • Updated the list of metrics verified by tests to reflect the new cache.requests and cache.evictions.
  • src/CacheImplementations/MeteredMemoryCache.cs
    • Modified the MeterName constant to Microsoft.Extensions.Caching.Memory.MemoryCache.
Activity
  • Two rounds of code review were conducted, leading to 8 issues being identified and fixed.
  • A code simplification pass resulted in 12 edits across 8 files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively refactors the metrics implementation to align with the dotnet/runtime#124140 specification. The changes, including updating the meter name and consolidating cache hit/miss metrics into a single cache.requests instrument, are applied consistently across both the source code and the extensive documentation. The documentation updates are thorough, correctly reflecting the new metric names, types, and tags. I've found one minor inconsistency in a PromQL query within the documentation, for which I've provided a suggestion to improve consistency across the project's guides.

@AguirreMoy
Copy link

LGTM

Copy link

@jmathes jmathes left a comment

Choose a reason for hiding this comment

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

I think the missing test cases are worth adding back in if it's idiomatic to be that rigorous in these things. Otherwise I only have questions which might be comments but I'm not sure.

rjmurillo and others added 2 commits March 13, 2026 09:08
- Standardize all PromQL queries with by (cache_name) per BCL cache.name dimension
- Improve test assertions in BestPractices.md and MigrationGuide.md to verify
  cache.request.type tag values (hit/miss) per dotnet/runtime#124140 spec
- Add hit/miss diagnostic split example in Troubleshooting.md
- Update FAQ.md PromQL queries for consistency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 13, 2026
@rjmurillo rjmurillo marked this pull request as ready for review March 13, 2026 16:38
Copilot AI review requested due to automatic review settings March 13, 2026 16:38
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link

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

Confirmed: I re-read .github/copilot-instructions.md in full before proceeding.

Aligns MeteredMemoryCache with the dotnet/runtime#124140 OpenTelemetry semantic conventions by standardizing the meter name and updating documentation to reflect the current instrument set and naming.

Changes:

  • Update MeteredMemoryCache.MeterName to Microsoft.Extensions.Caching.Memory.MemoryCache.
  • Refresh README and docs to use cache.requests/cache.evictions/cache.entries/cache.estimated_size (and corresponding Prometheus-exported names).
  • Update example guidance in docs and .github/copilot-instructions.md to reference the new instrument names.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/CacheImplementations/MeteredMemoryCache.cs Updates MeterName constant to the BCL-aligned meter name.
README.md Updates public-facing instrument list and AddMeter example.
examples/AspNetCore/docs/README-HTTP-Tests.md Updates described metric names for HTTP tests.
docs/Troubleshooting.md Updates troubleshooting sample to query cache.requests and split by cache.request.type.
docs/OpenTelemetryIntegration.md Updates Prometheus sample, views, and PromQL examples for cache.requests.
docs/MultiCacheScenarios.md Updates PromQL examples to use cache_requests_total patterns.
docs/MigrationGuide.md Updates migration examples and validation snippets to use cache.requests.
docs/MeteredMemoryCache.md Updates metric tables and eviction tracking explanation.
docs/FAQ.md Updates FAQ metric descriptions and example queries.
docs/DocumentationReview.md Declares metric naming standardization as resolved and documents meter name.
docs/BestPractices.md Updates dashboard/alert queries and test snippets to new metric names.
docs/ApiReference.md Updates API reference metric sections to new instrument names.
.github/copilot-instructions.md Updates internal guidance examples to reference cache.requests / cache.evictions.

You can also share your feedback on Copilot code review. Take the survey.

rjmurillo and others added 2 commits March 13, 2026 09:46
…e tag docs

Address copilot-pull-request-reviewer findings:
- MeteredMemoryCache.md: Clarify cache.evictions excludes Removed/Replaced
- README.md: Fix cache.estimated_size condition (TrackStatistics, not SizeLimit)
- OpenTelemetryIntegration.md: Same estimated_size condition fix
- ApiReference.md: cache.name is always present (defaults to Default),
  cache.evictions excludes explicit removals, cache.estimated_size
  condition corrected

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Panel of 5 audit agents reviewed all documentation against MeteredMemoryCache.cs
implementation. 37 inaccuracies found and fixed across 9 files.

Critical fixes (10):
- MeteredMemoryCache.md: 5x wrong AddMeter name 'MyApp.Cache' (metrics silently lost)
- MeteredMemoryCache.md: phantom meterName parameter on 2 API signatures + example
- ApiReference.md: Remove() falsely claimed cache.evictions emitted (excluded reason)
- Troubleshooting.md: pseudocode disclaimer on non-compilable test harness

High fixes (11):
- Prometheus _bytes suffix on cache_estimated_size (OTel unit 'By' conversion)
- Alert rules dropping cache_name label but annotations referencing it (3 files)
- cache.estimated_size condition: TrackStatistics, not SizeLimit (4 files)
- ApiReference: 2 missing IMeterFactory constructor docs, Name nullability
- Eviction semantics: exclusion logic (not positive match) across all docs

Medium/Low fixes (16):
- cache.name tag: 'always present, defaults to Default' (was 'if specified')
- HELP text alignment with code descriptions
- Overhead range, allocation counts, thread-safety mechanism

Test coverage (new file):
- tests/Unit/BclAdoptionCoverageTests.cs: 12 new tests filling coverage gaps
  including MeterName constant, eviction reasons, entry commit semantics,
  estimated_size registration conditions, disposal, GetCurrentStatistics

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rjmurillo rjmurillo merged commit e2b28e6 into main Mar 21, 2026
7 checks passed
@rjmurillo rjmurillo deleted the feat/align-metrics-with-124140 branch March 21, 2026 16:57
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.

4 participants