Skip to content
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

[PriorityBasedExecution] Added PriorityLevel as a RequestOption #3672

Merged
merged 16 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6909,6 +6909,11 @@ private INameValueCollection GetRequestHeaders(
headers.Set(HttpConstants.HttpHeaders.ConsistencyLevel, options.ConsistencyLevel.ToString());
}

if (options.PriorityLevel.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.PriorityLevel, options.PriorityLevel.ToString());
}

if (options.IndexingDirective.HasValue)
{
headers.Set(HttpConstants.HttpHeaders.IndexingDirective, options.IndexingDirective.ToString());
Expand Down
28 changes: 27 additions & 1 deletion Microsoft.Azure.Cosmos/src/RequestOptions/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,32 @@ public class RequestOptions
/// </summary>
public Action<Headers> AddRequestHeaders { get; set; }

/// <summary>
/// Gets or sets the priority level for a request.
Achint-Agrawal marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
/// <remarks>
/// Setting priority level only has an effect if Priority Based Execution is enabled.
/// If it is not enabled, the priority level is ignored by the backend.
/// Default PriorityLevel for each request is treated as High. It can be explicitly set to Low for some requests.
/// When Priority based execution is enabled, if there are more requests than the configured RU/S in a second,
/// then Cosmos DB will throttle low priority requests to allow high priority requests to execute.
/// This does not limit the throughput available to each priority level. Each priority level can consume the complete
/// provisioned throughput in absence of the other. If both priorities are present and the user goes above the
/// configured RU/s, low priority requests start getting throttled first to allow execution of mission critical workloads.
/// </remarks>
/// <seealso href="https://aka.ms/CosmosDB/PriorityBasedExecution"/>
#if PREVIEW
public
#else
internal
#endif
PriorityLevel? PriorityLevel { get; set; }

/// <summary>
/// Set Request Level Distributed Tracing Options.
/// </summary>
internal DistributedTracingOptions DistributedTracingOptions { get; set; }

/// <summary>
/// Gets or sets the boolean to use effective partition key routing in the cosmos db request.
/// </summary>
Expand Down Expand Up @@ -91,6 +112,11 @@ internal virtual void PopulateRequestOptions(RequestMessage request)
request.Headers.Add(HttpConstants.HttpHeaders.IfNoneMatch, this.IfNoneMatchEtag);
}

if (this.PriorityLevel.HasValue)
{
request.Headers.Add(HttpConstants.HttpHeaders.PriorityLevel, this.PriorityLevel.ToString());
}

this.AddRequestHeaders?.Invoke(request.Headers);
}

Expand Down
39 changes: 39 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/PriorityLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos
{
/// <summary>
/// Valid values of Priority Level for a request
/// </summary>
/// <remarks>
/// Setting priority level only has an effect if Priority Based Execution is enabled.
/// If it is not enabled, the priority level is ignored by the backend.
/// Default PriorityLevel for each request is treated as High. It can be explicitly set to Low for some requests.
/// When Priority based execution is enabled, if there are more requests than the configured RU/S in a second,
/// then Cosmos DB will throttle low priority requests to allow high priority requests to execute.
/// This does not limit the throughput available to each priority level. Each priority level can consume the complete
/// provisioned throughput in absence of the other. If both priorities are present and the user goes above the
/// configured RU/s, low priority requests start getting throttled first to allow execution of mission critical workloads.
/// </remarks>
/// <seealso href="https://aka.ms/CosmosDB/PriorityBasedExecution"/>

#if PREVIEW
public
#else
internal
#endif
enum PriorityLevel
{
/// <summary>
/// High Priority
/// </summary>
High = 1,

/// <summary>
/// Low Priority
/// </summary>
Low = 2,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,52 @@
}
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.PriorityLevel;System.Enum;IsAbstract:False;IsSealed:True;IsInterface:False;IsEnum:True;IsClass:False;IsValueType:True;IsNested:False;IsGenericType:False;IsSerializable:True": {
"Subclasses": {},
"Members": {
"Int32 value__": {
"Type": "Field",
"Attributes": [],
"MethodInfo": "Int32 value__;IsInitOnly:False;IsStatic:False;"
},
"Microsoft.Azure.Cosmos.PriorityLevel High": {
"Type": "Field",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PriorityLevel High;IsInitOnly:False;IsStatic:True;"
},
"Microsoft.Azure.Cosmos.PriorityLevel Low": {
"Type": "Field",
"Attributes": [],
"MethodInfo": "Microsoft.Azure.Cosmos.PriorityLevel Low;IsInitOnly:False;IsStatic:True;"
}
},
"NestedTypes": {}
},
"Microsoft.Azure.Cosmos.RequestOptions;System.Object;IsAbstract:False;IsSealed:False;IsInterface:False;IsEnum:False;IsClass:True;IsValueType:False;IsNested:False;IsGenericType:False;IsSerializable:False": {
"Subclasses": {},
"Members": {
"System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel] get_PriorityLevel()[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel] get_PriorityLevel();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel] PriorityLevel": {
"Type": "Property",
"Attributes": [],
"MethodInfo": "System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel] PriorityLevel;CanRead:True;CanWrite:True;System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel] get_PriorityLevel();IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;Void set_PriorityLevel(System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
},
"Void set_PriorityLevel(System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel])[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]": {
"Type": "Method",
"Attributes": [
"CompilerGeneratedAttribute"
],
"MethodInfo": "Void set_PriorityLevel(System.Nullable`1[Microsoft.Azure.Cosmos.PriorityLevel]);IsAbstract:False;IsStatic:False;IsVirtual:False;IsGenericMethod:False;IsConstructor:False;IsFinal:False;"
}
},
"NestedTypes": {}
}
},
"Members": {},
Expand Down