Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Business Metric Service #852

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ release.
([#853](https:/open-telemetry/opentelemetry-demo/pull/853))
* [chore] use `otel-demo` namespace for generated kubernetes manifests
([#848](https:/open-telemetry/opentelemetry-demo/pull/848))
* add new `businessmetricservice` to support otel operator instrumentation demo
([#852](https:/open-telemetry/opentelemetry-demo/pull/852))

## 1.4.0

Expand Down
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@ services:
kafka:
condition: service_healthy
logging: *logging
businessmetricservice:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-businessmetricservice
container_name: businessmetrics-service
build:
context: ./
dockerfile: ./src/businessmetricservice/Dockerfile
cache_from:
- ${IMAGE_NAME}:${IMAGE_VERSION}-businessmetricservice
deploy:
resources:
limits:
memory: 200M
restart: unless-stopped
environment:
- KAFKA_SERVICE_ADDR
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE
- OTEL_RESOURCE_ATTRIBUTES
- OTEL_SERVICE_NAME=businessmetricservice
depends_on:
otelcol:
condition: service_started
kafka:
condition: service_healthy
logging: *logging

# Frontend
frontend:
Expand Down
33 changes: 33 additions & 0 deletions src/businessmetricservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
FROM eclipse-temurin:17-jdk AS builder

WORKDIR /usr/src/app/

COPY ./src/businessmetricservice/gradlew* ./src/businessmetricservice/settings.gradle* ./src/businessmetricservice/build.gradle .
COPY ./src/businessmetricservice/gradle ./gradle

RUN ./gradlew
RUN ./gradlew downloadRepos

COPY ./src/businessmetricservice/ ./
COPY ./pb/ ./proto
RUN ./gradlew installDist -PprotoSourceDir=./proto

# -----------------------------------------------------------------------------

FROM eclipse-temurin:17-jre

WORKDIR /usr/src/app/

COPY --from=builder /usr/src/app/ ./

#NOTE: This service is intended to be instrumented through the OTel Operator in
#k8s. If you are running through compose, uncomment this next section.
#ARG version=1.24.0
#ADD https:/open-telemetry/opentelemetry-java-instrumentation/releases/download/v$version/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar
#RUN chmod 644 /usr/src/app/opentelemetry-javaagent.jar
#ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar

ENV KAFKA_BOOTSTRAP_SERVERS=localhost:9092
ENTRYPOINT [ "./build/install/opentelemetry-demo-business-metric-service/bin/BusinessMetricService" ]
4 changes: 4 additions & 0 deletions src/businessmetricservice/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
spring.kafka.consumer.bootstrap-servers=${KAFKA_SERVICE_ADDR:localhost:9092}
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.ByteArrayDeserializer
116 changes: 116 additions & 0 deletions src/businessmetricservice/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
plugins {
id 'application'
id 'com.google.protobuf' version '0.8.18'
id 'org.springframework.boot' version '2.5.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}

description = 'Business Metric Service'
group = 'businessmetricservice'
version = '0.1.0-SNAPSHOT'

def grpcVersion = "1.45.1"
def protocVersion = "3.20.0"


tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

ext {
offlineCompile = new File("$buildDir/output/lib")
}

def protoSourceDir = findProperty('protoSourceDir')?: project.projectDir.parentFile.parentFile.toPath().toString() + "/pb"
def protoDestDir = project.buildDir.toPath().toString() + "/proto"

// Copy protos to the build directory
tasks.register('copyProtos', Copy) {
from protoSourceDir
into protoDestDir
}

// Include the output directory of copyProtos in main source set so they are
// picked up by the protobuf plugin
sourceSets {
main {
proto {
srcDir(protoDestDir)
}
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protocVersion}"
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks { task ->
all()*.plugins {
grpc {}
}
ofSourceSet('main')
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.kafka:spring-kafka:2.7.2'
implementation 'io.opentelemetry:opentelemetry-api:1.25.0'
implementation 'com.google.protobuf:protobuf-java:3.18.1'
implementation "com.google.api.grpc:proto-google-common-protos:2.8.0"
implementation "javax.annotation:javax.annotation-api:1.3.2"
implementation 'io.grpc:grpc-netty-shaded:1.41.0'
implementation 'io.grpc:grpc-protobuf:1.41.0'
implementation 'io.grpc:grpc-stub:1.41.0'
}

sourceSets {
main {
proto {
srcDir 'src/main/proto'
}
java {
srcDirs 'src/main/java', 'src/generated/main/java', 'src/generated/main/grpc'
}
}
}

afterEvaluate {
// Ensure protos are copy before classes are generated
tasks.getByName('processResources').dependsOn 'copyProtos'
tasks.getByName('generateProto').dependsOn 'copyProtos'
}


repositories {
mavenCentral()
mavenLocal()
}

startScripts.enabled = false

task downloadRepos(type: Copy) {
from configurations.compileClasspath
into offlineCompile
from configurations.runtimeClasspath
into offlineCompile
}

task businessMetricService(type: CreateStartScripts) {
mainClass.set('businessmetricservice.BusinessMetricServiceApplication')
applicationName = 'BusinessMetricService'
outputDir = new File(project.buildDir, 'tmp')
classpath = startScripts.classpath
}

applicationDistribution.into('bin') {
from(businessMetricService)
fileMode = 0755
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading