Skip to content

Commit 5ed9e5d

Browse files
WMS ID 11728 - Configure a Java application to send application logs to Oracle Cloud Infrastructure (OCI) Logging using the Graal Development Kit for Micronaut (GDK) (oracle-livelabs#392)
* Adding gdk-oci-email workshop * Add more changes * Add build-and run sections * Update git-clone.md * Update git-clone * Follow Sachin P. comments * Follow Sachin P. comments * Update configure-app.md * Add more changes * Push more changes * Update manifest.json * Add more changes * Update git-clone.md * Additional changes * Minor updates * Update prepare-setup.md * Add minor changes * Update git-clone.md * minor fix * Add minor changes * Change OCI menu images * Change manifest.json files * Update configure-app.md * Update configure-app.md * Minor updates * Add gdk-oci-logging lab * Add more changes * Add more changes * Minor changes * Minor fix * Fix manifest.json files * Minor updates * update configure logging * Update configure-logging.md --------- Co-authored-by: Sachin Pikle <[email protected]>
1 parent f402a8c commit 5ed9e5d

30 files changed

+1074
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Introduction
2+
3+
## About this Workshop
4+
5+
This workshop takes you step by step through the process of configuring a Java application to send application logs to Oracle Cloud Infrastructure (OCI) Logging using the Graal Development Kit for Micronaut (GDK). You'll use GraalVM Native Image to package and run the application as a native executable.
6+
7+
It is aimed at application developers and DevOps engineers with a basic knowledge of Java.
8+
9+
Estimated Workshop Time: 75 minutes
10+
11+
### What is Graal Development Kit for Micronaut?
12+
13+
The [Graal Development Kit for Micronaut (GDK)](https://graal.cloud/gdk) is an Oracle build of the open source Micronaut® framework. The GDK provides a curated set of Micronaut framework modules that simplify cloud application development, are designed for ahead-of-time compilation with GraalVM Native Image, and are fully supported by Oracle. The GDK also provides project creation utilities, VS Code and IntelliJ extensions to simplify application development and deployment.
14+
15+
### What is Micronaut?
16+
17+
The [Micronaut® framework](https://micronaut.io/) is a modern, JVM-based framework to build modular, easily testable microservice and serverless applications. By avoiding runtime reflection in favor of annotation processing, Micronaut improves the Java-based development experience by detecting errors at compile time instead of runtime, and improves Java-based application startup time and memory footprint. Micronaut includes a persistence framework called Micronaut Data that precomputes your SQL queries at compilation time making it a great fit for working with databases like MySQL, Oracle Autonomous Database, etc.
18+
19+
> Micronaut® is a registered trademark of Object Computing, Inc. Use is for referential purposes and does not imply any endorsement or affiliation with any third-party product.
20+
21+
### What is GraalVM Native Image?
22+
23+
[GraalVM Native Image](https://www.graalvm.org/) technology compiles Java applications ahead-of-time into self-contained native executables that are small in size, start almost instantaneously, provide peak performance with no warmup, and require less memory and CPU. Only the code that is required at run time by the application gets added into the executable file. Native Image is perfect for containerized workloads and microservices — which is why it has been embraced by Micronaut, Spring Boot, Helidon, and Quarkus.
24+
25+
The GDK modules are designed for ahead-of-time compilation with GraalVM Native Image to produce native executables that are ideal for microservices: they have a small memory footprint, start instantly, and provide peak performance with no warmup.
26+
27+
> Graal Development Kit for Micronaut, and Oracle GraalVM are available at no additional cost on Oracle Cloud Infrastructure (OCI).
28+
29+
### Objectives
30+
31+
In this workshop, you will:
32+
33+
* Use Visual Studio Code (VS Code) from a remote desktop running in an OCI Compute Instance
34+
* Review the application source code developed with the Graal Development Kit for Micronaut
35+
* Configure OCI Logging:
36+
* Create a Log Group
37+
* Create a Custom Log
38+
* Build a native executable for the application using GraalVM Native Image
39+
* Run the application and send application logs to OCI Logging
40+
* Browse the application logs using the Oracle Cloud Console
41+
42+
### Prerequisites
43+
44+
This workshop assumes you have:
45+
46+
* Some familiarity with Oracle Cloud Infrastructure (OCI)
47+
* Understanding of the Java programming language
48+
* Oracle GraalVM for JDK 17
49+
* Visual Studio Code (VS Code)
50+
* A browser with access to the internet
51+
* An Oracle Cloud Infrastructure (OCI) account with adequate permissions
52+
53+
## Learn More
54+
55+
* [Graal Development Kit for Micronaut](https://graal.cloud/gdk/)
56+
57+
## Acknowledgements
58+
59+
* **Author** - [](var:author)
60+
* **Contributors** - [](var:contributors)
61+
* **Last Updated By/Date** - [](var:last_updated)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Prepare Setup
2+
3+
## Introduction
4+
5+
This lab will show you how to download the Oracle Resource Manager (ORM) stack zip file needed to set up the resources needed to run this workshop.
6+
7+
*Estimated Lab Time:* 5 minutes
8+
9+
### Objectives
10+
11+
* Download ORM stack
12+
* (*Optional*) Configure an existing Virtual Cloud Network (VCN)
13+
* Select a Compartment for the workshop
14+
15+
### Prerequisites
16+
17+
This lab assumes you have:
18+
19+
* An Oracle Cloud account
20+
21+
## Task 1: Download Oracle Resource Manager (ORM) stack zip file
22+
23+
1. Click on the link below to download the Resource Manager zip file you need to build your environment:
24+
25+
* [gdk-oci-logging-ll-orm.zip](https://c4u04.objectstorage.us-ashburn-1.oci.customer-oci.com/p/EcTjWk2IuZPZeNnD_fYMcgUhdNDIDA6rt9gaFj_WZMiL7VvxPBNMY60837hu5hga/n/c4u04/b/livelabsfiles/o/oci-library/gdk-oci-logging-ll-orm.zip)
26+
27+
2. Save it in your downloads folder.
28+
29+
3. (*Recommended*) We strongly recommend using this stack to create a new self-contained/dedicated VCN along with your instance. Skip to **Task 3** to follow the recommendation.
30+
31+
4. Alternatively, if you would rather use an existing VCN then proceed to the next task to update your existing VCN with the required network security rules.
32+
33+
## Task 2: Add Network Security Rules to an Existing VCN
34+
35+
This workshop requires a certain number of ports to be available, a requirement that is automatically met by using the default ORM stack execution that creates a new dedicated VCN.
36+
37+
However, if you would rather use an existing VCN/subnet, follow these steps to add the following rules to the network security list.
38+
39+
1. From the Oracle Cloud Console navigation menu, go to **Networking >> Virtual Cloud Networks**.
40+
2. Choose your network.
41+
3. Under **Resources**, select **Security Lists**.
42+
4. Click on **Default Security Lists** under the **Create Security List** button.
43+
5. Click **Add Ingress Rules** button.
44+
6. Create a rule for each row in the *Ingress* table below:
45+
46+
| Stateless | Source Type | Source CIDR | IP Protocol | Source Port Range | Destination Port Range | Description |
47+
| :------------- | :---------: | :---------: | :---------: | :---------------: | :--------------------: | :------------------------- |
48+
| No (unchecked) | CIDR | 0.0.0.0/0 | TCP | All | 80 | Remote Desktop using noVNC |
49+
| No (unchecked) | CIDR | 0.0.0.0/0 | TCP | All | 6080 | Remote Desktop using noVNC |
50+
{: title="Network Ingress Security Rules"}
51+
52+
7. Select **Egress Rule** from the left panel.
53+
8. Click **Add Egress Rule** button
54+
9. Create a rule for each row in the *Egress* table below:
55+
56+
| Stateless | Source Type | Destination CIDR | IP Protocol | Source Port Range | Destination Port Range | Description |
57+
| :------------- | :---------: | :--------------: | :---------: | :---------------: | :--------------------: | :-------------------- |
58+
| No (unchecked) | CIDR | 0.0.0.0/0 | TCP | All | 80 | Outbound HTTP access |
59+
| No (unchecked) | CIDR | 0.0.0.0/0 | TCP | All | 443 | Outbound HTTPS access |
60+
{: title="Network Egress Security Rules"}
61+
62+
## Task 3: Select a Compartment for the Workshop
63+
64+
We recommend you use a single compartment for the workshop. We will refer to this as your workshop compartment. This is the compartment where you will provision all the resources - Oracle Resource Manager (ORM) Stack, Compute Instance, VCN/Subnet, Instance Principals, Policies - needed for the workshop.
65+
66+
1. From the Oracle Cloud Console navigation menu, go to **Identity & Security >> Identity >> Compartments**.
67+
2. Go to your workshop compartment.
68+
3. Make a note of the compartment name and OCID. You will need this information in subsequent labs.
69+
70+
## Task 4: Setup Compute
71+
72+
Using the details from the above Tasks, proceed to the **Environment Setup** lab to set up your workshop environment using Oracle Resource Manager (ORM) with one of the following options:
73+
74+
* (*Recommended*) Create Stack: **Compute + Networking**
75+
* Create Stack: **Compute only** with an existing VCN where security lists have been updated as per **Task 2** above
76+
77+
The ORM stack will provision a compute instance with 4 OCPUs, 64 GB RAM and a Remote Desktop environment.
78+
79+
You may now **proceed to the next lab**.
80+
81+
## Acknowledgements
82+
83+
* **Author** - [](var:author)
84+
* **Contributors** - [](var:contributors)
85+
* **Last Updated By/Date** - [](var:last_updated)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Clone the Sample Application Source Code
2+
3+
## Introduction
4+
5+
This lab describes the steps to download the sample application source code used in the workshop.
6+
7+
Estimated Lab Time: 5 minutes
8+
9+
### Objectives
10+
11+
In this lab, you will:
12+
13+
* Clone the sample application source code
14+
15+
## Task 1: Clone the Sample Application Source Code
16+
17+
1. From the **Activities** menu, start a new **Terminal** window.
18+
19+
2. Clone the sample application source code.
20+
21+
```bash
22+
<copy>
23+
git init lab
24+
cd lab
25+
git remote add origin https://github.com/sachin-pikle/gdk-oci-samples.git
26+
git config core.sparsecheckout true
27+
echo "gdk-oci-logging-mvn/*">>.git/info/sparse-checkout
28+
git pull --depth=1 origin main
29+
</copy>
30+
```
31+
32+
3. Open the sample application source code from the _gdk-oci-logging-mvn_ directory in **Visual Studio Code**.
33+
34+
```bash
35+
<copy>
36+
code gdk-oci-logging-mvn
37+
</copy>
38+
```
39+
40+
4. VS Code may show a dialog box with the message "Do you trust the authors of the files in this folder?". Select **Trust the authors of all files in the parent folder 'oracle'** and click **Yes, I trust the authors**.
41+
42+
5. VS Code may ask you to choose a password for new keyring. Press **Cancel** twice to close the prompt.
43+
44+
6. VS Code may show a dialog box with the message "A git repository was found in the parent folders of the workspace or the open file(s). Would you like to open the repository?". Click **Never**.
45+
46+
![VS Code Question Icon](images/vs-code-question-icon.jpg#input)
47+
48+
You may now **proceed to the next lab**.
49+
50+
## Acknowledgements
51+
52+
* **Author** - [](var:author)
53+
* **Contributors** - [](var:contributors)
54+
* **Last Updated By/Date** - [](var:last_updated)
29.4 KB
Loading
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Review the Sample Application Source Code
2+
3+
## Introduction
4+
5+
This lab reviews the sample Micronaut application code used in the workshop. The application source code and build scripts are available for review in VS Code.
6+
7+
You'll see how easy it is to configure a Micronaut application to send logs to OCI Logging with the GDK.
8+
9+
Estimated Time: 10 minutes
10+
11+
### Objectives
12+
13+
In this lab, you will:
14+
15+
* Review the sample application source code
16+
17+
## Task 1: Review the Application Dependencies
18+
19+
The build file contains the following dependency to support the [Logback](https://logback.qos.ch/) appender that pushes logs to Oracle Cloud.
20+
21+
_oci/pom.xml_
22+
23+
<dependency>
24+
<groupId>io.micronaut.oraclecloud</groupId>
25+
<artifactId>micronaut-oraclecloud-logging</artifactId>
26+
<scope>compile</scope>
27+
</dependency>
28+
29+
30+
## Task 2: Review the Controller
31+
32+
Our application contains a simple controller class, named `GreetingController`, containing a single method `greet` which is invoked by an HTTP POST request. The method has an informational log statement to log the greeting message.
33+
34+
_lib/src/main/java/com/example/GreetingController.java_
35+
36+
``` java
37+
import org.slf4j.Logger; // <1>
38+
import org.slf4j.LoggerFactory; // <1>
39+
40+
@Controller
41+
class GreetingController {
42+
43+
private static final Logger LOG = LoggerFactory.getLogger(GreetingController.class); // <2>
44+
45+
@Post("/greet")
46+
void greet(@Body String message) {
47+
LOG.info(message); // <3>
48+
}
49+
}
50+
```
51+
52+
1. Import the Simple Logging Facade for Java (SLF4J) Logger and LoggerFactory classes. SLF4J serves as a simple facade or abstraction for various logging frameworks, such as `java.util.logging`, `logback` and `reload4j`. SLF4J enables the user to plug in the desired logging framework at deployment time.
53+
54+
2. Get a logger with the class name.
55+
56+
3. This logger is in turn used to log the message received in each POST request.
57+
58+
## Task 3: Review the Logback configuration
59+
60+
The Logback configuration has been modified by adding the `OracleCloudAppender` to send log statements to OCI Logging in addition to `STDOUT`.
61+
62+
_oci/src/main/resources/logback.xml_
63+
64+
<configuration debug='false'>
65+
66+
<appender name='STDOUT' class='ch.qos.logback.core.ConsoleAppender'>
67+
<encoder>
68+
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
69+
</encoder>
70+
</appender>
71+
<appender name='ORACLE' class='io.micronaut.oraclecloud.logging.OracleCloudAppender'>
72+
<!-- <appender-ref ref='STDOUT'/> -->
73+
<logId><!-- TODO set the value of the Oracle Cloud log OCID here --></logId>
74+
<encoder class='ch.qos.logback.core.encoder.LayoutWrappingEncoder'>
75+
<layout class='ch.qos.logback.contrib.json.classic.JsonLayout'>
76+
<jsonFormatter class='ch.qos.logback.contrib.jackson.JacksonJsonFormatter'/>
77+
</layout>
78+
</encoder>
79+
</appender>
80+
81+
<root level='INFO'>
82+
<appender-ref ref='ORACLE'/>
83+
<appender-ref ref='STDOUT'/>
84+
</root>
85+
86+
</configuration>
87+
88+
In the next section, you will configure OCI Logging and include the OCI Log OCID in the _logback.xml_ file.
89+
90+
You may now **proceed to the next lab**.
91+
92+
## Acknowledgements
93+
94+
* **Author** - [](var:author)
95+
* **Contributors** - [](var:contributors)
96+
* **Last Updated By/Date** - [](var:last_updated)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Configure OCI Logging
2+
3+
## Introduction
4+
5+
This lab provides instructions to configure the OCI Logging service.
6+
7+
Estimated Lab Time: 05 minutes
8+
9+
### Objectives
10+
11+
In this lab, you will:
12+
13+
* Create a Log Group
14+
* Create a Custom Log
15+
16+
## Task 1: Create a Log Group
17+
18+
1. From the Oracle Cloud Console navigation menu, go to **Observability & Management**. Under **Logging**, click **Log Groups**.
19+
20+
![Logging Menu](https://oracle-livelabs.github.io/common/images/console/logging.png)
21+
22+
2. Under **List scope**, select your workshop compartment.
23+
24+
![Select Compartment Button](images/select-compartment-button.jpg)
25+
26+
3. Click **Create Log Group**.
27+
28+
![Create Log Group Button](images/log-group-create-button.jpg#input)
29+
30+
4. You will see the **Create Log Group** screen. Enter the Name as "MicronautLogGroup". Click **Create** to create the Log Group.
31+
32+
![Create Log Group Screen](images/log-group-create-screen.jpg#input)
33+
34+
## Task 2: Create a Custom Log
35+
36+
1. From the **MicronautLogGroup** details screen, click **Logs** under **Resources**. Click **Create custom log**.
37+
38+
![Create Custom Log Button](images/custom-log-create-button.jpg#input)
39+
40+
2. You will see the **Create custom log** wizard. Enter the Custom log name as "MicronautCustomLog". Select Log group as "MicronautLogGroup" from the drop down list (if it's not already selected). Click **Create custom log** to proceed to **Create agent config**.
41+
42+
![Create Custom Log Screen 1](images/custom-log-create-screen-1.jpg#input)
43+
44+
3. On the **Create agent configuration** screen, select the **Add configuration later** option. Click **Create agent config**.
45+
46+
![Create Custom Log Screen 2](images/custom-log-create-screen-2.jpg#input)
47+
48+
4. From the Logs list, click **MicronautCustomLog** to go to the Log details screen.
49+
50+
![Open MicronautCustomLog](images/micronaut-custom-log-open.jpg#input)
51+
52+
15. From the **Log Information** tab of the **MicronautCustomLog** details screen, click **Copy** to copy the Log OCID. You’ll need it to configure the application in the next step.
53+
54+
![Copy MicronautCustomLog OCID](images/micronaut-custom-log-copy-ocid.jpg#input)
55+
56+
Congratulations! In this lab, you configured OCI Logging by creating a Log Group and a Custom Log object.
57+
58+
You may now **proceed to the next lab**.
59+
60+
## Acknowledgements
61+
62+
* **Author** - [](var:author)
63+
* **Contributors** - [](var:contributors)
64+
* **Last Updated By/Date** - [](var:last_updated)
245 KB
Loading
156 KB
Loading
148 KB
Loading
57.2 KB
Loading

0 commit comments

Comments
 (0)