-
-
Notifications
You must be signed in to change notification settings - Fork 3
Improve Configuration API (Round 2) #136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # These are supported funding model platforms | ||
|
|
||
| github: [viceroypenguin] |
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
119 changes: 119 additions & 0 deletions
119
src/Immediate.Jobs.Dashboard/ImmediateJobsDashboardBuilder.cs
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,119 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.Options; | ||
|
|
||
| namespace Immediate.Jobs.Dashboard; | ||
|
|
||
| /// <summary> | ||
| /// The fluent registration result returned by <see cref="ImmediateJobsDashboardServiceCollectionExtensions.AddImmediateJobsDashboard(IImmediateJobsBuilder)"/>. | ||
| /// </summary> | ||
| public interface IImmediateJobsDashboardBuilder : IImmediateJobsBuilder | ||
| { | ||
| /// <summary> | ||
| /// Provides an extension point to configure the options using a user provided configuration method. | ||
| /// </summary> | ||
| /// <param name="configureDashboard"> | ||
| /// The configuration method used to set the options. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The supplied builder. | ||
| /// </returns> | ||
| IImmediateJobsDashboardBuilder ConfigureDashboard( | ||
| Action<OptionsBuilder<ImmediateJobsDashboardOptions>> configureDashboard | ||
| ); | ||
|
|
||
| /// <summary> | ||
| /// Provides an extension point to configure the options using a user provided configuration method. | ||
| /// </summary> | ||
| /// <param name="configureDashboard"> | ||
| /// The configuration method used to set the options. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The supplied builder. | ||
| /// </returns> | ||
| IImmediateJobsDashboardBuilder ConfigureDashboard( | ||
| Action<ImmediateJobsDashboardOptions> configureDashboard | ||
| ); | ||
|
|
||
| /// <summary> | ||
| /// Adds a provider-specific link from job details to an external telemetry system. | ||
| /// </summary> | ||
| /// <param name="label"> | ||
| /// User-facing action label. | ||
| /// </param> | ||
| /// <param name="kind"> | ||
| /// Whether the link opens traces or logs. | ||
| /// </param> | ||
| /// <param name="createUrl"> | ||
| /// Builds a URL from the job and optional exact execution. Exact-execution requests scope the job's attempt, | ||
| /// trace ID, span ID, and execution-started compatibility fields to that execution. Return <see | ||
| /// langword="null"/> when the link is not available, such as before a trace has been created. | ||
| /// </param> | ||
| /// <returns> | ||
| /// The supplied builder. | ||
| /// </returns> | ||
| IImmediateJobsDashboardBuilder AddTelemetryLink( | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| string label, | ||
| JobTelemetryLinkKind kind, | ||
| Func<JobTelemetryLinkContext, Uri?> createUrl | ||
| ); | ||
| } | ||
|
|
||
| internal sealed class ImmediateJobsDashboardBuilder(IImmediateJobsBuilder builder, OptionsBuilder<ImmediateJobsDashboardOptions> optionsBuilder) : IImmediateJobsDashboardBuilder | ||
| { | ||
| public IImmediateJobsDashboardBuilder AddTelemetryLink( | ||
| string label, | ||
| JobTelemetryLinkKind kind, | ||
| Func<JobTelemetryLinkContext, Uri?> createUrl | ||
| ) | ||
| { | ||
| ArgumentException.ThrowIfNullOrWhiteSpace(label); | ||
|
|
||
| if (!Enum.IsDefined(kind)) | ||
| throw new ArgumentOutOfRangeException(nameof(kind)); | ||
|
|
||
| ArgumentNullException.ThrowIfNull(createUrl); | ||
|
|
||
| optionsBuilder.Configure(o => o.TelemetryLinks.Add(new(label, kind, createUrl))); | ||
| return this; | ||
| } | ||
|
|
||
| public IImmediateJobsDashboardBuilder ConfigureDashboard(Action<OptionsBuilder<ImmediateJobsDashboardOptions>> configureDashboard) | ||
| { | ||
| configureDashboard(optionsBuilder); | ||
| return this; | ||
| } | ||
|
|
||
| public IImmediateJobsDashboardBuilder ConfigureDashboard(Action<ImmediateJobsDashboardOptions> configureDashboard) | ||
| { | ||
| optionsBuilder.Configure(configureDashboard); | ||
| return this; | ||
| } | ||
|
|
||
| public IServiceCollection Services => builder.Services; | ||
|
|
||
| public IImmediateJobsBuilder AddHealthCheck(string name = "immediate-jobs", HealthStatus? failureStatus = null, IEnumerable<string>? tags = null) => | ||
| builder.AddHealthCheck(name, failureStatus, tags); | ||
|
|
||
| public IImmediateJobsBuilder ConfigureWorkers(Action<ImmediateJobsOptions> configureJobs) => | ||
| builder.ConfigureWorkers(configureJobs); | ||
|
|
||
| public IImmediateJobsBuilder ConfigureWorkers(Action<OptionsBuilder<ImmediateJobsOptions>> configureJobs) => | ||
| builder.ConfigureWorkers(configureJobs); | ||
|
|
||
| public IImmediateJobsBuilder ConfigureStorage(Action<IImmediateJobsStorageBuilder> configure) => | ||
| builder.ConfigureStorage(configure); | ||
|
|
||
| public IImmediateJobsBuilder DisableWorkers() => | ||
| builder.DisableWorkers(); | ||
|
|
||
| public IImmediateJobsBuilder UseFairQueues() => | ||
| builder.UseFairQueues(); | ||
|
|
||
| public IImmediateJobsBuilder UseFairQueues(Action<OptionsBuilder<FairQueueOptions>> configureFairQueues) => | ||
| builder.UseFairQueues(configureFairQueues); | ||
|
|
||
| IImmediateJobsBuilder IImmediateJobsBuilder.UseIdGenerator<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TGenerator>() => | ||
| builder.UseIdGenerator<TGenerator>(); | ||
| } | ||
82 changes: 29 additions & 53 deletions
82
src/Immediate.Jobs.Dashboard/ImmediateJobsDashboardOptions.cs
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,61 +1,37 @@ | ||
| using Immediate.Validations.Shared; | ||
|
|
||
| namespace Immediate.Jobs.Dashboard; | ||
|
|
||
| /// <summary>Configures the Immediate.Jobs dashboard and monitoring API.</summary> | ||
| public sealed class ImmediateJobsDashboardOptions | ||
| /// <summary> | ||
| /// Configures the Immediate.Jobs dashboard and monitoring API. | ||
| /// </summary> | ||
| [Validate] | ||
| public sealed partial class ImmediateJobsDashboardOptions : IValidationTarget<ImmediateJobsDashboardOptions> | ||
| { | ||
| private readonly List<JobTelemetryLinkRegistration> _telemetryLinks = []; | ||
|
|
||
| /// <summary>The interval between server-sent monitoring snapshots.</summary> | ||
| /// <value>The interval between consecutive dashboard updates.</value> | ||
| /// <summary> | ||
| /// The interval between server-sent monitoring snapshots. | ||
| /// </summary> | ||
| [GreaterThan(nameof(TimeSpan.Zero))] | ||
| public TimeSpan UpdateInterval { get; set; } = TimeSpan.FromSeconds(2); | ||
|
|
||
| internal bool RestrictToDevelopmentEnvironment { get; private set; } = true; | ||
| internal string? AuthorizationPolicy { get; private set; } | ||
| internal IReadOnlyList<JobTelemetryLinkRegistration> TelemetryLinks => _telemetryLinks; | ||
|
|
||
| /// <summary>Allows dashboard access without an authorization policy in any hosting environment.</summary> | ||
| /// <remarks> | ||
| /// This disables the default development-environment restriction. Prefer <see cref="RequireAuthorization"/> | ||
| /// when exposing the dashboard outside a trusted development environment. | ||
| /// </remarks> | ||
| /// <returns>This options instance.</returns> | ||
| public ImmediateJobsDashboardOptions AllowInAnyEnvironment() | ||
| { | ||
| RestrictToDevelopmentEnvironment = false; | ||
| return this; | ||
| } | ||
|
|
||
| /// <summary>Requires the named ASP.NET Core authorization policy on every dashboard endpoint.</summary> | ||
| /// <param name="policy">The registered authorization policy name.</param> | ||
| /// <returns>This options instance.</returns> | ||
| public ImmediateJobsDashboardOptions RequireAuthorization(string policy) | ||
| { | ||
| ArgumentException.ThrowIfNullOrWhiteSpace(policy); | ||
| AuthorizationPolicy = policy; | ||
| return this; | ||
| } | ||
| /// <summary> | ||
| /// Determines whether the dashboard is disabled in non-<c>Development</c> environments. | ||
| /// </summary> | ||
| /// <value> | ||
| /// When <see langword="true" />, dashboard will only be enabled when the current environment | ||
| /// is <c>Development</c>. Otherwise, dashboard will be enabled in all environments. | ||
| /// Default is <see langword="true" />. | ||
| /// </value> | ||
| public bool RestrictToDevelopmentEnvironment { get; set; } = true; | ||
|
|
||
| /// <summary>Adds a provider-specific link from job details to an external telemetry system.</summary> | ||
| /// <param name="label">User-facing action label.</param> | ||
| /// <param name="kind">Whether the link opens traces or logs.</param> | ||
| /// <param name="createUrl"> | ||
| /// Builds a URL from the job and optional exact execution. Exact-execution requests scope the job's | ||
| /// attempt, trace ID, span ID, and execution-started compatibility fields to that execution. Return | ||
| /// <see langword="null"/> when the link is not available, such as before a trace has been created. | ||
| /// </param> | ||
| /// <returns>This options instance.</returns> | ||
| public ImmediateJobsDashboardOptions AddTelemetryLink( | ||
| string label, | ||
| JobTelemetryLinkKind kind, | ||
| Func<JobTelemetryLinkContext, Uri?> createUrl | ||
| ) | ||
| { | ||
| ArgumentException.ThrowIfNullOrWhiteSpace(label); | ||
| ArgumentNullException.ThrowIfNull(createUrl); | ||
| if (!Enum.IsDefined(kind)) | ||
| throw new ArgumentOutOfRangeException(nameof(kind)); | ||
| /// <summary> | ||
| /// Requires the named ASP.NET Core authorization policy on every dashboard endpoint. | ||
| /// </summary> | ||
| /// <value> | ||
| /// The registered authorization policy name. | ||
| /// </value> | ||
| [NotEmpty] | ||
| public string? AuthorizationPolicy { get; set; } | ||
|
|
||
| _telemetryLinks.Add(new(label, kind, createUrl)); | ||
| return this; | ||
| } | ||
| internal List<JobTelemetryLinkRegistration> TelemetryLinks { get; } = []; | ||
| } |
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.