-
Notifications
You must be signed in to change notification settings - Fork 363
Scaler apis #2954
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
Scaler apis #2954
Changes from 9 commits
705526e
79a0486
d7bd09e
49ede7a
3e3b1a0
8ad30bd
c7bf959
476ba91
c1a8a93
d6f781d
5d77b9a
79d9086
e2b08af
3d15a6a
b59bf70
b7479b5
256602f
d101ac2
8b6936a
87d1cc2
00bf27f
bd3ebb0
4467104
e0c7520
9f68638
26ed467
fcc5aaf
bdf6ac7
82cd90a
be2550e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,8 +31,12 @@ public static void AddAzureStorageCoreServices(this IServiceCollection services) | |
| // Adds necessary Azure services to create clients | ||
| services.AddAzureClientsCore(); | ||
|
|
||
| services.TryAddSingleton<IAzureBlobStorageProvider, AzureStorageProvider>(); | ||
| services.AddAzureStorageScaleServices(); | ||
|
alrod marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public static void AddAzureStorageScaleServices(this IServiceCollection services) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this meant to ever be called by a customer?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this will be called from ScaleController, see example here: Function host is not supposed to call this. |
||
| { | ||
| services.TryAddSingleton<IAzureBlobStorageProvider, AzureStorageProvider>(); | ||
| services.AddSingleton<IConcurrencyStatusRepository, BlobStorageConcurrencyStatusRepository>(); | ||
|
chiangvincent marked this conversation as resolved.
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,17 @@ | |
| using System; | ||
| using System.Linq; | ||
| using Microsoft.Azure.WebJobs; | ||
| using Microsoft.Azure.WebJobs.Host; | ||
| using Microsoft.Azure.WebJobs.Host.Config; | ||
| using Microsoft.Azure.WebJobs.Host.Executors; | ||
| using Microsoft.Azure.WebJobs.Host.Scale; | ||
| using Microsoft.Azure.WebJobs.Hosting; | ||
| using Microsoft.Extensions.Configuration; | ||
| using Microsoft.Extensions.Configuration.EnvironmentVariables; | ||
| using Microsoft.Extensions.Configuration.Json; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
| using Microsoft.FeatureManagement; | ||
|
|
||
| namespace Microsoft.Extensions.Hosting | ||
| { | ||
|
|
@@ -135,6 +140,38 @@ public static IHostBuilder ConfigureWebJobs(this IHostBuilder builder, Action<Ho | |
| return builder; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configures the specified <see cref="IHostBuilder"/> as a scale manager host. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that something a customer will do? Or do we need to mention this is only for internal infrastructure or something like that?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this will be called from `ScaleController and a webjobs customer is not suppose to create a "scale manager host". I I extended the description. |
||
| /// </summary> | ||
| /// <param name="builder">The <see cref="IHostBuilder"/> to configure.</param> | ||
| /// <param name="configure">Configuration action to perform as part of service configuration.</param> | ||
| /// <param name="configureScaleOptions">Configuration action for <see cref="ScaleOptions"/>.</param> | ||
| /// <returns>The <see cref="IHostBuilder"/>.</returns> | ||
| public static IHostBuilder ConfigureWebJobsScale(this IHostBuilder builder, | ||
| Action<HostBuilderContext, IWebJobsBuilder> configure, | ||
| Action<ScaleOptions> configureScaleOptions) | ||
| { | ||
| builder.ConfigureServices((context, services) => | ||
| { | ||
| WebJobsBuilder webJobsBuilder = new WebJobsBuilder(services); | ||
| configure?.Invoke(context, webJobsBuilder); | ||
|
|
||
| if (configureScaleOptions != null) | ||
| { | ||
| services.Configure(configureScaleOptions); | ||
| } | ||
|
|
||
| services.AddFeatureManagement(); | ||
| services.TryAddSingleton<IScaleMonitorManager, ScaleMonitorManager>(); | ||
| services.TryAddSingleton<ITargetScalerManager, TargetScalerManager>(); | ||
| services.TryAddSingleton<IScaleManager, ScaleManager>(); | ||
| services.TryAddSingleton<IHostedService, ScaleMonitorService>(); | ||
|
alrod marked this conversation as resolved.
Outdated
|
||
| services.TryAddSingleton<IPrimaryHostStateProvider>(new PrimaryHostStateProvider() { IsPrimary = true }); | ||
|
alrod marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private static IConfigurationBuilder TryAddDefaultConfigurationSources(this IConfigurationBuilder config) | ||
| { | ||
| if (!config.Sources.OfType<JsonConfigurationSource>().Any(p => string.Equals(p.Path, "appsettings.json", StringComparison.OrdinalIgnoreCase))) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Host.Scale | ||
| { | ||
| /// <summary> | ||
| /// Provides scale status. | ||
| /// </summary> | ||
| public interface IScaleManager | ||
| { | ||
| /// <summary> | ||
| /// Gets the current scale status <see cref="ScaleStatus"> for all monitored functions. | ||
| /// </summary> | ||
| /// <param name="context">The <see cref="ScaleStatusContext"/>.</param> | ||
| /// <returns>The current <see cref="ScaleStatus"/>.</returns> | ||
| Task<ScaleStatus> GetScaleStatusAsync(ScaleStatusContext context); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Host.Scale | ||
| { | ||
| /// <summary> | ||
| /// Interface defining methods for reading/writing scale metrics to a persistent store. | ||
| /// </summary> | ||
| public interface IScaleMetricsRepository | ||
| { | ||
| /// <summary> | ||
| /// Persist the metrics for each monitor. | ||
| /// </summary> | ||
| /// <param name="monitorMetrics">The collection of metrics for each monitor.</param> | ||
| /// <returns>A task.</returns> | ||
| Task WriteMetricsAsync(IDictionary<IScaleMonitor, ScaleMetrics> monitorMetrics); | ||
|
|
||
| /// <summary> | ||
| /// Read the metrics. | ||
| /// </summary> | ||
| /// <param name="monitors">The current collection of monitors.</param> | ||
| /// <returns>Map of metrics per monitor.</returns> | ||
| Task<IDictionary<IScaleMonitor, IList<ScaleMetrics>>> ReadMetricsAsync(IEnumerable<IScaleMonitor> monitors); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Host.Scale | ||
| { | ||
| /// <summary> | ||
| /// Interface for providing scalers. | ||
| /// </summary> | ||
| public interface IScalerProvider | ||
|
alrod marked this conversation as resolved.
Outdated
|
||
| { | ||
| /// <summary> | ||
| /// Gets a collection of <see cref="IScaleMonitor"/>s. | ||
| /// </summary> | ||
| /// <returns>The <see cref="IScaleMonitor"/>s.</returns> | ||
| IEnumerable<IScaleMonitor> GetScaleMonitors(); | ||
|
|
||
| /// <summary> | ||
| /// Gets a collection of <see cref="ITargetScaler"/>s. | ||
| /// </summary> | ||
| /// <returns>The <see cref="ITargetScaler"/>s.</returns> | ||
| IEnumerable<ITargetScaler> GetTargetScalers(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Host.Scale | ||
| { | ||
| /// <summary> | ||
| /// Provides trigger metadata. | ||
| /// </summary> | ||
| public interface ITriggerMetadataProvider | ||
| { | ||
| /// <summary> | ||
| /// Gets the trigger metadata. | ||
| /// </summary> | ||
| /// <returns>The trigger metadata.</returns> | ||
| IEnumerable<TriggerMetadata> GetTriggerMetadata(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is about to be published as a GA (non-beta) release, OK to add the changes here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to
<HostStorageVersion>5.0.0$(VersionSuffix)</HostStorageVersion>