Skip to content

Commit 3c3408e

Browse files
authored
Merge pull request #21 from igfasouza/master
added new samples for Datadog and Syniverse
2 parents 06c5ba5 + 23cf0f0 commit 3c3408e

29 files changed

+861
-0
lines changed

samples/basic-observability/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Basic Observability Guidance
2+
3+
This example shows how you can get basic observability using out-of-the-box service metrics and alarms for
4+
* [Functions](functions.md)
5+
* [Notifications Service](notifications.md)
6+
* [Service Connector Hub](service-connector-hub.md)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Basic Guidance for Monitoring your Functions
2+
3+
This guide shows how you can use a simple email alert to monitor the status of your functions.
4+
5+
For more details, refer to the [technical documentation](https://docs.oracle.com/en-us/iaas/Content/Functions/Reference/functionsmetrics.htm).
6+
7+
8+
## Create a topic and a subscription for the Notification Service
9+
10+
1. From the [OCI Console](https://cloud.oracle.com) navigation menu, select **Application Integration**, and then select **Notifications**
11+
12+
2. Click **Create Topic** and create a topic with **my_function_status** name
13+
14+
3. Choose your topic, click **Create Subscription** and create a subscription with your email:
15+
* **Protocol**: Select Email
16+
* **Email**: Enter your email address
17+
18+
4. The subscription will be created in "Pending" status. You will receive a confirmation email
19+
and will need to click on the link in the email to confirm your email address.
20+
21+
22+
## Check Metrics and create an alarm definition from Metrics
23+
24+
1. From the navigation menu, select **Developer Services**, and then select **Functions**
25+
26+
2. Choose the application and the function that you want to monitor
27+
28+
3. From the Metrics page, go to the "Functions Errors" chart, click on **Options** and **Create an Alarm on this Query**
29+
30+
4. Add a **name** and under **Notifications** select **Destination service** as notification service, select the compartment **your_compartment**, and select **Topic** as my_function_status
31+
32+
33+
34+
## Create an alarm definition from scratch
35+
36+
1. From the navigation menu, select **Monitoring**, and then select **Alarm Definitions**
37+
38+
2. Click **Create Alarm** and use the following example:
39+
* **Alarm Name**: my_function_status
40+
* **Alarm severity**: Critical
41+
* **Alarm body**: OCI Alarm: my function
42+
43+
3. On **Metric description** select the compartment **your_compartment**, select **Metric namespace** as oci_faas, **Metric name** as FunctionResponseCount, **Interval** as 1m, and **Statistic** as Mean
44+
45+
4. On **Trigger rule** select Value greater than 1
46+
47+
6. On **Notification** select **Destination service** as notification service, select the compartment **your_compartment**, and select **Topic** as my_function_status
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Basic Guidance for Monitoring your Notifications Topics
2+
3+
This guide shows how you can use a simple email alert to monitor the status of your Oracle Notifications Service (ONS) Topics.
4+
5+
For more details, refer to the [technical documentation](https://docs.oracle.com/en-us/iaas/Content/Notification/Reference/notificationmetrics.htm).
6+
7+
## Create a topic and a subscription for the Notification Service
8+
9+
1. From the [OCI Console](https://cloud.oracle.com) navigation menu, select **Application Integration**, and then select **Notifications**
10+
11+
2. Click **Create Topic** and create a topic with **my_ons_status** name
12+
13+
3. Choose your topic, click **Create Subscription** and use the following example:
14+
* **Protocol**: Select Email
15+
* **Email**: Enter your email address
16+
17+
4. The subscription will be created in "Pending" status. You will receive a confirmation email
18+
and will need to click on the link in the email to confirm your email address.
19+
20+
21+
## Check Metrics and create an alarm definition from Metrics
22+
23+
1. From the navigation menu, select **Application Integration**, and then select **Notification**
24+
25+
2. Choose the notification topic that you want to monitor and click on **Metrics** link under **Resources** in the left navigation pane
26+
27+
3. From the chart that you want to add the alarm e.g. "Failed Messages Count", click on **Options** and **Create an Alarm on this Query**
28+
29+
4. Add a **name** and on **Notification** select **Destination service** as Notifications service, select the compartment **your_compartment**, and select **Topic** as my_ons_status
30+
31+
32+
## Create an alarm definition from scratch
33+
34+
1. From the navigation menu, select **Monitoring**, and then select **Alarm definitions**
35+
36+
2. Click **Create Alarm** and use the following example:
37+
* **Alarm Name**: my_ons_status
38+
* **Alarm severity**: Critical
39+
* **Alarm body**: OCI Alarm: my notification
40+
41+
3. On **Metric description** select the compartment **your_compartment**, select **Metric namespace** as oci_notification, **Metric name** as FailedMessagesSize, **Interval** as 1m, and **Statistic** as Sum
42+
43+
4. On **Trigger rule** select Value greater than 1
44+
45+
6. On **Notification** select **Destination service** as notification service, select the compartment **your_compartment**, and select **Topic** as my_ons_status
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Basic Guidance for Monitoring your Service Connectors
2+
3+
This guide shows how you can use a simple email alert to monitor the status of your Service Connectors.
4+
5+
For more details, refer to the [technical documentation](https://docs.oracle.com/en-us/iaas/Content/service-connector-hub/metrics.htm).
6+
7+
## Create a topic and a subscription for the Notification Service
8+
9+
1. From the [OCI Console](https://cloud.oracle.com) navigation menu, select **Application Integration**, and then select **Notifications**
10+
11+
2. Click **Create Topic** and create a topic with **my_sch_status** name
12+
13+
3. Choose your topic, click **Create Subscription** and use the following example:
14+
* **Protocol**: Select Email
15+
* **Email**: Enter your email address
16+
17+
4. The subscription will be created in "Pending" status. You will receive a confirmation email
18+
and will need to click on the link in the email to confirm your email address.
19+
20+
21+
## Check Metrics and create an alarm definition from Metrics
22+
23+
1. From the navigation menu, select **Logging**, and then select **Service Connectors**
24+
25+
2. Choose the connector that you want to monitor and click on **Metrics** link under **Resources** in the left navigation pane
26+
27+
3. From the metrics chart that you want to add the alarm e.g., "Service Connector Hub Errors", click on **Options** and **Create an Alarm on this Query**
28+
29+
4. Add a **name** and on **Notification** select **Destination service** as notification service, select the compartment **your_compartment**, and select **Topic** as my_sch_status
30+
31+
32+
## Create an alarm definition from scratch
33+
34+
1. From the navigation menu, select **Monitoring**, and then select **Alarm definitions**
35+
36+
2. Click **Create Alarm** and use the following example:
37+
* **Alarm Name**: my_sch_status
38+
* **Alarm severity**: Critical
39+
* **Alarm body**: OCI Alarm: my sch
40+
41+
3. On **Metric description** select the compartment **your_compartment**, select **Metric namespace** as oci_service_connector_hub, **Metric name** as ServiceConnectorHubErros, **Interval** as 1m, and **Statistic** as Mean
42+
43+
4. On **Trigger rule** select Value greater than 1
44+
45+
6. On **Notification** select **Destination service** as notification service, select the compartment **your_compartment**, and select **Topic** as my_sch_status

samples/oci-logs-datadog/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## Monitor Oracle Cloud Infrastructure with Datadog
2+
3+
Move logs from Oracle Cloud Infrastructure Logging service to Datadog for the following processes: Running analytics on service, audit, and custom logs in Datadog; Consolidating logs from multicloud and hybrid environments;
4+
5+
6+
![workflow](./images/workflow.png)
7+
8+
More
9+
- [Detailed Steps](https://docs.oracle.com/en/learn/logs_oci_datadog/#introduction)
10+
11+
12+
As you make your way through this tutorial, look out for this icon ![user input icon](./images/userinput.png).
13+
Whenever you see it, it's time for you to perform an action.
14+
15+
16+
## Prerequisites
17+
18+
Before you deploy this sample function, make sure you have run steps A, B
19+
and C of the [Oracle Functions Quick Start Guide for Cloud Shell](https://www.oracle.com/webfolder/technetwork/tutorials/infographics/oci_functions_cloudshell_quickview/functions_quickview_top/functions_quickview/index.html)
20+
* A - Set up your tenancy
21+
* B - Create application
22+
* C - Set up your Cloud Shell dev environment
23+
24+
25+
## List Applications
26+
27+
Assuming you have successfully completed the prerequisites, you should see your
28+
application in the list of applications.
29+
30+
```
31+
fn ls apps
32+
```
33+
34+
35+
## Review and customize the function
36+
37+
Review the following files in the current folder:
38+
* the code of the function, [func.py](./func.py)
39+
* its dependencies, [requirements.txt](./requirements.txt)
40+
* the function metadata, [func.yaml](./func.yaml)
41+
42+
43+
## Create a Datadog API key
44+
45+
* In your Datadog account, select Integrations, and under the APIs, click create API key. This will generate your API key.
46+
* Replace the value of the DATADOG_TOKEN in the [func.yaml](./func.yaml)
47+
48+
49+
## Deploy the function
50+
51+
In Cloud Shell, run the `fn deploy` command to build *this* function and its dependencies as a Docker image,
52+
push the image to the specified Docker registry, and deploy *this* function to Oracle Functions
53+
in the application created earlier:
54+
55+
![user input icon](./images/userinput.png)
56+
```
57+
fn -v deploy --app <app-name>
58+
```
59+
e.g.,
60+
```
61+
fn -v deploy --app myapp
62+
```
63+
64+
65+
### Test
66+
67+
In Cloud Shell, run the following `fn invoke` command to unit test this function:
68+
69+
![user input icon](./images/userinput.png)
70+
```
71+
fn invoke <app-name> <function-name> < test-logs.json
72+
```
73+
e.g.,
74+
```
75+
fn invoke myapp oci-logs-to-datadog-python < test-logs.json
76+
```
77+
78+
You should see the logs appear in Datadog.
79+
80+
81+
## Configure the logs you want to capture
82+
83+
1. From the [OCI Console](https://cloud.oracle.com) navigation menu, select **Logging**, and then select **Log Groups**.
84+
85+
2. Click Create Log Group, select your compartment, add a Name and Description
86+
87+
3. Select Logs in the left menu, click Enable Service Log, select your compartment, select Log Category on Service and fill the rest of the fields appropriately.
88+
89+
90+
## Create a Service Connector for reading logs from Logging and send to Functions
91+
92+
1. From the navigation menu, select **Logging**, and then select **Service Connectors**.
93+
94+
2. Click Create Connector, add a Name, Description, select the compartment, select the Source as **Logging** and Target as **Functions**.
95+
96+
3. On Configure Source connection, select the compartment, select the Log Group created earlier.
97+
98+
4. On Configure Target connection, select the compartment and select the Function. If prompted to create a policy for writing to functions, click Create.
99+
100+

samples/oci-logs-datadog/func.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# oci-logs-datadog version 1.0.
3+
#
4+
# Copyright (c) 2020 Oracle, Inc. All rights reserved.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
6+
#
7+
8+
import io
9+
import oci
10+
import os
11+
import json
12+
import requests
13+
import logging
14+
from fdk import response
15+
16+
17+
"""
18+
This Function receives the logging json and invokes the Datadog endpoint for ingesting logs.
19+
Logging Format Overview https://docs.cloud.oracle.com/en-us/iaas/Content/Logging/Reference/top_level_logging_format.htm#top_level_logging_format
20+
If this Function is invoked with more than one log the function go over each log and invokes the Datadog endpoint for ingesting one by one.
21+
"""
22+
def handler(ctx, data: io.BytesIO=None):
23+
try:
24+
logs = json.loads(data.getvalue())
25+
26+
# go over each log and invokes the Datadog endpoint for ingesting one by one.
27+
for item in logs:
28+
29+
# Datadog endpoint URL and token to call the REST interface. These values are defined in func.yaml
30+
datadoghost = os.environ['DATADOG_HOST']
31+
datadogtoken = os.environ['DATADOG_TOKEN']
32+
33+
# Call the Datadog with the payload.
34+
headers = {'Content-type': 'application/json', 'DD-API-KEY': datadogtoken}
35+
x = requests.post(datadoghost, data = json.dumps(item), headers=headers)
36+
logging.getLogger().info(x.text)
37+
38+
except (Exception, ValueError) as ex:
39+
logging.getLogger().info(str(ex))
40+
return

samples/oci-logs-datadog/func.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
schema_version: 20180708
2+
name: oci-logs-to-datadog-python
3+
version: 0.0.48
4+
runtime: python
5+
entrypoint: /python/bin/fdk /function/func.py handler
6+
config:
7+
DATADOG_HOST: https://http-intake.logs.datadoghq.com/v1/input
8+
DATADOG_TOKEN: ZZZZZzzzzz
2.96 KB
Loading
119 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fdk
2+
requests
3+
oci
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"results":[{"data":{"logContent":{"data":{"additionalDetails":{"bucketName":"bucket-test","eTag":"e34d66e8-ac09-4XXXxxxXXX9e885299be7","namespace":"yourTenancyName","publicAccessType":"NoPublicAccess","versioning":"Disabled"},"availabilityDomain":"PHX-AD-2","compartmentId":"ocid1.compartment.oc1..ZZZzzz","compartmentName":"syniverse-compartmment","definedTags":{},"eventGroupingId":"phx-1:hJX79im5JP-ZZZzzz","eventName":"CreateBucket","freeformTags":{},"identity":{"authType":"natv","callerId":null,"callerName":null,"consoleSessionId":null,"credentials":"ZZZzzz","ipAddress":"37.XXX.XXX.XXX","principalId":"ocid1.user.oc1..ZZZzzz","principalName":"ZZZzzz","tenantId":"ocid1.tenancy.oc1..ZZZzzz","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0"},"message":"Bucket created.","request":{"action":"POST","headers":{"Accept":["/"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["en"],"Connection":["keep-alive"],"Content-Length":["250"],"Origin":["https://object-storage.plugins.oci.oraclecloud.com"],"Referer":["https://object-storage.plugins.oci.oraclecloud.com/buckets"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0"],"authorization":["Signature keyId=\"XXXXXxxxdI-7ew\",version=\"1\",algorithm=\"rsa-sha256\",headers=\"(request-target) host content-length accept-language content-type opc-request-id x-content-sha256 x-date\",signature=\"*****\""],"content-type":["application/json"],"opc-request-id":["ZZZzzz"],"x-content-sha256":["1ZZZzzz="],"x-date":["Wed, 16 Dec 2020 11:44:39 GMT"]},"id":"phx-1:ZZZzzz","parameters":{"param0":["yourTenancyName"]},"path":"/n/yourTenancyName/b/"},"resourceId":"/n/yourTenancyName/b/","response":{"headers":{"Content-Length":["765"],"Content-Type":["application/json"],"access-control-allow-credentials":["true"],"access-control-allow-methods":["POST,PUT,GET,HEAD,DELETE,OPTIONS"],"access-control-allow-origin":["*"],"access-control-expose-headers":["access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,date,etag,location,opc-client-info,opc-request-id,x-api-id"],"date":["Wed, 16 Dec 2020 11:44:40 GMT"],"etag":["e34d66e8-ax5299be7"],"location":["https://objectstorage.us-phoenix-1.oraclecloud.com/n/tenancy_name/b/bucket-name-test"],"opc-request-id":["phx-1:ZZZzzz"],"x-api-id":["native"]},"message":null,"payload":{"id":"/n/yourTenancyName/b/","resourceName":"/n/test/b/"},"responseTime":"2020-12-16T11:44:40.003Z","status":"200"},"stateChange":{"current":{"bucketName":"bucket-_test","eTag":"ZZZzzz"},"previous":{}}},"dataschema":"2.0","id":"1158fbdexxxx0","oracle":{"compartmentid":"ocid1.compartment.oc1..aaaaaaaxxga","ingestedtime":"2020-12-16T11:44:48.648Z","loggroupid":"_Audit","tenantid":"ocid1.tenancy.oc1..ZZZzzz"},"source":"bucket-test","specversion":"1.0","time":"2020-12-16T11:44:40.003Z","type":"com.oraclecloud.objectstorage.createbucket"},"datetime":1608119080003,"oracle.tenantid":"ocid1.tenancy.oc1..ZZZzzz","oracle.compartmentid":"ocid1.compartment.oc1..ZZZzzz","oracle.loggroupid":"_Audit","specversion":"1.0","type":"com.oraclecloud.objectstorage.createbucket","source":"bucket-test","subject":null,"id":"1158x","time":"2020-12-16T11:44:40.003Z"}}],"summary":{"resultCount":1}}

0 commit comments

Comments
 (0)