Skip to content

Commit

Permalink
more cloudwatch
Browse files Browse the repository at this point in the history
  • Loading branch information
prenagha committed Aug 23, 2024
1 parent 21dbeae commit 911ed0a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-websocket")


// db management
implementation("org.flywaydb:flyway-core")
implementation("org.flywaydb:flyway-database-postgresql")

// monitoring
implementation("de.siegmar:logback-awslogs-json-encoder:2.0.0")
implementation("io.micrometer:micrometer-registry-cloudwatch2")

// monitoring endpoints
implementation("org.springframework.boot:spring-boot-starter-actuator")

// auth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.renaghan.todo.config;

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
Expand All @@ -8,14 +9,16 @@
@Component
class LoggingContextConfiguration implements WebMvcConfigurer {

private final MeterRegistry meterRegistry;
private final ApplicationEventPublisher eventPublisher;

public LoggingContextConfiguration(ApplicationEventPublisher eventPublisher) {
public LoggingContextConfiguration(MeterRegistry meterRegistry, ApplicationEventPublisher eventPublisher) {
this.meterRegistry= meterRegistry;
this.eventPublisher = eventPublisher;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoggingContextInterceptor(eventPublisher));
registry.addInterceptor(new LoggingContextInterceptor(meterRegistry, eventPublisher));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.renaghan.todo.config;

import com.renaghan.todo.tracing.TracingEvent;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tags;
import jakarta.annotation.Nonnull;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -16,9 +18,12 @@
class LoggingContextInterceptor implements HandlerInterceptor {

private final Logger logger = LoggerFactory.getLogger(LoggingContextInterceptor.class);
private final MeterRegistry meterRegistry;
private final ApplicationEventPublisher eventPublisher;

public LoggingContextInterceptor(ApplicationEventPublisher eventPublisher) {
public LoggingContextInterceptor(
MeterRegistry meterRegistry, ApplicationEventPublisher eventPublisher) {
this.meterRegistry = meterRegistry;
this.eventPublisher = eventPublisher;
}

Expand All @@ -34,6 +39,9 @@ public boolean preHandle(
MDC.put("userId", userId);
// event which is then async written to dynamodb breadcrumb table
this.eventPublisher.publishEvent(new TracingEvent(this, request.getRequestURI(), userId));

meterRegistry.counter("stratospheric.web.hits", Tags.of(request.getRequestURI())).increment();

return true;
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/resources/application-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ management:
cloudwatch:
metrics:
export:
enabled: false
enabled: true
namespace: todo-app
step: 1m
metrics:
environment: ${ENVIRONMENT_NAME}



# noinspection SpringBootApplicationYaml
custom:
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
management:
cloudwatch:
metrics:
export:
enabled: true
namespace: todo-app
step: 1m
endpoint:
health:
# show all on actuator info page
Expand Down

0 comments on commit 911ed0a

Please sign in to comment.