Type
What’s this?
Scope
How to use it?
Usefulness
Spring AOP (Aspect-Oriented Programming
Intercept method calls within a specific package
Measures execution time and log relevant details
Pure Java
Dependency
aspectjrt
spring-boot-starter-aop
Annotation and set up
Code Block @Aspect @Component @Slf4j public class CpsLoggingAspectService {
sets up spring AOP
Code Block language java private static final String CPS_PACKAGE_NAME = "org.onap.cps"; private static final String ALL_CPS_METHODS = "execution(* " + CPS_PACKAGE_NAME + "..*(..)))"; private static final String METHOD_RETURNING_SENSITIVE_DATA = "AuthPassword"; private static final String SENSITIVE_DATA_MASK = "***********"; @Around(ALL_CPS_METHODS) @SneakyThrows public Object interceptMethodCall(final ProceedingJoinPoint proceedingJoinPoint) {...}
line 5 expression tells spring to intercept all cps methods in the given package
uses stopwatch to record start and end time of method execution
the method above also states to mask all logging data from methods that contains ‘AuthPassword’ (line 3) from the method signature name
this method can be modified to tell what to do before and after a method runs
in logs, sample result:
all public methods in the packages configured in set up
no annotation needed
Default logging level of “logging.level.org.onap.cps” is set to “INFO”.
to change this, set line 194 (logging.level.org.onap.cps to DEBUG)
Changing logging level dynamically
can control easily which packages and/or methods to run by changing the constants
no repetitive code for debugging all method performances to see when methods are executed, their parameters, return values etc.
note that there might be degradation in performance when enabled
“@Around"/@Before/@After annotation takes other expressions to specify to Spring which methods you want to monitor , can be based on their name, parameters, or return type…examples:
@Around("execution(* org.thirdparty.library.*.*(..))") - only intercepts methods of the given library
@Around("execution(*org.onap.cps.*.*(org.onap.TrustLevel))") - only intercepts methods with TrustLevel as first parameter
MicroMeter
allows to collect metrics with use of annotation
integrates with Spring boot Actuator
TimedAspect (micrometer class) uses AOP
Annotation and set up
MicroMeterConfig.java
wherever annotation “@Timed” is used, timing metrics is automatically applied to that method (org/onap/cps/config/MicroMeterConfig.java)
our methods are annotated in the following way:
Code Block @Timed(value = "cps.rest.admin.controller.schemaset.create", description = "Time taken to create schemaset from controller")
specified given “value” will be the name of the metric
description is the details of the given metric
all methods with @Timed annotation
ADD LIST OF WHAT WE HAVE
other annotations that can be added
@Counted
@Gauge
enabled by default
collected metrics are accessible via endpoint of actuator/prometheus
see application.yml - management.endpoint.web.exposure.include: info,health,loggers,prometheus
http://localhost:8080/actuator/prometheus
Grafana - use prometheus readings to visualise
see docker-compose
what can we get?
metrics: counters, gauges, timers
right now we only have timer but counters and gauges can be added to the configuration
HTTP request metrics response times, request counts etc
JVM metrics (memory usage,garbage collection, thread count, class loading stats)
Datasource metrics (connection pool stats)
System metrics (disk space, CPU usage etc)
Elaborate 3pp metrics
sample actuator/prometheus output
Type | What’s this? | Scope | How to use it? | Usefulness | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Spring AOP (Aspect-Oriented Programming |
|
|
|
| |||||||||||||
MicroMeter |
|
|
|
| |||||||||||||
OpenTelemetry | end-to-end tracing (tracing requests across services) OpenTelemetry - open-source set of APIs, libraries, agents, and instrumentation to monitor application. Allows to collect metrics, logs, and traces Jaeger - open-source distributed tracing system used with OpenTelemetry to visualise traces and understand flow of requests ** we use OpenTelemetry to send trace data to Jaeger and view it in Jaeger UI
|
|
| ** Trace shows the journey of the request flow. It is made up of spans which shows each operations ** Each span has metadata: id ,start and end time, operation name (i.e. HTTP GET), status code, response time etc.. What gets traced?
|
|
|
~Database Queries
|
|