Skip to content

Commit

Permalink
Hugo dev and prod setup (#2)
Browse files Browse the repository at this point in the history
* working hugo, docker and python

* working dev and prod environment of hugo

* otel in action part traces

* code for otel in action lab

* working hugo, docker and python (#1)

Co-authored-by: Jens Plüddemann <[email protected]>

* newer docker cli

* working docker-in-docker

---------

Co-authored-by: Jens Plüddemann <[email protected]>
Co-authored-by: Matthias Haeussler <[email protected]>
  • Loading branch information
3 people authored Apr 8, 2024
1 parent d4daf15 commit b0b651d
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 109 deletions.
22 changes: 9 additions & 13 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@
"SHELL": "/bin/bash"
},
"forwardPorts": [
"0.0.0.0:3000",
5000,
"0.0.0.0:8080"
"tutorial:80",
"application:5000"
],
"portsAttributes": {
"0.0.0.0:3000": {
"label": "Tutorial",
"onAutoForward": "notify"
"tutorial:80": {
"label": "Tutorial"
},
"0.0.0.0:5000": {
"label": "Application",
"onAutoForward": "notify"
},
"8080": {
"label": "Otel Collector"
"application:5000": {
"label": "Manual instrumentation application"
}
},
"features": {},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"customizations": {
"vscode": {
"settings": {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pycache__
25 changes: 19 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
FROM gradle:8.7.0-jdk21 as base
FROM gradle:8-jdk21 as base

ARG DEBIAN_FRONTEND=noninteractive
ARG USERNAME=otel
ARG USER_UID=1001
ARG USER_GID=$USER_UID
ARG DOCKER_REPOSITORY_VERSION=bookworm

RUN apt-get -qq update && apt-get -qq upgrade

RUN apt-get -qq install ca-certificates curl sudo bash git
RUN install -m 0755 -d /etc/apt/keyrings
RUN curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
RUN chmod a+r /etc/apt/keyrings/docker.asc

RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo ${DOCKER_REPOSITORY_VERSION}) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN apt-get -qq update

RUN apt-get -qq install \
sudo \
bash \
git \
python3 \
python3-pip \
docker \
docker-compose
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin

RUN pip3 install \
requests \
Expand Down
12 changes: 7 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ services:
build:
context: .
dockerfile: Dockerfile
image: otel-getting-started-application:lastest
image: otel-getting-started-application:latest
tty: true
volumes:
- ./:/workspace
- /var/run/docker.sock:/var/run/docker.sock
- ./labs:/workspace
ports:
- 5000:5000

httpbin:
image: kennethreitz/httpbin
container_name: httpbin

tutorial:
image: otel-getting-started-tutorial:latest
build:
context: tutorial/
dockerfile: Dockerfile
target: rt
tty: true
volumes:
- ./tutorial:/workspace
ports:
- 3000:80
- 1313:80
3 changes: 3 additions & 0 deletions labs/manual-instrumentation-logs/initial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# otel-manual-instrumentation-lab

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/jtl-novatec/otel-manual-instrumentation-lab) [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/jtl-novatec/otel-manual-instrumentation-lab)
22 changes: 11 additions & 11 deletions labs/manual-instrumentation-logs/initial/src/app.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import time

import requests
from client import ChaosClient, FakerClient
from flask import Flask, make_response
from client import FakerClient, ChaosClient

# global variables
app = Flask(__name__)

@app.route('/users', methods=['GET'])
@app.route("/users", methods=["GET"])
def get_user():
user, status = db.get_user(123)
data = {}
if user is not None:
data = {
"id": user.id,
"name": user.name,
"address": user.address
}
data = {"id": user.id, "name": user.name, "address": user.address}
response = make_response(data, status)
return response


def do_stuff():
time.sleep(.1)
time.sleep(0.1)
url = "http://httpbin:80/anything"
response = requests.get(url)
_response = requests.get(url)

@app.route('/')

@app.route("/")
def index():
do_stuff()
current_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())
return f"Hello, World! It's currently {current_time}"


if __name__ == "__main__":
db = ChaosClient(client=FakerClient())
app.run(host="0.0.0.0", debug = True)
app.run(host="0.0.0.0", debug=True)
20 changes: 11 additions & 9 deletions labs/manual-instrumentation-logs/initial/src/client.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import time
import os
import random
import time
from abc import ABC, abstractmethod

from faker import Faker
from model.user import User


class UserInterface(ABC):
@abstractmethod
def get_user(self, id: int) -> tuple[User, int]:
pass
def get_user(self, id: int) -> tuple[User|None, int]:
pass

# simulates a database
class FakerClient(UserInterface):
def __init__(self):
self.faker = Faker()

def get_user(self, id: int) -> tuple[User, int]:
def get_user(self, id: int) -> tuple[User|None, int]:
usr = User(
id = random.randint(1, 1000),
name = self.faker.name(),
address = self.faker.address()
)
return usr
return usr, 200

# wraps another client for Application-level fault injection
class ChaosClient(UserInterface):
Expand All @@ -38,9 +40,9 @@ def __init__(self, client: UserInterface, base_delay: int = 50):
self.response_status = ["success", "fail"]
self.response_code_probability = (.90, .10)

def get_user(self, id: int) -> tuple[User, int]:
def get_user(self, id: int) -> tuple[User|None, int]:
faults_enabled = (os.getenv("CHAOS", "false").lower() == "true")
if faults_enabled:
if faults_enabled:
# add latency
additional_latency = self.request_latency[random.choices(self.request_type, self.request_probability)[0]]
time.sleep(self.base_delay/1000)
Expand All @@ -49,8 +51,8 @@ def get_user(self, id: int) -> tuple[User, int]:
# choose status code
status = random.choices(self.response_status, self.response_code_probability)[0]
if status == "success":
return self.client.get_user(id), 200
return self.client.get_user(id)[0], 200
elif status == "fail":
return None, 404

return self.client.get_user(id), 200
return self.client.get_user(id)[0], 200
8 changes: 5 additions & 3 deletions labs/manual-instrumentation-logs/initial/src/model/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

class User():
def __init__(self, id, name, address):
class User:
def __init__(self, id: int, name: str, address: str):
self.id = id
self.name = name
self.address = address

def __str__(self):
return ", ".join((f"{item}: {self.__dict__[item]}" for item in self.__dict__))
1 change: 0 additions & 1 deletion labs/manual-instrumentation-logs/solution/src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from abc import ABC, abstractmethod

from faker import Faker

from model.user import User


Expand Down
14 changes: 7 additions & 7 deletions labs/otel-in-action/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.1'

services:

### APPLICATION PART
Expand Down Expand Up @@ -73,10 +71,11 @@ services:

loadgenerator:
image: generator:v0.1
networks:
- todonet
build:
context: ./loadgenerator
networks:
- todonet


### OTEL PART

Expand Down Expand Up @@ -110,11 +109,12 @@ services:

otelcol:
image: ${COLLECTOR_CONTRIB_IMAGE}
restart: unless-stopped
networks:
- todonet
command: ["--config=/etc/otel-collector-config.yaml", ""]
command: ["--config=/etc/otel-collector-config.yml", ""]
volumes:
- ./collector/otel-collector-config.yaml:/etc/otel-collector-config.yaml
- ./collector/otel-collector-config.yml:/etc/otel-collector-config.yml
ports:
- "4317:4317" # OTLP gRPC receiver
- "4318:4318"
Expand Down Expand Up @@ -149,7 +149,7 @@ services:

networks:
todonet:

# opensearch:
# image: ${OPENSEARCH_IMAGE}
# container_name: opensearch
Expand Down
25 changes: 22 additions & 3 deletions labs/otel-in-action/todobackend-springboot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
FROM docker.io/maven:3-eclipse-temurin-21 as build
WORKDIR /workspace/app

COPY pom.xml .
COPY src src

RUN --mount=type=cache,target=/root/.m2 mvn install -DskipTests
# RUN mvn install -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

FROM docker.io/eclipse-temurin:21-jdk-alpine
RUN mkdir -p /opt/todobackend
WORKDIR /opt/todobackend
ADD --chmod=555 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar .
COPY target/todobackend-0.0.1-SNAPSHOT.jar /opt/todobackend
CMD ["java", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar", "-jar", "todobackend-0.0.1-SNAPSHOT.jar"]
#RUN addgroup -S demo && adduser -S demo -G demo
#USER demo
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /opt/todobackend/app/lib
COPY --from=build ${DEPENDENCY}/META-INF /opt/todobackend/app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /opt/todobackend/app

#ADD --chmod=555 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar /opt/todobackend
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar /opt/todobackend

ENTRYPOINT ["java", "-cp", "/opt/todobackend/app:/opt/todobackend/app/lib/*", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar","io.novatec.todobackend.TodobackendApplication"]
25 changes: 0 additions & 25 deletions labs/otel-in-action/todobackend-springboot/Dockerfile-multistage

This file was deleted.

6 changes: 6 additions & 0 deletions labs/otel-in-action/todobackend-springboot/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM docker.io/eclipse-temurin:21-jdk-alpine
RUN mkdir -p /opt/todobackend
WORKDIR /opt/todobackend
ADD --chmod=555 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar .
COPY target/todobackend-0.0.1-SNAPSHOT.jar /opt/todobackend
CMD ["java", "-javaagent:/opt/todobackend/opentelemetry-javaagent.jar", "-jar", "todobackend-0.0.1-SNAPSHOT.jar"]
23 changes: 18 additions & 5 deletions labs/otel-in-action/todoui-thymeleaf/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
FROM docker.io/maven:3-eclipse-temurin-21 as build
WORKDIR /workspace/app

COPY pom.xml .
COPY src src

RUN --mount=type=cache,target=/root/.m2 mvn install -DskipTests
RUN mvn install -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

FROM docker.io/eclipse-temurin:21-jdk-alpine
RUN mkdir -p /opt/todoui
WORKDIR /opt/todoui
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar .
COPY target/todoui-0.0.1-SNAPSHOT.jar /opt/todoui
CMD ["java", "-javaagent:/opt/todoui/opentelemetry-javaagent.jar", "-jar", "todoui-0.0.1-SNAPSHOT.jar"]
RUN addgroup -S demo && adduser -S demo -G demo
USER demo
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","io.novatec.todoui.TodouiApplication"]
19 changes: 0 additions & 19 deletions labs/otel-in-action/todoui-thymeleaf/Dockerfile-multistage

This file was deleted.

Loading

0 comments on commit b0b651d

Please sign in to comment.