A maven spring boot catalog application for the product catalog and product information retrieval.
It requires following things to be installed:
- Java: ^8.0
- Maven
To run the application locally use the command given below:
mvn spring-boot:run
To deploy app inside a docker container
-
Create a network if it doesn't already exist by executing
docker network create --driver bridge nordmart-apps
-
Build jar file of the app by executing
mvn clean package
-
Next build the image using
docker build -t catalog .
-
Finally run the image by executing
docker run -d --name catalog --network nordmart-apps -p 8080:8080 catalog
Helm operator needs to to be running inside the cluster. Helm operator is deployed by Stakater Global Stack, deployment guidelines are provided in this link
To create helm release of this application using the command given below:
kubectl apply -f helm-release.yaml -n
The following dependencies are needed to expose micrometer and application metrics
<dependencies>
<!-- For micrometer support -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.4</version>
</dependency>
</dependencies>
Add the following properties to application.properties
to expose the micrometer endpoint.
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
Add the MeterRegistry bean to your spring boot application by adding the follwoing snippet to your SpringBootApplication class.
@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> registry.config().commonTags("application", "common-service");
}
This will help you create custom metrics within the application
To count the number of times an operation has been performed, just create a io.micrometer.core.instrument.Counter
variable by doing
Counter.builder("count_metric_name").description("Description of metric").register(meterRegistry);
To add metrics that keeps track of processing time taken by a piece of code, follow the following snippet:
private final Timer timer = Timer.builder("metricsname").tag("tagKey", "tagValue").register(meterRegistry);
long start = System.nanoTime();
...your code here
timer.record(System.nanoTime() - start, TimeUnit.NANOSECONDS);
A gauge is a handle to get the current value. Typical examples for gauges would be the size of a collection or map. To create a gauge metric just do
AtomicInteger myCount = meterRegistry.gauge("gauge_value", new AtomicInteger(0));
and then you can just set the value as it changes using
myCount.set(myList.size());
Dasbhoards given below can be used to monitor application by configuring them in Monitoring stack. If monitoring stack is not already configured use guidelines given in this link to configure it.
-
Catalog service metrics dashboard can be configured using this config.