Google App Engine

Google App Engine

Google App Engine (GAE) is highly scalable application system on a fully managed serverless platform.

We need to run the Instana agent in the same container where main application is running.

GAE Custom runtime

The Custom Runtime allows you to include additional components like language interpreters, application servers or additional apps to your environment.

Building a container

Instana agent Dockerfile is available on GitHub and is an excellent starting point to monitor your apps on within GAE.

Checkout Instana agent Docker repository

$ git checkout 'https://github.com/instana/instana-agent-docker.git'
$ cd instana-agent-docker

Modification to support Java

To support running Java based apps, the Dockerfile must be modified and it has to contain:

  • All variables needed by Instana agent
  • Instana agent repository configuration
  • Java installation
  • Instana agent configuration files
  • replace java_app_name.jar with your application
  • update main-process script for running Java application
FROM alpine:3.7 

ENV LANG=C.UTF-8 \
    INSTANA_AGENT_KEY="" \
    INSTANA_AGENT_ENDPOINT="" \
    INSTANA_AGENT_ENDPOINT_PORT="" \
    INSTANA_AGENT_ZONE="" \
    INSTANA_AGENT_TAGS="" \
    INSTANA_AGENT_HTTP_LISTEN="" \
    INSTANA_AGENT_PROXY_HOST="" \
    INSTANA_AGENT_PROXY_PORT="" \
    INSTANA_AGENT_PROXY_PROTOCOL="" \
    INSTANA_AGENT_PROXY_USER="" \
    INSTANA_AGENT_PROXY_PASSWORD="" \
    INSTANA_AGENT_PROXY_USE_DNS=""

RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    apk update && \
    apk upgrade && \
    apk add --update-cache --update gomplate@edge bash ca-certificates curl docker@edge inotify-tools && \
    curl -sSL https://packages.instana.io/Instana.rsa -o /etc/apk/keys/instana.rsa.pub && \
    echo "https://_:YOUR_INSTANA_AGENT_HERE@packages.instana.io/agent/apk/generic" >> /etc/apk/repositories && \ 
    apk update && \
    apk add instana-agent-dynamic && \
    ( /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 C.UTF-8 || true ) && \
    echo "export LANG=C.UTF-8" > /etc/profile.d/locale.sh && \
    sed -i '$d' /etc/apk/repositories && \
    rm -rf /tmp/* /var/cache/apk/*

# Install OpenJDK-8
RUN apk update && \
    apk --update add openjdk8-jre

ADD org.ops4j.pax.logging.cfg /root/
ADD org.ops4j.pax.url.mvn.cfg /root/
ADD configuration.yaml /root/
ADD com.instana.agent.main.sender.Backend.cfg.tmpl /root/
ADD mvn-settings.xml.tmpl /root/

# This is run.sh from repository renamed to instana-agent
ADD instana-agent /root

# Add jar file and main-process
ADD java_app_name.jar /root
ADD main-process /root

# Wrapper is used to run both processes in the same container
COPY wrapper.sh /root

WORKDIR /root

ENTRYPOINT ["./wrapper.sh"]

Rename run.sh to instana-agent.

Create a new file called main-process and add this content to it:

java -jar /root/java_app_name.jar &

Create wrapper.sh file:

#!/bin/bash

# Start the first process

./main-process -D
status=$?
if [ $status -ne 0 ]; then
  echo "Failed to start main-process: $status"
  exit $status
fi

# Start the second process
./instana-agent -D
status=$?
if [ $status -ne 0 ]; then
  echo "Failed to start instana-agent: $status"
  exit $status
fi

while sleep 60; do
  ps aux |grep main-process |grep -q -v grep
  PROCESS_1_STATUS=$?
  ps aux |grep instana-agent |grep -q -v grep
  PROCESS_2_STATUS=$?
  # If the greps above find anything, they exit with 0 status
  # If they are not both 0, then something is wrong
  if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
    echo "One of the processes has already exited."
    exit 1
  fi
done

Modification to support NodeJS

The process is much like the Java application. Instead of Java, install NodeJS and the instana-nodejs-sensor:

ADD package.json /root
ADD app.js /root/
# Install NodeJS
RUN apk update && \
    apk --update add nodejs nodejs-npm
RUN npm install --save instana-nodejs-sensor

The main-process file needs instruction how to run your NodeJS app:

node app.js &

Summary

  • Instana agent key must be placed in Dockerfile in order to install Instana agent
  • main-process is used to start Java process
  • instana-agent is used to start Instana agent process (renamed from run.sh)
  • wrapper is used to start both processes

GAE manifest file

After adding and modifying all necessary files in previous steps we can add a GAE manifest file that describes the GAE instance.

runtime: custom
env: flex

service: gae-java-app

manual_scaling:
  instances: 1

env_variables:
  INSTANA_AGENT_KEY: 'YOUR_INSTANA_AGENT_KEY'
  INSTANA_AGENT_ENDPOINT: 'saas-us-west-2.instana.io'
  INSTANA_AGENT_ENDPOINT_PORT: '443'
  INSTANA_AGENT_ZONE: 'gae-java-app'

resources:
  cpu: 4
  memory_gb: 4

health_check:
  enable_health_check: False

skip_files:
- ^\.git/.*$

For NodeJS, Python, Golang based apps, an additional environment variable is needed:

INSTANA_AGENT_HTTP_LISTEN: "*"

to enable tracing. Please note that your source code must include sensor for language you are monitoring (except Java).

Deployment

Finally, we can deploy this file with running the following command:

gcloud app deploy gae-java-app.yaml

After confirmation you can see the output of the whole process or stream logs from the command line by running:

$ gcloud app logs tail -s gae-java-app

The Instana agent will discover new instances on the map for every deployed app/instance on Google App Engine Flex. Java

NodeJS