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

[joysl] Neptune Autoscaling #180

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
302 changes: 151 additions & 151 deletions source/common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/common/config/rush/repo-state.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "6ff045f325a4557e2c96b1cf8e6a73cea9638863",
"pnpmShrinkwrapHash": "a91e3cdfb0f70338c98919f90c62b3eb5bfe08c0",
"preferredVersionsHash": "14c05a7722342014cec64c4bef7d9bed0d0b7b7f"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#-----------------------------------------------------------------------------------------------------------------------
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
# Licensed under the Apache License, Version 2.0 (the 'License'). You may not use this file except in compliance
# with the License. A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
Expand Down Expand Up @@ -107,6 +107,30 @@ Parameters:
- false
MinLength: 1

ApplyNeptuneAutoscaling:
Description: If true, will apply auto-scaling as defined in `./cfn-autoscaling-neptune.yml'
Type: String
Default: false
AllowedValues:
- true
- false
MinLength: 1

NeptuneAutoScalingMinCapacity:
Description: The no. of desired minimum read replicas to provision
Type: Number
Default: 1

NeptuneAutoScalingMaxCapacity:
Description: The no. of desired maximum read replicas to provision
Type: Number
Default: 1

NeptuneTargetUtilization:
Description: Target utilization (0 to 100).
Type: Number
Default: 75

CdfService:
Description: Service name to tag resources.
Type: String
Expand Down Expand Up @@ -136,11 +160,16 @@ Conditions:

DeployInVPC: !Not [!Equals [!Ref VpcId, 'N/A']]

DeployWithProvisionedCapacity: !Not [!Equals [!Ref ProvisionedConcurrentExecutions, '0']]
DeployWithProvisionedCapacity:
!Not [!Equals [!Ref ProvisionedConcurrentExecutions, '0']]
DeployWithScaling: !Equals [!Ref ApplyAutoscaling, 'true']
DeployWithNeptuneScaling: !Equals [!Ref ApplyNeptuneAutoscaling, 'true']

DeployWithLambdaAuth:
!Or [!Equals [!Ref AuthType, 'LambdaRequest'], !Equals [!Ref AuthType, 'LambdaToken']]
!Or [
!Equals [!Ref AuthType, 'LambdaRequest'],
!Equals [!Ref AuthType, 'LambdaToken'],
]
EnableApiGatewayAccessLogs: !Equals [!Ref EnableApiGatewayAccessLogs, 'true']

Resources:
Expand Down Expand Up @@ -321,6 +350,25 @@ Resources:
Value: !Ref CdfService
DependsOn: LambdaFunction

# Optional Neptune auto-scaling configuration
AutoScalingNeptuneNestedStack:
Type: AWS::CloudFormation::Stack
Comment on lines +353 to +355
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: What's the benefit of having this be a nested stack instead of part of the top-level one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just decided to follow what was set for Lambda autoscaling which was a nested stack.

Condition: DeployWithNeptuneScaling
Properties:
TemplateURL: ./cfn-autoscaling-neptune.yml
Parameters:
NeptuneClusterID: !Sub '{{resolve:ssm:/cdf/asset-library/${Environment}/neptuneClusterID}}'
MinCapacity: !Ref NeptuneAutoScalingMinCapacity
MaxCapacity: !Ref NeptuneAutoScalingMaxCapacity
TargetUtilization: !Ref NeptuneTargetUtilization
TimeoutInMinutes: 5
Tags:
- Key: cdf_environment
Value: !Ref Environment
- Key: cdf_service
Value: !Ref CdfService
DependsOn: LambdaFunction

IotFleetIndex:
Type: Custom::IotFleetIndex
Condition: DeployLiteMode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
#-----------------------------------------------------------------------------------------------------------------------
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the 'License'). You may not use this file except in compliance
# with the License. A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
# and limitations under the License.
#-----------------------------------------------------------------------------------------------------------------------
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Description: |
CDF Asset Library Service Scaling
=================================
This template provides an example of how to apply auto-scaling to the Asset Library Neptune Cluster.

Parameters:
MinCapacity:
Description: The minimum value to scale to in response to a scale-in event.
Type: Number
Default: 1
MaxCapacity:
Description: The maximum value to scale to in response to a scale-out event.
Type: Number
Default: 1
TargetUtilization:
Description: Target utilization (0 to 90).
Type: Number
Default: 75
NeptuneClusterID:
Description: This parameter will contain the ClusterID used for Neptune Auto Scaling
Type: String
Default: cluster:test

Resources:
ScalableTarget:
Type: AWS::ApplicationAutoScaling::ScalableTarget
Properties:
MaxCapacity: !Ref MaxCapacity
MinCapacity: !Ref MinCapacity
ResourceId: !Ref NeptuneClusterID
RoleARN: !Sub arn:aws:iam::${AWS::AccountId}:role/aws-service-role/neptune.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_NeptuneCluster
ScalableDimension: neptune:cluster:ReadReplicaCount
ServiceNamespace: neptune

TargetTrackingScalingPolicy:
Type: AWS::ApplicationAutoScaling::ScalingPolicy
Properties:
PolicyName: utilizationNeptune
PolicyType: TargetTrackingScaling
ScalingTargetId: !Ref ScalableTarget
TargetTrackingScalingPolicyConfiguration:
TargetValue: !Ref TargetUtilization
PredefinedMetricSpecification:
PredefinedMetricType: NeptuneReaderAverageCPUUtilization
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#-----------------------------------------------------------------------------------------------------------------------
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
# Licensed under the Apache License, Version 2.0 (the 'License'). You may not use this file except in compliance
# with the License. A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
Expand Down Expand Up @@ -33,7 +33,7 @@ Parameters:
Neptune DB instance type. The list of available instance types for your region can be found here:
https://aws.amazon.com/neptune/pricing/
Type: String
AllowedPattern: "^db\\.[tr]\\d+[a-z0-9]*\\.[a-z0-9]*$"
AllowedPattern: '^db\\.[tr]\\d+[a-z0-9]*\\.[a-z0-9]*$'
ConstraintDescription: Must be a valid Neptune instance type.
CreateDBReplicaInstance:
Description: Create a read replica for MultiAZ?
Expand Down Expand Up @@ -308,6 +308,14 @@ Resources:
DependsOn:
- NeptuneDBInstance

DBClusterIdSsmParameter:
Type: 'AWS::SSM::Parameter'
Properties:
Description: VPC ID for the account
Name: !Sub '/cdf/asset-library/${Environment}/neptuneClusterID'
Type: String
Value: !Sub 'cluster:${NeptuneDBCluster}'

Outputs:
DBClusterId:
Description: Neptune Cluster Identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { ModuleName, PostmanEnvironment, RestModule } from '../../../models/modu
import { applicationConfigurationPrompt } from '../../../prompts/applicationConfiguration.prompt';
import {
enableAutoScaling,
provisionedConcurrentExecutions,
enableNeptuneAutoScaling,
maxNeptuneReadReplicas,
minNeptuneReadReplicas,
neptuneTargetUtilization,
provisionedConcurrentExecutions
} from '../../../prompts/autoscaling.prompt';
import { customDomainPrompt } from '../../../prompts/domain.prompt';
import { redeployIfAlreadyExistsPrompt } from '../../../prompts/modules.prompt';
Expand Down Expand Up @@ -175,6 +179,10 @@ export class AssetLibraryInstaller implements RestModule {
},
enableAutoScaling(this.name, answers),
provisionedConcurrentExecutions(this.name, answers),
enableNeptuneAutoScaling(this.name, answers),
minNeptuneReadReplicas(this.name, answers),
maxNeptuneReadReplicas(this.name, answers),
neptuneTargetUtilization(this.name, answers),
...applicationConfigurationPrompt(this.name, answers, [
{
question: 'Enable authorization?',
Expand Down Expand Up @@ -288,6 +296,11 @@ export class AssetLibraryInstaller implements RestModule {
'ProvisionedConcurrentExecutions',
answers.assetLibrary.provisionedConcurrentExecutions
);
addIfSpecified('ApplyNeptuneAutoscaling', answers.assetLibrary.enableNeptuneAutoScaling);
addIfSpecified('NeptuneAutoScalingMinCapacity', answers.assetLibrary.minNeptuneReadReplicaCapacity);
addIfSpecified('NeptuneAutoScalingMaxCapacity', answers.assetLibrary.maxNeptuneReadReplicaCapacity);
addIfSpecified('NeptuneTargetUtilization', answers.assetLibrary.neptuneTargetUtilization);

addIfSpecified(
'CustomResourceVPCLambdaArn',
answers.assetLibrary.mode === 'full'
Expand Down
10 changes: 9 additions & 1 deletion source/packages/services/installer/src/models/answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ export interface ProvisionedConcurrencyModuleAttribues extends ServiceModuleAttr
provisionedConcurrentExecutions?: number;
enableAutoScaling?: boolean;
}

export interface NeptuneScalingAttributes {
minNeptuneReadReplicaCapacity?: number;
maxNeptuneReadReplicaCapacity?: number;
enableNeptuneAutoScaling?: boolean;
neptuneTargetUtilization?: number;
}
export interface RestServiceModuleAttribues extends ServiceModuleAttributes {
enableCustomDomain?: boolean;
customDomainBasePath?: string;
Expand All @@ -123,7 +130,8 @@ export interface OrganizationManager extends RestServiceModuleAttribues {

export interface AssetLibrary
extends RestServiceModuleAttribues,
ProvisionedConcurrencyModuleAttribues {
ProvisionedConcurrencyModuleAttribues,
NeptuneScalingAttributes {
mode?: 'full' | 'lite';
neptuneDbInstanceType?: string;
createDbReplicaInstance?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import { Question } from 'inquirer';
import {
Answers,
ProvisionedConcurrencyModuleAttribues as ProvisionedConcurrencyModuleAttributes,
NeptuneScalingAttributes,
ProvisionedConcurrencyModuleAttribues as ProvisionedConcurrencyModuleAttributes
} from '../models/answers';
import { ModuleName } from '../models/modules';

Expand Down Expand Up @@ -49,3 +50,71 @@ export function provisionedConcurrentExecutions(
},
};
}

export function enableNeptuneAutoScaling(moduleName: ModuleName, answers: Answers): Question {
return {
message: 'Deployed with a autoscaling for Neptune?',
type: 'confirm',
name: `${moduleName}.enableNeptuneAutoScaling`,
default: (answers[moduleName] as NeptuneScalingAttributes)?.enableNeptuneAutoScaling ?? false,
askAnswered: true,
};
}


export function maxNeptuneReadReplicas(moduleName: ModuleName, answers: Answers): Question {
return {
message: 'The max number of read replicas when neptune is scaled. Default is 1',
type: 'input',
name: `${moduleName}.maxNeptuneReadReplicas`,
default: (answers[moduleName] as NeptuneScalingAttributes)?.maxNeptuneReadReplicaCapacity ?? 1,
askAnswered: true,
when(answers: Answers) {
return answers.assetLibrary?.enableNeptuneAutoScaling
},
validate(answer: number) {
if (answer < 0) {
return `You must enter number 0 or larger than 0.`;
}
return true;
},
};
}

export function minNeptuneReadReplicas(moduleName: ModuleName, answers: Answers): Question {
return {
message: 'The minimum number of read replicas when neptune is scaled. Default is 1',
type: 'input',
name: `${moduleName}.minNeptuneReadReplicas`,
default: (answers[moduleName] as NeptuneScalingAttributes)?.minNeptuneReadReplicaCapacity ?? 1,
askAnswered: true,
when(answers: Answers) {
return answers.assetLibrary?.enableNeptuneAutoScaling
},
validate(answer: number) {
if (answer < 0) {
return `You must enter number 0 or larger than 0.`;
}
return true;
},
};
}

export function neptuneTargetUtilization(moduleName: ModuleName, answers: Answers): Question {
return {
message: 'The target CPU utilization for Neptune to auto-scale read replica?',
type: 'input',
name: `${moduleName}.neptuneTargetUtilization`,
default: (answers[moduleName] as NeptuneScalingAttributes)?.neptuneTargetUtilization ?? 75,
askAnswered: true,
when(answers: Answers) {
return answers.assetLibrary?.enableNeptuneAutoScaling
},
validate(answer: number) {
if (answer <= 0) {
return `You must enter number 1 or larger .`;
}
return true;
},
};
}