Skip to content

feat(metrics): add canonical cached grain-type dimensions - #11253

Merged
ReubenBond merged 7 commits into
dotnet:mainfrom
ReubenBond:rb-feat-canonical-grain-type-metrics
Sep 15, 2026
Merged

ReubenBond merged 7 commits into
dotnet:mainfrom
ReubenBond:rb-feat-canonical-grain-type-metrics

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Activation populations and lifecycle metrics need a consistent grain-type identity so operators can correlate growth, churn, failures, and latency. This adds grain_type dimensions using the canonical GrainId.Type.ToString() value, cached per registered type and shared across activations.

  • Maintain per-type catalog and working-set populations at existing registration/removal transitions, with snapshot observations and retained zero counts. Preserve the distinct scopes of catalog entries, stateless-worker instances, and working-set membership.
  • Tag lifecycle counters and latency histograms while retaining status, directory, via, and once-only completion. Capture directory failures before deactivation cleanup cancels the activation token, preserving the directory_error outcome.
  • Balance instance accounting through construction failure, repeated disposal, and throwing disposers. Preserve CLR display names for management statistics using instance-local cached counters with atomic updates; stateless-worker wrappers reuse shared type metadata.
  • Targeted events use the grain type carried by their grain ID, including rejected activation requests with uncached types. Rejected requests reuse cached names when available and otherwise format the identity for that event, keeping cache growth tied to type registration.
  • Cover canonical names, generic types, synchronized population reconciliation, cancellation, migration, stateless workers, and allocation-free warmed recording paths.

Metric schema migration: orleans-grains changes from type containing a CLR implementation name to grain_type containing the canonical identity. Migration guidance describes query updates, event-versus-population aggregation, emitter identity, and freshness. The sample Grafana dashboard supports canonical and legacy schemas separately.

Collection scans retain their scan-level scope. The historical additional shutdown event for each nonempty collection batch carries only via=collection, preserving aggregate event totals. Working-set members which expose no grain identity contribute untagged populations, distinct from a grain literally named unknown. Request and streaming metrics retain their existing schemas.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 12, 2026 15:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Two unresolved moderate findings affect grain-type sentinel uniqueness and constructor-failure observer cleanup.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 Medium severity

Open findings (1)
What changed in this PR

Adds cached canonical grain_type dimensions to Orleans metrics, with population/lifecycle accounting, schema migration guidance, tests, and dashboard updates.

Changes:

  • Adds per-type cached metrics and population gauges.
  • Updates lifecycle and instance accounting while preserving management statistics.
  • Documents and tests the new metric schema and dashboard queries.

Review findings:

  • src/Orleans.Core/Diagnostics/Metrics/GrainTypeMetrics.cs:16 — Moderate, 3 votes: "unknown" can collide with a valid grain type, producing duplicate series.
  • src/Orleans.Runtime/Catalog/ActivationData.cs:1014 — Moderate, 1 vote: constructor failures skip OnDestroyActivation, breaking observer cleanup.
File Summary
test/​Orleans.Runtime.Tests/​Diagnostics/​GrainInstrumentsTests.cs Tests instance metrics, tags, and accounting.
test/​Orleans.Runtime.Internal.Tests/​ActivationsLifeCycleTests/​ActivationDataMigrationTests.cs Tests lifecycle, migration, cancellation, disposal, and stateless workers.
test/​Orleans.Core.Tests/​Runtime/​CatalogInstrumentsTests.cs Tests typed metrics, trackers, caching, and allocation behavior.
test/​Orleans.Core.Tests/​Runtime/​ActivationCollectorTests.cs Tests population and collection accounting.
src/​Orleans.Runtime/​Catalog/​GrainTypeSharedContext.cs Shares cached type metrics across activations.
src/​Orleans.Runtime/​Catalog/​Catalog.cs Tags catalog lifecycle and nonexistent-activation events.
src/​Orleans.Runtime/​Catalog/​ActivationWorkingSet.cs Tracks per-type working-set populations.
src/​Orleans.Runtime/​Catalog/​ActivationDirectory.cs Tracks per-type catalog populations.
src/​Orleans.Runtime/​Catalog/​ActivationData.cs Updates lifecycle metrics and disposal accounting.
src/​Orleans.Runtime/​Catalog/​ActivationCollector.cs Preserves collection-level shutdown events.
src/​Orleans.Core/​Statistics/​GrainMetricsListener.cs Removes the global metrics listener.
src/​Orleans.Core/​Statistics/​GrainCountStatistics.cs Uses local grain instrumentation statistics.
src/​Orleans.Core/​Diagnostics/​Metrics/​GrainTypeMetrics.cs Defines cached per-type metric state.
src/​Orleans.Core/​Diagnostics/​Metrics/​GrainInstruments.cs Adds canonical tags and local instance accounting.
src/​Orleans.Core/​Diagnostics/​Metrics/​CatalogInstruments.cs Adds tagged lifecycle instruments and population gauges.
samples/​GPSTracker/​README.md Documents dashboard migration guidance.
samples/​GPSTracker/​grafana_dash.json Updates canonical and legacy metric queries.
docs/​site/​src/​content/​docs/​migration-guide.md Documents metric schema migration.
docs/​site/​src/​content/​docs/​host/​monitoring/​metrics.md Updates metric descriptions and aggregation semantics.
docs/​site/​src/​content/​docs/​host/​monitoring/​metrics-catalog.md Documents metric dimensions, scopes, and identity.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 12, 2026 16:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The unknown-type sentinel can collide with the valid canonical GrainType("unknown"), requiring a fix before approval.

Review tier: Lite
Findings: 1 Medium severity

Open findings (1)

Copilot AI review requested due to automatic review settings September 13, 2026 14:57
@ReubenBond
ReubenBond force-pushed the rb-feat-canonical-grain-type-metrics branch from c33e9c9 to c63b483 Compare September 13, 2026 14:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The unknown grain type can collide with the synthetic unknown sentinel, making exported series indistinguishable.

Review tier: Lite
Findings: 1 Medium severity

Open findings (1)

@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 81.67% (110,322 / 135,088) 81.61% (110,168 / 134,990) +0.0548 pp
Branches 70.59% (31,361 / 44,430) 70.51% (31,308 / 44,404) +0.0780 pp

Report-only conclusion: improved.

The current-main baseline is commit 5efe793862 and uses the same reviewed coverage matrix.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

Copilot AI review requested due to automatic review settings September 14, 2026 09:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The broad runtime and metrics changes warrant final human review.

Review tier: Lite
Findings: None

Resolved findings (1)

Copilot AI review requested due to automatic review settings September 14, 2026 23:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Broad cross-cutting metrics and lifecycle changes require final human review; three style nits remain.

Review tier: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 14, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The DurableJobsJournaling dashboard still queries the removed type label and must be migrated to grain_type or an explicit legacy-schema query.

Review tier: Lite
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 15, 2026 00:41
@ReubenBond
ReubenBond force-pushed the rb-feat-canonical-grain-type-metrics branch from 9fcfc01 to 41f780c Compare September 15, 2026 00:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Two test files have unresolved import-order style nits.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 2 Low severity

Open (2)
Resolved since last review (1)

This was referenced Oct 12, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants