Skip to content

Commit

Permalink
elasticsearch configuring
Browse files Browse the repository at this point in the history
  • Loading branch information
IvannKurchenko committed Jan 23, 2024
1 parent 3497b8f commit 9d7088f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TODO
Apart from source code current repo has the following folders:
```
blog - blog post
docker - various docker compose files to setup
docker-compose - various docker compose files to setup
```

## How to run
Expand Down
5 changes: 4 additions & 1 deletion blog/BLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ collector processors.
Code source for this blog post can be found [here](TODO)
OpenTelemetry links:
- OTLP protocol;
- Supported languages;
- Supported languages;

References:
https://opentelemetry.io/docs/languages/java/automatic/spring-boot/ - Spring Boot instrumentation
10 changes: 5 additions & 5 deletions docker-compose/setup-direct-publishing.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Docker compose to demonstrate direct publishing of metrics and traces to monitoring backend.
# Run with the following command: docker-compose -f docker-compose/monitoring-direct-publishing.yml up -d
# Run with the following command: docker-compose -f docker-compose/setup-direct-publishing.yaml up -d
version: "3.9"
services:
elasticsearch:
extends:
file: products-service-environment.yaml
file: common-environment.yaml
service: elasticsearch
hostname: elasticsearch
networks:
- products

postgres:
extends:
file: products-service-environment.yaml
file: common-environment.yaml
service: postgres
hostname: postgres
networks:
- products

products-service:
extends:
file: products-service.yaml
file: common-products-service.yaml
service: products-service
depends_on:
- postgres
Expand All @@ -30,7 +30,7 @@ services:
- "SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/products"
- "SPRING_DATASOURCE_USERNAME=products_user"
- "SPRING_DATASOURCE_PASSWORD=products_password"
- "SPRING_ELASTICSEARCH_REST_URIS=[elasticsearch:9200]"
- "SPRING_ELASTICSEARCH_REST_URI=elasticsearch:9200"
networks:
- products

Expand Down
11 changes: 11 additions & 0 deletions java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Run with: docker build -t products-service .
FROM gradle:8.5.0-jdk21-alpine AS builder
RUN mkdir -p /usr/src/products-service
COPY . /usr/src/products-service
WORKDIR /usr/src/products-service
RUN ./gradlew bootJar

FROM eclipse-temurin:21-jre-alpine
COPY --from=builder /usr/src/products-service/build/libs/products-service-0.0.1-SNAPSHOT.jar /usr/app/products-service.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/app/products-service.jar"]
17 changes: 14 additions & 3 deletions java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@ dependencies {

implementation 'org.springframework:spring-web:6.1.3'

implementation 'org.springframework.boot:spring-boot-starter-web:3.2.1'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:3.2.1'
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch:3.2.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'

implementation 'io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter'
implementation 'io.opentelemetry.instrumentation:opentelemetry-jdbc'
implementation 'io.opentelemetry.instrumentation:opentelemetry-elasticsearch-rest-common'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
imports {
mavenBom("io.opentelemetry:opentelemetry-bom:1.34.1")
mavenBom("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:2.0.0-alpha")
}
}

tasks.named('test') {
useJUnitPlatform()
}
2 changes: 1 addition & 1 deletion java/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'blog-otel-decoupled-monitoring'
rootProject.name = 'products-service'
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
package io.github.ivankurchenko.blogoteldecoupledmonitoring.config;public class ApplicationElasticsearchConfiguration {
package io.github.ivankurchenko.blogoteldecoupledmonitoring.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchConfiguration;

@Configuration
public class ApplicationElasticsearchConfiguration extends ElasticsearchConfiguration {

private final Environment environment;

public ApplicationElasticsearchConfiguration(Environment environment) {
this.environment = environment;
}

@Override
public ClientConfiguration clientConfiguration() {
var uri = environment.getProperty("spring.elasticsearch.rest.uri");
return ClientConfiguration.builder()
.connectedTo(uri)
.build();
}
}
2 changes: 1 addition & 1 deletion java/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ spring.datasource.password=products_password
spring.flyway.baseline-on-migrate=true
spring.flyway.out-of-order=true

#app.elasticsearch.url=http://localhost:9200
spring.elasticsearch.rest.uri=localhost:9200

0 comments on commit 9d7088f

Please sign in to comment.