Add Oracle Management Cloud Integration

You can upload the configured image over to the Oracle Container Registry or any other container registry and create a deployment manifest to deploy the application to your Kubernetes cluster. Once you have the distributed application ready, you can monitor it and seamlessly keep track of new instances that are created as well as the instances that are shut down.

To make the Oracle Application Performance Monitoring agent installation simpler and descriptive, download the installer from Oracle Management Cloud and save the registration key in a file.

Download the Oracle Application Performance Monitoring agent binaries and the registration key:

  • Download the agent binaries: From the Oracle Management Cloud console, navigate to Administration > Agents > Download Agents.
  • Download the registration key: From the Oracle Management Cloud console, navigate to Administration > Agents > Manage Registration Keys.

Save the Oracle Management Cloud installer binaries and the registration key in the gs-accessing-data-rest/complete/src/dist directory (you need to create the dist directory).

You need to register your applications with Oracle Management Cloud. To add Oracle Management Cloud integration, obtain the binaries and perform the agent installation at the time you create the Docker image. To do this, you leverage the gradle-docker-plugin plug-in to add a few more instructions into the Dockerfile that you're generating.

Add the following to your build.gradle file:

dockerCreateDockerfile {
    instruction {'RUN unzip /omc-sample-app/*APM*.zip -d /omc-sample-app/omc'}
    instruction {'COPY /omc-sample-app/registrationKey.txt /omc-sample-app/omc'}
    instruction {'WORKDIR /omc-sample-app/omc'}
    instruction {'RUN /bin/bash ProvisionApmJavaAsAgent.sh -d . -h do-not-use -no-wallet -no-prompt -regkey-file registrationKey.txt'}
    instruction {'ENV APM_PROP_FILE=/omc-sample-app/omc/apmagent/config/AgentStartup.properties'}
    instruction {'RUN echo "oracle.apmaas.agent.appServer.classifications=OMC_SAMPLE" >> ${APM_PROP_FILE}'}
    environmentVariable('JAVA_OPTS', '${JAVA_OPTIONS} -javaagent:/omc-sample-app/omc/apmagent/lib/system/ApmAgentInstrumentation.jar')
}

The preceding lines of code first extract the agent JAR file and copy the registration key as a file. Then the code runs the installer, ProvisionApmJavaAsAgent.sh. The process installs the agent and then adds a configuration to group all instances of this container to a classification called OMC_SAMPLE. Finally, the code adds the javaagent parameter to the JAVA_OPTS environment variable. This environment variable enables you to externalize some options used when the JVM is started. Here, it's used to add the agent.

Now every container you start up using this image automatically has the agent integrated into it. As soon as the container starts, it starts reporting metrics to the Oracle Management Cloud. Moreover, all the instances will be grouped together by Oracle Management Cloud using the classification that you've added. This enables you to automatically monitor your Oracle Container Engine for Kubernetes deployments as a group as opposed to individual pods or containers, or setting up custom queries or labels to group nodes.

Here's a sample build.gradle with all the entries:

buildscript {
    repositories {
        mavenCentral()
        maven {
                url 'https://plugins.gradle.org/m2/'
            }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
        classpath 'com.bmuschko:gradle-docker-plugin:4.3.0'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'
apply plugin: 'com.bmuschko.docker-java-application'

mainClassName = 'hello.Application'


jar {
    enabled = true
    baseName = 'gs-accessing-data-rest'
    version = '0.1.0'
}

bootJar {
    baseName = 'gs-accessing-data-rest'
    version = '0.1.0'
}

repositories {
    mavenCentral()
    jcenter()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

docker {
        javaApplication {
            baseImage = 'openjdk:8'
            maintainer = 'Your Name "your.email@company.com"'
            ports = [8080]
            tag = 'region-code.ocir.io/my-tenant/my-repo/omc-sample-app:latest'
        }
}

dockerCreateDockerfile {
        instruction 'RUN unzip /omc-sample-app/*APM*.zip -d /omc-sample-app/omc'
        instruction 'COPY /omc-sample-app/registrationKey.txt /omc-sample-app/omc'
        instruction 'WORKDIR /omc-sample-app/omc'
        instruction 'RUN /bin/bash ProvisionApmJavaAsAgent.sh -d . -h do-not-use -no-wallet -no-prompt -regkey-file registrationKey.txt'
        instruction 'ENV APM_PROP_FILE=/omc-sample-app/omc/apmagent/config/AgentStartup.properties'
        instruction 'RUN echo "oracle.apmaas.agent.appServer.classifications=OMC_SAMPLE" >> ${APM_PROP_FILE}'
        environmentVariable 'JAVA_OPTS', '${JAVA_OPTIONS} -javaagent:/omc-sample-app/omc/apmagent/lib/system/ApmAgentInstrumentation.jar' 
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("com.h2database:h2")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}