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

Upgrade to Scala 2.13.6 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import sbtassembly.AssemblyKeys.assembly

lazy val akkaHttpVersion = "10.1.12"
lazy val akkaVersion = "2.6.6"
lazy val elasticApmVersion = "1.17.0"
lazy val elasticApmVersion = "1.24.1-SNAPSHOT"

resolvers += Resolver.mavenLocal

lazy val root = (project in file(".")).
settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.13.2"
scalaVersion := "2.13.6"
)),
name := "akka-http-apm",
libraryDependencies ++= Seq(
Expand Down
93 changes: 59 additions & 34 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,76 @@
version: '2.2'

services:
apm-server:
image: docker.elastic.co/apm/apm-server:7.12.0
depends_on:
elasticsearch:
condition: service_healthy
kibana:
condition: service_healthy
cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"]
cap_drop: ["ALL"]
ports:
- 8200:8200
networks:
- elastic
command: >
apm-server -e
-E apm-server.rum.enabled=true
-E setup.kibana.host=kibana:5601
-E setup.template.settings.index.number_of_replicas=0
-E apm-server.kibana.enabled=true
-E apm-server.kibana.host=kibana:5601
-E output.elasticsearch.hosts=["elasticsearch:9200"]
healthcheck:
interval: 10s
retries: 12
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- cluster.name=docker-cluster
- cluster.routing.allocation.disk.threshold_enabled=false
- discovery.type=single-node
- ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g
ulimits:
memlock:
soft: -1
hard: -1
soft: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports: ['9200:9200']
networks: ['elastic']
- esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
healthcheck:
interval: 20s
retries: 10
test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"'

kibana:
image: docker.elastic.co/kibana/kibana:7.8.0
container_name: kibana
ports: ['5601:5601']
networks: ['elastic']
depends_on: ['elasticsearch']
apm-server:
image: docker.elastic.co/apm/apm-server:7.8.0
container_name: apm_server
ports: ['8200:8200']
networks: ['elastic']
command: --strict.perms=false -e # -e flag to log to stderr and disable syslog/file output
#secrets:
#- source: apm-server.yml
#target: /usr/share/apm-server/apm-server.yml
#- source: apm-server.keystore
#target: /usr/share/apm-server/apm-server.keystore
#- source: ca.crt
#target: /usr/share/apm-server/certs/ca/ca.crt
#volumes:
#- './scripts/setup-beat.sh:/usr/local/bin/setup-beat.sh:ro'
depends_on: ['elasticsearch', 'kibana']
image: docker.elastic.co/kibana/kibana:7.12.0
depends_on:
elasticsearch:
condition: service_healthy
environment:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
ports:
- 5601:5601
networks:
- elastic
healthcheck:
interval: 10s
retries: 20
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:5601/api/status

volumes:
data01:
esdata:
driver: local

networks:
elastic:
driver: bridge


2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.10
sbt.version=1.5.5
16 changes: 8 additions & 8 deletions src/main/scala/com/example/api/UserRoutes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import akka.http.scaladsl.server.RouteResult.{Complete, Rejected}
import akka.http.scaladsl.server.{Route, RouteResult}
import co.elastic.apm.api.{ElasticApm, Scope, Transaction}

import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal

class UserRoutes(userRegistry: UserRegistryClient)(implicit val system: ActorSystem[_]) {
Expand All @@ -20,10 +20,10 @@ class UserRoutes(userRegistry: UserRegistryClient)(implicit val system: ActorSys
case Complete(httpResponse: HttpResponse) =>
val statusCode = httpResponse.status.intValue
val statusRange = (statusCode / 100).toString + "xx"
transaction.addLabel("status_code", statusCode.toString)
transaction.setLabel("status_code", statusCode.toString)
transaction.setResult(s"HTTP $statusRange")
case Rejected(_) =>
transaction.addLabel("status_code", "500")
transaction.setLabel("status_code", "500")
transaction.setResult("HTTP 5xx")
}
println("transaction-id: " + ElasticApm.currentTransaction().getId + " Ending transaction " + transaction.getId + " thread=" + Thread.currentThread().getId)
Expand All @@ -35,25 +35,25 @@ class UserRoutes(userRegistry: UserRegistryClient)(implicit val system: ActorSys

def withTraceContext(route: Route): Route = { ctx =>
val transaction = ElasticApm.startTransaction()
var scope: Scope = null;
var scope: Scope = null
try {
scope = transaction.activate()
} catch {
case NonFatal(_) =>
if (scope != null) {
scope.close();
scope.close()
}
}
println("transaction-id: " + ElasticApm.currentTransaction().getId + "Starting transaction " + transaction.getId + " thread=" + Thread.currentThread().getId)
transaction.setType(Transaction.TYPE_REQUEST)
transaction.setName(ctx.request.method.value + " " + ctx.request.uri.path.toString)
transaction.addLabel("path", ctx.request.uri.path.toString)
transaction.addLabel("request_method", ctx.request.method.value)
transaction.setLabel("path", ctx.request.uri.path.toString)
transaction.setLabel("request_method", ctx.request.method.value)

mapRouteResult(mapRouteResultWithTransaction(transaction, scope))(route)(ctx)
}

implicit val executionContext = system.executionContext
implicit val executionContext: ExecutionContext = system.executionContext

def waitForIt(): Future[Unit] = {
println("transaction-id: " + ElasticApm.currentTransaction().getId + " waitForIt before " + " thread=" + Thread.currentThread().getId)
Expand Down