Skip to content

Commit

Permalink
health check added
Browse files Browse the repository at this point in the history
  • Loading branch information
IvannKurchenko committed Feb 7, 2024
1 parent cbfea14 commit 2b48965
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 15 deletions.
5 changes: 0 additions & 5 deletions docker-compose/common-otel-collector.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ receivers:
processors:
# Data sources: traces, metrics, logs
memory_limiter:
check_interval: 5s
check_interval: 1s
limit_mib: 4000
spike_limit_mib: 500

# Data sources: traces
probabilistic_sampler:
hash_seed: 22
sampling_percentage: 15


# Exporters' configuration section
# See for more details following documentation: https://opentelemetry.io/docs/collector/configuration/#exporters
Expand All @@ -42,7 +37,7 @@ service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, probabilistic_sampler]
processors: [memory_limiter]
exporters: [otlphttp]
metrics:
receivers: [otlp]
Expand Down
44 changes: 44 additions & 0 deletions docker-compose/mount/otel-collector-config-prometheus-jaeger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This OTEL collector configuration file that aims is to export metrics to Prometheus and traces to Zipkin.
# It exposes a single OTLP receiver for this purpose.

# Receivers' configuration section
# See for more details following documentation: https://opentelemetry.io/docs/collector/configuration/#receivers
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4418

# Processors' configuration section
# See fore more details following documentation: https://opentelemetry.io/docs/collector/configuration/#processors
processors:
# Data sources: traces, metrics, logs
memory_limiter:
check_interval: 1s
limit_mib: 4000
spike_limit_mib: 500


# Exporters' configuration section
# See for more details following documentation: https://opentelemetry.io/docs/collector/configuration/#exporters
exporters:
# Data sources: traces
otlphttp:
endpoint: http://jaeger:4318

# Data sources: metrics
prometheus:
endpoint: 0.0.0.0:9094
namespace: products_service

# Services configuration section
# See for more details following documentation: https://opentelemetry.io/docs/collector/configuration/#services
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter]
exporters: [otlphttp]
metrics:
receivers: [otlp]
exporters: [prometheus]
69 changes: 69 additions & 0 deletions docker-compose/setup-otel-collector-publishing-filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Docker compose to demonstrate publishing of metrics and traces to monitoring backend though OTEL collector.
# Run with the following command: docker-compose -f docker-compose/setup-otel-collector-publishing.yaml up -d
version: "3.9"
services:
elasticsearch:
extends:
file: common-environment.yaml
service: elasticsearch
hostname: elasticsearch
networks:
- products

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

jaeger:
extends:
file: common-monitoring-prometheus-jeager.yml
service: jaeger
hostname: jaeger
networks:
- products

prometheus:
extends:
file: common-monitoring-prometheus-jeager.yml
service: prometheus-collector
hostname: prometheus
networks:
- products

products-service:
extends:
file: common-products-service.yaml
service: products-service
depends_on:
- postgres
- elasticsearch
hostname: products-service
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/products
- SPRING_DATASOURCE_USERNAME=products_user
- SPRING_DATASOURCE_PASSWORD=products_password
- SPRING_ELASTICSEARCH_REST_URI=elasticsearch:9200
- OTEL_SERVICE_NAME=products_service
- OTEL_METRICS_EXPORTER=otlp
- OTEL_TRACES_EXPORTER=otlp
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4418
networks:
- products

otel-collector:
image: otel/opentelemetry-collector-contrib:0.93.0
hostname: otel-collector
volumes:
- ./mount/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml
ports:
- "9094:9094" # Prometheus http exporter
- "4418:4418" # OTLP http receiver
networks:
- products

networks:
products:
2 changes: 2 additions & 0 deletions java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ ARG OTEL_VERSION=v2.0.0
RUN wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/$OTEL_VERSION/opentelemetry-javaagent.jar
COPY --from=builder /usr/src/products-service/build/libs/products-service-0.0.1-SNAPSHOT.jar /usr/app/products-service.jar
EXPOSE 8080
RUN apk add curl
HEALTHCHECK --interval=1s --retries=3 --timeout=1s --start-period=5s CMD curl -f http://localhost:8080/health > /dev/null 2>&1 || exit 1
ENTRYPOINT ["java","-javaagent:opentelemetry-javaagent.jar","-jar","/usr/app/products-service.jar"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.ivankurchenko.blogoteldecoupledmonitoring.controllers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthController {
private static final Logger logger = LoggerFactory.getLogger(HealthController.class);

@GetMapping("/health")
public String health() {
logger.info("Health check API invoked!");
return "OK";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public ProductController(ProductService productService) {
this.productService = productService;
}


@PostMapping("/api/product")
public Product createProduct(@RequestBody Product data) {
return productService.createProduct(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public class ProductService {
private final ProductDocumentRepository productDocumentRepository;

public ProductService(ProductRepository productRepository,
ProductDocumentRepository productDocumentRepository,
ElasticsearchOperations elasticsearchOperations) {
ProductDocumentRepository productDocumentRepository) {
this.productRepository = productRepository;
this.productDocumentRepository = productDocumentRepository;
}
Expand Down

0 comments on commit 2b48965

Please sign in to comment.