-
Notifications
You must be signed in to change notification settings - Fork 26
Enable Integrated Mode #2786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mikeminutillo
wants to merge
24
commits into
master
Choose a base branch
from
embedded-mode-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+330
−264
Draft
Enable Integrated Mode #2786
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6b4c159
Split application settings and host settings
mikeminutillo d7fa796
Extract App from Host
mikeminutillo adbec3f
Extract core from host
mikeminutillo 1dceb07
Add public API documentation
mikeminutillo 2baf8f4
Rename Settings to make it clear in other contexts
mikeminutillo b1deaaf
Skip AutomaticVersionRange on MS Dependency
mikeminutillo 2f5c197
Expect an additional nuget
mikeminutillo e7e7bef
Serving files off disk is optional
mikeminutillo d66f45a
Indicate to UI if running in embedded mode
mikeminutillo 2c75cbe
Adjust SP UI when embedded
mikeminutillo 428524e
Cleanup
mikeminutillo 619535c
Update StaticMiddlewareTests.cs
mikeminutillo 450e8b1
Use passed ServiceControl url if embedded
mikeminutillo 78f431d
Allow serving constants file anonymously
mikeminutillo d654bd4
Remove unused method
mikeminutillo 38492b3
Remove unused method 2
mikeminutillo c3d4987
Apply suggestions from code review
mikeminutillo 1d95ae2
Cleanup
mikeminutillo 0eac598
Fix whitespace
mikeminutillo cd06a6a
Put hosting extension in namespace
mikeminutillo 41f596d
Change embedded to integrated
mikeminutillo eae680a
Update to .NET 10
mikeminutillo 0108fed
Fix dotnet versions used for actions
mikeminutillo 07460e1
Use global json file
mikeminutillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "8.0.400", | ||
| "version": "10.0.0", | ||
| "allowPrerelease": false, | ||
| "rollForward": "latestFeature" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Particular.PlatformSample.ServicePulse/Particular.PlatformSample.ServicePulse.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| namespace ServicePulse; | ||
|
|
||
| using System.Reflection; | ||
|
|
||
| class ConstantsFile | ||
| { | ||
| public static string GetContent(ServicePulseSettings settings) | ||
| { | ||
| var version = GetVersionInformation(); | ||
|
|
||
| var constantsFile = $$""" | ||
| window.defaultConfig = { | ||
| default_route: '{{settings.DefaultRoute}}', | ||
| version: '{{version}}', | ||
| service_control_url: '{{settings.ServiceControlUrl}}', | ||
| monitoring_urls: ['{{settings.MonitoringUrl ?? "!"}}'], | ||
| showPendingRetry: {{settings.ShowPendingRetry.ToString().ToLower()}}, | ||
| isIntegrated: {{settings.IsIntegrated.ToString().ToLower()}} | ||
| } | ||
| """; | ||
|
|
||
| return constantsFile; | ||
| } | ||
|
|
||
| static string GetVersionInformation() | ||
| { | ||
| var majorMinorPatch = "0.0.0"; | ||
|
|
||
| var attributes = typeof(ConstantsFile).Assembly.GetCustomAttributes<AssemblyMetadataAttribute>(); | ||
|
|
||
| foreach (var attribute in attributes) | ||
| { | ||
| if (attribute.Key == "MajorMinorPatch") | ||
| { | ||
| majorMinorPatch = attribute.Value ?? "0.0.0"; | ||
| } | ||
| } | ||
|
|
||
| return majorMinorPatch; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="10.0.2" AutomaticVersionRange="false" /> | ||
| <PackageReference Include="Particular.Packaging" Version="4.5.0" PrivateAssets="All" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <EmbeddedResource Include="..\Frontend\dist\**\*" Exclude="..\Frontend\dist\js\**\*" LinkBase="wwwroot" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| namespace ServicePulse; | ||
|
|
||
| using System.Net.Mime; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.Extensions.FileProviders; | ||
|
|
||
| /// <summary> | ||
| /// Extensions for hosting ServicePulse within a WebApplication. | ||
| /// </summary> | ||
| public static class ServicePulseHostingExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds ServicePulse static file serving and configuration endpoint to the WebApplication. | ||
| /// </summary> | ||
| public static void UseServicePulse(this WebApplication app, ServicePulseSettings settings, IFileProvider? overrideFileProvider = null) | ||
| { | ||
| var manifestEmbeddedFileProvider = new ManifestEmbeddedFileProvider(typeof(ServicePulseHostingExtensions).Assembly, "wwwroot"); | ||
| IFileProvider fileProvider = overrideFileProvider is null | ||
| ? manifestEmbeddedFileProvider | ||
| : new CompositeFileProvider(overrideFileProvider, manifestEmbeddedFileProvider); | ||
|
|
||
| var defaultFilesOptions = new DefaultFilesOptions { FileProvider = fileProvider }; | ||
| app.UseDefaultFiles(defaultFilesOptions); | ||
|
|
||
| var staticFileOptions = new StaticFileOptions { FileProvider = fileProvider }; | ||
| app.UseStaticFiles(staticFileOptions); | ||
|
|
||
| var constantsFile = ConstantsFile.GetContent(settings); | ||
|
|
||
| app.MapGet("/js/app.constants.js", (HttpContext context) => | ||
| { | ||
| context.Response.ContentType = MediaTypeNames.Text.JavaScript; | ||
| return constantsFile; | ||
| }).AllowAnonymous(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| namespace ServicePulse; | ||
|
|
||
| using System.Text.Json; | ||
|
|
||
| /// <summary> | ||
| /// Application Settings for ServicePulse. | ||
| /// </summary> | ||
| public record ServicePulseSettings | ||
| { | ||
| /// <summary> | ||
| /// The location of the ServiceControl API. | ||
| /// </summary> | ||
| public required string ServiceControlUrl { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The location of the ServiceControl Monitoring API. | ||
| /// </summary> | ||
| public required string? MonitoringUrl { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The default route to navigate to from the root. | ||
| /// </summary> | ||
| public required string DefaultRoute { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Flag to enable the pending retry feature. | ||
| /// </summary> | ||
| public required bool ShowPendingRetry { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Flag to indicate if ServicePulse is running in integrated mode. | ||
| /// </summary> | ||
| public required bool IsIntegrated { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Loads the settings from environment variables. | ||
| /// </summary> | ||
| public static ServicePulseSettings GetFromEnvironmentVariables() | ||
| { | ||
| var serviceControlUrl = Environment.GetEnvironmentVariable("SERVICECONTROL_URL") ?? "http://localhost:33333/api/"; | ||
|
|
||
| if (!serviceControlUrl.EndsWith("/", StringComparison.Ordinal)) | ||
| { | ||
| serviceControlUrl += "/"; | ||
| } | ||
|
|
||
| if (!serviceControlUrl.EndsWith("api/", StringComparison.Ordinal)) | ||
| { | ||
| serviceControlUrl += "api/"; | ||
| } | ||
|
|
||
| var serviceControlUri = new Uri(serviceControlUrl); | ||
|
|
||
| var monitoringUrls = ParseLegacyMonitoringValue(Environment.GetEnvironmentVariable("MONITORING_URLS")); | ||
| var monitoringUrl = Environment.GetEnvironmentVariable("MONITORING_URL"); | ||
|
|
||
| monitoringUrl ??= monitoringUrls; | ||
| monitoringUrl ??= "http://localhost:33633/"; | ||
|
|
||
| var monitoringUri = monitoringUrl == "!" ? null : new Uri(monitoringUrl); | ||
|
|
||
| var defaultRoute = Environment.GetEnvironmentVariable("DEFAULT_ROUTE") ?? "/dashboard"; | ||
|
|
||
| var showPendingRetryValue = Environment.GetEnvironmentVariable("SHOW_PENDING_RETRY"); | ||
| bool.TryParse(showPendingRetryValue, out var showPendingRetry); | ||
|
|
||
| return new ServicePulseSettings | ||
| { | ||
| ServiceControlUrl = serviceControlUri.ToString(), | ||
| MonitoringUrl = monitoringUri?.ToString(), | ||
| DefaultRoute = defaultRoute, | ||
| ShowPendingRetry = showPendingRetry, | ||
| IsIntegrated = false | ||
| }; | ||
| } | ||
|
|
||
| static string? ParseLegacyMonitoringValue(string? value) | ||
| { | ||
| if (value is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var cleanedValue = value.Replace('\'', '"'); | ||
| var json = $$"""{"Addresses":{{cleanedValue}}}"""; | ||
|
|
||
| MonitoringUrls? result; | ||
|
|
||
| try | ||
| { | ||
| result = JsonSerializer.Deserialize<MonitoringUrls>(json); | ||
| } | ||
| catch (JsonException) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var addresses = result?.Addresses; | ||
|
|
||
| if (addresses is not null && addresses.Length > 0) | ||
| { | ||
| return addresses[0]; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| class MonitoringUrls | ||
| { | ||
| public string[] Addresses { get; set; } = []; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.