Skip to content

Commit

Permalink
Add Health Check for Runtime mode (#16715)
Browse files Browse the repository at this point in the history
* Add Health Check for Runtime mode

* Update src/Umbraco.Core/EmbeddedResources/Lang/en.xml

Co-authored-by: Jason Elkin <jasonelkin86@gmail.com>

* Update src/Umbraco.Core/HealthChecks/Checks/LiveEnvironment/RuntimeModeCheck.cs

Co-authored-by: Jason Elkin <jasonelkin86@gmail.com>

* Update lang file

* Fix typo.

---------

Co-authored-by: Jason Elkin <jasonelkin86@gmail.com>
  • Loading branch information
erikjanwestendorp and JasonElkin authored Jul 24, 2024
1 parent f20528c commit 9a49ab7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Umbraco.Core/Constants-HealthChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class DocumentationLinks
public static class LiveEnvironment
{
public const string CompilationDebugCheck = "https://umbra.co/healthchecks-compilation-debug";
public const string RuntimeModeCheck = "https://docs.umbraco.com/umbraco-cms/fundamentals/setup/server-setup/runtime-modes";
}

public static class Configuration
Expand Down
4 changes: 3 additions & 1 deletion src/Umbraco.Core/EmbeddedResources/Lang/en.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<language alias="en" intName="English (UK)" localName="English (UK)" lcid="" culture="en-GB">
<creator>
<name>The Umbraco community</name>
Expand Down Expand Up @@ -428,6 +428,8 @@
<key alias="compilationDebugCheckErrorMessage">Debug compilation mode is currently enabled. It is recommended to
disable this setting before go live.
</key>
<key alias="runtimeModeCheckSuccessMessage">Runtime mode is set to production.</key>
<key alias="runtimeModeCheckErrorMessage">Runtime mode is not set to Production. It is recommended to set the Runtime Mode to Production for live/production environments.</key>
<!-- The following keys get these tokens passed in:
0: Path to the file not found
-->
Expand Down
2 changes: 2 additions & 0 deletions src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@
<key alias="compilationDebugCheckErrorMessage">Debug compilation mode is currently enabled. It is recommended to
disable this setting before go live.
</key>
<key alias="runtimeModeCheckSuccessMessage">Runtime mode is set to production.</key>
<key alias="runtimeModeCheckErrorMessage">Runtime mode is not set to Production. It is recommended to set the Runtime Mode to Production for live/production environments.</key>
<!-- The following keys get these tokens passed in:
0: Comma delimitted list of failed folder paths
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.HealthChecks.Checks.LiveEnvironment;

/// <summary>
/// Health check for the recommended production configuration for the runtime mode.
/// </summary>
[HealthCheck(
"8E31E5C9-7A1D-4ACB-A3A8-6495F3EDB932",
"Runtime Mode",
Description = "The Production Runtime Mode disables development features and checks that settings are configured optimally for production.",
Group = "Live Environment")]
public class RuntimeModeCheck : AbstractSettingsCheck
{
private readonly IOptionsMonitor<RuntimeSettings> _runtimeSettings;

/// <summary>
/// Initializes a new instance of the <see cref="RuntimeModeCheck" /> class.
/// </summary>
public RuntimeModeCheck(ILocalizedTextService textService, IOptionsMonitor<RuntimeSettings> runtimeSettings)
: base(textService) =>
_runtimeSettings = runtimeSettings;

/// <inheritdoc />
public override string ItemPath => Constants.Configuration.ConfigRuntimeMode;

/// <inheritdoc />
public override ValueComparisonType ValueComparisonType => ValueComparisonType.ShouldEqual;

/// <inheritdoc />
public override IEnumerable<AcceptableConfiguration> Values => new List<AcceptableConfiguration>
{
new() { IsRecommended = true, Value = RuntimeMode.Production.ToString() },
};

/// <inheritdoc />
public override string CurrentValue => _runtimeSettings.CurrentValue.Mode.ToString();

/// <inheritdoc />
public override string CheckSuccessMessage => LocalizedTextService.Localize("healthcheck", "runtimeModeCheckSuccessMessage");

/// <inheritdoc />
public override string CheckErrorMessage => LocalizedTextService.Localize("healthcheck", "runtimeModeCheckErrorMessage");

/// <inheritdoc />
public override string ReadMoreLink => Constants.HealthChecks.DocumentationLinks.LiveEnvironment.RuntimeModeCheck;
}

0 comments on commit 9a49ab7

Please sign in to comment.