Skip to content

Add health checks for sustainability monitoring#80

Open
rickbutterfield wants to merge 4 commits intov5/devfrom
feature/health-checks
Open

Add health checks for sustainability monitoring#80
rickbutterfield wants to merge 4 commits intov5/devfrom
feature/health-checks

Conversation

@rickbutterfield
Copy link
Contributor

@rickbutterfield rickbutterfield commented Feb 17, 2026

Summary

Introduces three Umbraco health checks to monitor website sustainability metrics:

  • Page Coverage Health Check: Reports the percentage of published pages that have been tested for sustainability. Displays warnings when metrics become stale (configurable threshold, default 30 days). Helps identify untested content and encourages regular monitoring.

  • Carbon Rating Health Check: Evaluates the site's overall carbon footprint based on average page metrics (A+ to F rating). Provides actionable feedback when ratings fall below expectations. Uses consistent rating thresholds across the package.

  • Green Hosting Health Check: Verifies if the website is hosted on green infrastructure using The Green Web Foundation API. Checks the current hostname from the application configuration.

Health checks can be configured via appsettings.json under Sustainability:HealthChecks section. The Page Coverage health check supports a configurable StaleDays threshold (default: 30 days) to determine when metrics are considered stale.

Files changed

  • New: HealthChecks/CarbonRatingHealthCheck.cs, HealthChecks/GreenHostingHealthCheck.cs, HealthChecks/PageCoverageHealthCheck.cs
  • New: Helpers/CarbonRatingHelper.cs (shared rating calculation logic)
  • New: Models/PageCoverageData.cs, Models/SustainabilityHealthCheckSettings.cs
  • New: Migrations/04_ChangePageDataToNVarcharMax.cs (SQLite-compatible migration)
  • Modified: Services/PageMetricService.cs (added GetPageCoverageData method)
  • Modified: SustainabilityComposer.cs (health check configuration and HTTP client setup)

This commit introduces three health checks to monitor website sustainability:

- Page Coverage Health Check: Reports the percentage of published pages that
  have been tested for sustainability, with warnings for stale metrics
- Carbon Rating Health Check: Evaluates the site's overall carbon footprint
  based on average page metrics
- Green Hosting Health Check: Verifies if the website is hosted on green
  infrastructure using The Green Web Foundation API

Also includes:
- PageCoverageData model for tracking tested pages and stale metrics
- SustainabilityHealthCheckSettings for configurable thresholds
- CarbonRatingHelper for consistent rating calculations
- Migration to change PageData column to NVARCHAR(MAX) for better compatibility
- Service method to retrieve page coverage statistics

Health checks can be configured via appsettings.json under
Sustainability:HealthChecks section.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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

Adds Umbraco backoffice health checks to surface sustainability monitoring signals (coverage, carbon rating, and green hosting), plus supporting settings and data access/migrations.

Changes:

  • Adds three new Umbraco health checks: Page Coverage, Site Carbon Rating, and Green Hosting.
  • Introduces shared carbon-rating calculation helper and models for health check settings / page coverage data.
  • Extends PageMetricService with coverage aggregation and adds a migration to alter PageData storage type.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/Umbraco.Community.Sustainability/SustainabilityComposer.cs Wires up health check settings and registers a named HTTP client for Green Web Foundation calls.
src/Umbraco.Community.Sustainability/Services/PageMetricService.cs Adds GetPageCoverageData for coverage/staleness aggregation.
src/Umbraco.Community.Sustainability/Notifications/PageMetricsNotificationHandler.cs Adds migration step 04 and switches upgrader execution to async.
src/Umbraco.Community.Sustainability/Models/SustainabilityHealthCheckSettings.cs Introduces config model for health checks (currently only stale-days).
src/Umbraco.Community.Sustainability/Models/PageCoverageData.cs Adds model to return tested/stale page counts.
src/Umbraco.Community.Sustainability/Migrations/04_ChangePageDataToNVarcharMax.cs Adds migration to alter PageData column type (non-SQLite).
src/Umbraco.Community.Sustainability/Helpers/CarbonRatingHelper.cs Centralizes carbon grade thresholds used by the carbon rating health check.
src/Umbraco.Community.Sustainability/HealthChecks/PageCoverageHealthCheck.cs New health check for sustainability coverage and stale-metric warnings.
src/Umbraco.Community.Sustainability/HealthChecks/CarbonRatingHealthCheck.cs New health check to rate site carbon footprint from average metrics.
src/Umbraco.Community.Sustainability/HealthChecks/GreenHostingHealthCheck.cs New health check that queries The Green Web Foundation API for hosting greenness.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rickbutterfield and others added 2 commits February 17, 2026 14:13
- Fix SQL queries to filter NULL NodeKey values in page coverage statistics
- Improve security by logging errors and returning generic messages in GreenHostingHealthCheck
- Add ILogger<GreenHostingHealthCheck> dependency for error logging
- Remove unused ILocalizedTextService dependency from all three health checks
- Use dynamic assembly version for User-Agent instead of hard-coded "5.0"
- Update PR description to match actual implementation (remove mention of custom domains)

Fixes: GitHub Copilot review issues on PR #80

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove unused using statements from health check classes
- Add proper null handling for JSON response in GreenHostingHealthCheck
- Add JsonException handler to gracefully handle malformed API responses
- Make Green property nullable to handle missing/null values
- Fix coverage percentage calculation to cap at 100%
- Ensure stale count never exceeds tested count
- Update message clarity: "Tested published pages" instead of "Tested pages"
- Convert PageMetricsNotificationHandler to async pattern (INotificationAsyncHandler)
- Improve SQL queries to filter by published content only
- Add LatestMetricByNode helper class for cleaner query logic

These changes improve robustness and prevent data inconsistencies in health check reporting.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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.

2 participants