Cloudwatch custom metrics namespace in Grafana - spring

My application is pushing custom metrics to CloudWatch. Furthermore, these metrics are plotted using Grafana.
For this to work I need to configure Grafana to look for my custom metrics namespaces by adding them under Datasources -> CloudWatch. Like this:
The only problem is that I'm having another custom metric namespace called "MyApp (prod,en)". Since there is a comma in the namespace itself, it messes up the list above (which is comma separated).
I have not chosen the namespace name myself. Is was automatically generated. It's a Spring boot app called MyApp using 2 spring profiles: 'prod' and 'en'
My questions is how do I get the metrics from the namespace "MyApp (prod,en)" into Grafana?

I changed the namespace name to "MyApp (prod en)" when initializing the CloudWatchConfig. This fixed my problem.

Related

How to add same prefix to all LOGS in request in SpringBoot project

I use #Slf4j to add logs in all layers in my SpringBoot project.
I want to use some unque ID for all logs inside onq request.
For example generate UUID at the RestController and automatic add it to every logs in this thread
For example
[..... Some UUID ....] "The real logger message"
How to do this?
It need to have possibility to filter all logs of specific request.
If your application is threaded (or any better word to describe "opposed to a reactive application where it might be possible that everything happens in the main thread"), use the mapped diagnostic context (MDC). The MDC is a thread-bound Key-Value Map, where you can put and retrieve data. Baeldung has a tutorial on logging with the mdc using multiple logging frameworks. Also, there are plenty of examples across the web.
If your application should be reactive, you may wanna check out this project reactor reference.

Spring GCP Datastore interface: setting the namespace?

I want to save an entity into Google Datastore using the Spring DatastoreOperations interface (com.google.cloud.spring.data.datastore.core.DatastoreTemplate.save() method). However, I also need to specify the datastore namespace, as I my data is stored in a separate namespace for each user. Is this at all possible using the Spring abstraction? It works when I hardcode the namespace in application.properties (spring.cloud.gcp.datastore.namespace=...) but obviously I need to set it at runtime depending on the request.
Ok, I think I found the solution: implementing a bean of type DatastoreNamespaceProvider seems to address exactly this need.

Using Prometheus metrics with CircuitBreakerConfigCustomizer

I'm trying to setup prometheus metrics with CircuitBreaker, our application uses CircuitBreakerConfigCustomizer with an entry in application.properties as outlined in https://resilience4j.readme.io/docs/getting-started-3
Since its a customizer, we need an entry in application.properties to set resilience4j.circuitbreaker.backends.backendA.register-health-indicator=true where backendA is the circuit breaker name.
Probably, this is associating the CB backendA with some registry. However, I want to retrieve this registry so that I can use TaggedCircuitBreakerMetrics.ofCircuitBreakerRegistry and bind it to a PrometheusMeterRegistry - but how can I fetch the associated registry?
I created a new registry using ofDefaults() but that is a different instance and doesn't have references to the backends already defined in properties.
How do I setup metrics to work with this setup?
Since you are using micrometer, resilience4j provides a micrometer module so that the metrics would be exported out of the box.
Check the documentation for details here

Configuring SpringBoot 2 application for Micrometer for AWS cloudwatch

I have a springboot 2 application, and I want to display metrics in AWS Cloudwatch.
I have included micrometer cloudwatch dependency in pom.
Here setting is documented for various metric systems but not cloudwatch.
Whar else configurations I need to do for cloudwatch?
First of all you may have to add some additional dependecies. I needed the following:
org.springframework.boot - spring-boot-starter-actuator
org.springframework.cloud - spring-cloud-starter-aws
io.micrometer - micrometer-core
io.micrometer - micrometer-registry-cloudwatch
Boot was not able to manage the versions for these dependencies except for actuator in my case, so you might have to figure out the right versions for you.
Firthermore some application properties have to be set:
# disable unwanted features to prevent autoconfigure which will produce errors and abort of application startup eventually
# alternatively you can try to configure those features correctly if you intend to use them
cloud.aws.stack.auto=false
# enable micrometer for cloudwatch (only where there is actually access to it)
management.metrics.export.cloudwatch.enabled=true
# set the namespace that will contain the metrics for this application
management.metrics.export.cloudwatch.namespace=test
# set max batch size to the actual maximum (if not a bug in certain versions of micrometer for cloudwatch will send
# batches that are too big)
management.metrics.export.cloudwatch.batchSize=20
The next step will be in AWS. The role associated with your EC2-instance (or whatever you are using) needs to have the permission CloudWatch:PutMetricData.
Using this configuration should enable CloudWatch-Monitoring for your Spring-Boot-Application.
One of the sources I encountered stated that you should use:
cloud.aws.credentials.instanceProfile=false
This will prevent Spring Boot from automatically obtaining credentials that are necessary to push metrics to CloudWatch. You could also provide own credentials another way, but I didn't try that.

springboot admin: How to display custom metrics in springboot admin GUI ("Metrics" tab)

We are using serveral microservices with springboot (Vers. 1.4.3) and for monitoring them springboot-admin (Vers. 1.5.0).
Inside our microservices we generate several custom metrics (using the
'#com.codahale.metrics.annotation.Timed' annotation).
While all these custom metrics are displayed through the ordinary actuator-endpoint "/metrics" they are sorrowly not shown in the springboot admin GUI -"Metrics" tab.
Obviously only "counter." and "gauge." metrics are displayed in the latter.
Is there any possibility to configure / modify springboot admin, so that these custom metrics also are shown - either in the existing 'metrics' tab or in another new tab ?
Ok, meanwhile I found out, that the new springboot-admin version 1.5.2 will solve our problem:
As I could see at a project from a colleague, this springboot-admin version will display ALL metrics without any restrictions regarding the metrics-key.
[ At the moment we can't upgrade to this version since our springboot-version dependency prevents it but in the future we'll be able to do so.]
So the problem is more or less solved.

Resources