Skip to content

Commit

Permalink
Add .editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciogeneroso committed Jun 28, 2024
1 parent b1f3940 commit 5d95924
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.java]
max_line_length = 120
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public FilterRegistrationBean<RequestLoggingFilter> incomingRequestLogFilter() {

@Bean
public FilterRegistrationBean<ApplicationResponsesMetricsFilter> responseMetricFilter(
MetricsService metricsService) {
MetricsService metricsService) {
var filter = new FilterRegistrationBean<>(new ApplicationResponsesMetricsFilter(metricsService));
filter.setOrder(1);
return filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class ApplicationResponsesMetricsFilter implements Filter {
private final MetricsService metricsService;

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException, IOException {

chain.doFilter(request, response);

var httpServletRequest = (HttpServletRequest) request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
public class RequestLoggingFilter implements Filter {

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

var httpServletRequest = (HttpServletRequest) request;
var httpServletResponse = (HttpServletResponse) response;
var path = httpServletRequest.getRequestURI();
Expand Down
14 changes: 7 additions & 7 deletions sd-app/src/main/java/com/generoso/sd/metrics/MetricsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class MetricsService {

public void applicationResponseTotal(String method, String path, String status) {
var tags = Tags.of(
Tag.of("method", method),
Tag.of("path", path),
Tag.of("status", status)
Tag.of("method", method),
Tag.of("path", path),
Tag.of("status", status)
);

Counter.builder("application.responses.total")
.description("Metrics for application responses per endpoint, method and http response code.")
.tags(tags)
.register(meterRegistry)
.increment();
.description("Metrics for application responses per endpoint, method and http response code.")
.tags(tags)
.register(meterRegistry)
.increment();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GetAppsRequestTemplate extends RequestTemplate {

@Autowired
public GetAppsRequestTemplate(@Value("${service.host}") String host,
@Value("${service.context-path:}") String contextPath) {
@Value("${service.context-path:}") String contextPath) {
super(host, contextPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import java.util.List;

public record Application(@JsonProperty("versions__delta") String version,
@JsonProperty("apps__hashcode") String appHashCode,
List<ApplicationDetail> application) {
public record Application(
@JsonProperty("versions__delta") String version,
@JsonProperty("apps__hashcode") String appHashCode,
List<ApplicationDetail> application) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public void theMetricForEndpointWithParameterAndStatusResponseHasIncrementedBy(S
int increment) {
var path = String.format("%s/%s", endpoint.getPath(), pathParameter);
var initialCount = getResourceAndStatusCounterValue(metricsState.getInitialMetrics(), metricName,
endpoint.getMethod(), path, statusCode);
endpoint.getMethod(), path, statusCode);
var newCount = getResourceAndStatusCounterValue(metricsState.getNewMetrics(), metricName,
endpoint.getMethod(), path, statusCode);
endpoint.getMethod(), path, statusCode);
assertThat(newCount).isEqualTo(initialCount + increment);
}

Expand All @@ -61,9 +61,9 @@ private double getResourceAndStatusCounterValue(List<MetricFamily> metrics, Stri
private double getResourceAndStatusCounterValue(List<MetricFamily> metrics, String metricName, String method,
String path, String status) {
return sumCounterMetric(metrics, metricName, List.of(
metric -> metric.getLabels().get("method").equals(method),
metric -> metric.getLabels().get("path").equals(path),
metric -> metric.getLabels().get("status").equals(status)));
metric -> metric.getLabels().get("method").equals(method),
metric -> metric.getLabels().get("path").equals(path),
metric -> metric.getLabels().get("status").equals(status)));
}

private double sumCounterMetric(List<MetricFamily> metricFamilies, String metricName, List<Predicate<Metric>> filters) {
Expand All @@ -73,15 +73,15 @@ private double sumCounterMetric(List<MetricFamily> metricFamilies, String metric
private double sumMetric(List<MetricFamily> metricFamilies, String metricName, MetricType metricType, List<Predicate<Metric>> filters) {
var metricsStream = getMetricsStreamWithNameAndType(metricFamilies, metricName, metricType);
return applyFilters(metricsStream, filters)
.map(MetricWrapper::new)
.mapToDouble(MetricWrapper::getValue)
.sum();
.map(MetricWrapper::new)
.mapToDouble(MetricWrapper::getValue)
.sum();
}

private Stream<Metric> getMetricsStreamWithNameAndType(List<MetricFamily> metricFamilies, String metricName, MetricType metricType) {
return metricFamilies.stream()
.filter(mf -> mf.getName().equals(metricName) && mf.getType().equals(metricType))
.flatMap(mf -> mf.getMetrics().stream());
.filter(mf -> mf.getName().equals(metricName) && mf.getType().equals(metricType))
.flatMap(mf -> mf.getMetrics().stream());
}

private Stream<Metric> applyFilters(Stream<Metric> metricsStream, List<Predicate<Metric>> filters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ResponseStepDefinitions {
Expand Down

0 comments on commit 5d95924

Please sign in to comment.