Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Set Up Database autoscaling using Oracle Cloud Infrastructure Cloud Native Services
Introduction
Setting up autoscaling is part of and requirement of every team hosting their applications on cloud.
For database instances like Oracle Autonomous Data Warehouse (ADW) and Oracle Autonomous Transaction Processing (ATP), we can set up autoscaling using Oracle Cloud Infrastructure (OCI) cloud native services.
Objectives
-
Set up autoscaling based on metrics other than CPU.
-
Configure using cloud native managed services on OCI.
Prerequisites
-
Have required access permissions in Oracle Cloud Infrastructure Identity and Access Management (OCI IAM) to create dynamic group, IAM policy, create functions, update ADW/ATP CPUs count and notification service.
-
Access to all required components to view their OCIDs and other relevant information.
-
Access to OCI Cloud Shell so that you can create, deploy and invoke the functions.
Task 1: Set up required IAM policies and dynamic groups
-
Log in to OCI console using this link.
-
Once logged in, go to IAM Dynamic Group and create a new dynamic group as below:
-
Provide the compartment OCID to the rule as below. Your database instance should exist in this compartment:
-
Go to IAM policies and create an IAM policy with this statement:
allow dynamic-group dynamic_group_name to manage autonomous-database-family in compartment compartment_name
Task 2: Create and deploy the function code
-
Go to functions/applications and create a function. This function will use the IAM Dynamic Group and Policy to access the ADW and perform the required scaling (both up and down) when the function is triggered. Follow the steps on screen to create the function. We have used Python to code the required logic, but you can use your own language and change the logic as needed. To write the code, open the function
requirement.txt
file andfunc.py
file in OCI Cloud Shell and write the code. -
Get the full function code from this repo, it also uses the OCI Resource Principals so that you don’t have to worry about keeping your OCI credentials here.
-
Once you have finished writing the code, update the function in registry and deploy the latest code using this command on the cloud shell:
fn -v deploy — app e2e-function-demo
-
Once deployed, your function is ready to be invoked. You can try to test using the function invoke command and once you are sure the function is working as required, you can move to next section.
DEBUG=1 fn invoke e2e-function-demo e2e-fn-streaming
NOTE:
OCI supports resource/instance principals to avoid providing any user related information while executing the function. So this step is needed to make sure the function has the correct permission set to call the APIs, failing which the function will not work properly.
Optional: You can also check the Debug mode, for troubleshooting. For example: Run this command from the cloud shell to invoke and test the function if it is working as expected:
DEBUG=1 fn invoke e2e-function-demo e2e-fn-streaming
.`
Task 3: Set up notifications and configure alarm
-
Let’s create a topic which will trigger the function created. Go to Notifications, Topic and create a topic.
-
Then create a subscription in the created topic and point it to function created.
Now our topic is also configured.
-
We need to set up the alarm, provide a trigger condition and then add the Topic created above as trigger destination. For this, go to the desired database instance and scroll down to the metric for which you want to create the alarm on, and click on the options and then click Create an alarm on this query option.
-
Fill details like name and description and select the severity
-
Set up the metric description, provide values for metric namespace, name, interval and statistic.
-
Provide the details for metric dimensions and trigger rule. You can also set the trigger rule using advanced query as described in this doc: Building Metric Queries.
-
Provide the created topic details which will trigger the function when the condition matches.
-
-
Save the alarm. This will trigger the alarm and invoke the function when the condition matches.
Related Links
Acknowledgments
- Lovelesh Saxena (Cloud Engineering Architect)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Set Up Database autoscaling using Oracle Cloud Infrastructure Cloud Native Services
F84886-01
August 2023
Copyright © 2023, Oracle and/or its affiliates.