Adding "Auto Scaling" to the Oracle Database Cloud Service - Step 3: Service Connector Hub

This is the step 3 of adding "Auto Scaling" to the Oracle Database Cloud Service.
If you want to check the other steps, please click the below links respectively.

- Step 1: [Gather OCI DB System CPU Usage and write it into a custom log](https://qiita.com/RexZheng/items/797ab17177f1c44f2a28) 
- Step 2: [Configure OCI Logging service to ingest the custom log](https://qiita.com/RexZheng/items/f785c1337bfce82c755a)
- Step 3: [Configure OCI Service Connector Hub service to transfer the custom log to OCI Functions](https://qiita.com/RexZheng/items/5b417c1c3b80b49cd0ec)
- Step 4: [Configure OCI Functions to act accordingly based on the CPU usage in the custom log](https://qiita.com/RexZheng/items/874372ad22d18a42a3e1)

## Configure OCI Service Connector Hub service to transfer the custom log to OCI Functions

By completing step 1: Gather OCI DB System CPU Usage and write it into a custom log and step 2: Configure OCI Logging service to ingest the custom log, we have successfully gathered, ingested and uploaded the custom log into OCI Logging service. As mentioned at the very beginning, our final target is using OCI Functions to scale up the DB System according to the CPU Usage information in the log.

So obviously, next action that we need to do is to transfer the ingested custom log from OCI Logging service to the OCI Functions. Service Connector Hub is the right service to do so.

Below the a brief introduction of Service Connector Hub excerpted from the official document.

> Service Connector Hub is a cloud message bus platform that offers a single pane of glass for describing, executing, and monitoring movement of data between services in Oracle Cloud Infrastructure.
>
> Service Connector Hub orchestrates data movement between services in Oracle Cloud Infrastructure.
>
> Data is moved using service connectors. A service connector specifies the source service that contains the data to be moved, tasks to run on the data, and the target service for delivery of data when tasks are complete.

Below is the flow of data in Service Connector Hub. As we can see, Logging is supported as source, and Functions is supported as target. That's the right one we need.

[Figure: flow of data in SCH]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/c3163f55-a964-1dbb-b476-8beb2ce7f992.png)


## Prerequisite

To create a Service Connector Hub, we need existing Logging and Functions as source and target. The Custom log in OCI Logging service has been created in step 2, so we don't need to worry about the source. But for the target side, we have not created the real Function to handle the custom log yet.

But, We should have completed some basic tasks of OCI Functions. Otherwise, it will be very hard for you to move to next step: Configure OCI Functions to act accordingly based on the CPU usage in the custom log.

So, as a prerequisite, please follow the document [Configuring Your Client Environment for Function Development](https://docs.cloud.oracle.com/en-us/iaas/Content/Functions/Tasks/functionsconfiguringclient.htm#Configuring_Your_Client_Environment_for_Function_Development) and complete the Quick Start Guide.

There are three options to setup the Functions development environment. I choose the local machine option and you can choose any one as you wish.

If you have completed the Quick Start Guide, there should be an Application and a Function exists. Once we invoke the Function, it should return a message.

In below screenshot, the Function `sayhi` is a simple function and it will response "Hello, <Name>" when we invoke it. In next section we will use this Function to test the Service Connector Hub.

[Figure: function - sayhi]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/81bd48d3-612a-2896-d1cb-03fbb7392f1b.png)


## Create a Service Connector Hub

Frankly, creating a Service Connector Hub is quite easy, as long as we have prepared the source and target.

Follow the steps of the below screenshots to create a SCH.

[Figure: visit SCH]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/e7051be5-e16d-bf5f-8e5f-ce1adb96c05f.png)

[Figure: Create SCH]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/d0e4eba6-4fa8-efd2-7f9c-7c18cb5daf20.png)

When inputting the details of the SCH, we select the created Custom Log as source and the simple Function as target.

[Figure: create SCH, details]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/4b0a45ec-3a3c-e448-98e2-867c60f7e453.png)

## Verify the Service Connector Hub

From the web console, we know that the SCH is `ACTIVE`, that means it is running. But is it running as expected? Is it transferring logs from Logging to the Function? Most important, is the Function being invoked?

To verify whether the SCH is working, we can check the metrics of the SCH like below.

[Figure: SCH Metrics]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/79dbd2fa-1481-023f-0c85-2b8ab4d70444.png)

To verify whether the Function is invoked, we can enable Log of the Application and check the log in Logging service.


[Figure: Enable Function Application Log]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/2024b265-3251-4312-afc3-7805bcede758.png)

From the Function invoke log, we can see that the Function has been invoked successfully.

[Figure: Function invoke log]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/c64d6875-f1ce-892b-bb48-d2d93f5acecf.png)


## Transfer Custom Log from Logging to Object Storage

Remember the Log Retention in Logging service? The longest retention we can select is 6 months, what if we want to retain the logs longer? The easiest way is to use Service Connector Hub. We can simply create a SCH to connect Logging and Object Storage, and transfer the logs to a specific bucket.

[Figure: Create SCH, connect Logging to Object Storage]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/136eaa60-b51c-635f-8e08-0ff1d4de07e0.png)


## Next

[Figure: Step 3 completed]
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/100411/7df02112-5e74-dda2-d8ac-2e1b46918f43.png)

Until now, we have completed the step 3: **Configure OCI Service Connector Hub service to transfer the custom log to OCI Functions**. We created a Service Connector Hub to transfer the custom log from Logging to the Functions and Object Storage, and we confirmed that the SCH is working as expected.

In next step, we will continue to complete the final step, step 4: **Configure OCI Functions to act accordingly based on the CPU usage in the custom log**