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

Propulsion.Tool: Add support for Cosmos Autoscaling #142

Merged
merged 6 commits into from
May 27, 2022
Merged
Changes from 1 commit
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
29 changes: 16 additions & 13 deletions tools/Propulsion.Tool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open Argu
open Propulsion.CosmosStore.Infrastructure // AwaitKeyboardInterruptAsTaskCancelledException
open Propulsion.Tool.Args
open Serilog
open System

Expand All @@ -23,30 +24,32 @@ type Parameters =
| Project _ -> "Project from store specified as the last argument, storing state in the specified `aux` Store (see init)."

and [<NoComparison; NoEquality>] InitAuxParameters =
| [<AltCommandLine("-ru"); Mandatory>] Rus of int
| [<AltCommandLine "-A">] Autoscale
| [<AltCommandLine "-m">] Mode of CosmosModeType
| [<AltCommandLine("-s")>] Suffix of string
| [<CliPrefix(CliPrefix.None)>] Cosmos of ParseResults<Args.Cosmos.Parameters>
| [<AltCommandLine("-ru"); Unique>] Rus of int
| [<AltCommandLine "-A"; Unique>] Autoscale
| [<AltCommandLine "-m"; Unique>] Mode of CosmosModeType
| [<AltCommandLine("-s")>] Suffix of string
| [<CliPrefix(CliPrefix.None)>] Cosmos of ParseResults<Args.Cosmos.Parameters>
interface IArgParserTemplate with
member a.Usage = a |> function
| Rus _ -> "Specify RU/s level to provision for the Aux Container."
| Rus _ -> "Specify RU/s level to provision for the Aux Container. (with AutoScale, the value represents the maximum RU/s to AutoScale based on)."
| Autoscale -> "Autoscale provisioned throughput. Use --rus to specify the maximum RU/s."
| Mode _ -> "Configure RU mode to use Container-level RU, Database-level RU, or Serverless allocations (Default: Use Container-level allocation)."
| Suffix _ -> "Specify Container Name suffix (default: `-aux`)."
| Cosmos _ -> "Cosmos Connection parameters."

and CosmosInitInfo(args : ParseResults<InitAuxParameters>) =

let throughputSpec =
match args.Contains Autoscale with
| true -> Equinox.CosmosStore.Core.Initialization.Throughput.Autoscale (args.GetResult(Rus, 4000))
| false -> Equinox.CosmosStore.Core.Initialization.Throughput.Manual (args.GetResult(Rus, 400))

member _.ProvisioningMode =
let throughput () =
if args.Contains Autoscale
then Equinox.CosmosStore.Core.Initialization.Throughput.Autoscale (args.GetResult(Rus, 4000))
else Equinox.CosmosStore.Core.Initialization.Throughput.Manual (args.GetResult(Rus, 400))
match args.GetResult(Mode, CosmosModeType.Container) with
| CosmosModeType.Container -> Equinox.CosmosStore.Core.Initialization.Provisioning.Container (throughput ())
| CosmosModeType.Db -> Equinox.CosmosStore.Core.Initialization.Provisioning.Database (throughput ())
| CosmosModeType.Container -> Equinox.CosmosStore.Core.Initialization.Provisioning.Container throughputSpec
| CosmosModeType.Db -> Equinox.CosmosStore.Core.Initialization.Provisioning.Database throughputSpec
| CosmosModeType.Serverless ->
if args.Contains Rus || args.Contains Autoscale then raise (failwith "Cannot specify RU/s or Autoscale in Serverless mode")
if args.Contains Rus || args.Contains Autoscale then raise (MissingArg "Cannot specify RU/s or Autoscale in Serverless mode")
bartelink marked this conversation as resolved.
Show resolved Hide resolved
Equinox.CosmosStore.Core.Initialization.Provisioning.Serverless
and [<NoEquality; NoComparison>] CheckpointParameters =
| [<AltCommandLine "-s"; Mandatory>] Source of Propulsion.Feed.SourceId
Expand Down