From 5d95924eb38025c89596a55802f6c789cc1f93cb Mon Sep 17 00:00:00 2001 From: Mauricio Generoso Date: Sat, 29 Jun 2024 00:16:30 +0100 Subject: [PATCH] Add .editorconfig --- .editorconfig | 12 +++++++++++ .../com/generoso/sd/config/FiltersConfig.java | 2 +- .../ApplicationResponsesMetricsFilter.java | 4 +++- .../sd/filter/RequestLoggingFilter.java | 4 +++- .../generoso/sd/metrics/MetricsService.java | 14 ++++++------- .../ft/sd/client/GetAppsRequestTemplate.java | 2 +- .../ft/sd/client/model/Application.java | 7 ++++--- .../ft/sd/steps/MetricsStepDefinitions.java | 20 +++++++++---------- .../ft/sd/steps/ResponseStepDefinitions.java | 4 +--- 9 files changed, 42 insertions(+), 27 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..03c4f01 --- /dev/null +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/sd-app/src/main/java/com/generoso/sd/config/FiltersConfig.java b/sd-app/src/main/java/com/generoso/sd/config/FiltersConfig.java index 1a567b3..f1fb2cf 100644 --- a/sd-app/src/main/java/com/generoso/sd/config/FiltersConfig.java +++ b/sd-app/src/main/java/com/generoso/sd/config/FiltersConfig.java @@ -19,7 +19,7 @@ public FilterRegistrationBean incomingRequestLogFilter() { @Bean public FilterRegistrationBean responseMetricFilter( - MetricsService metricsService) { + MetricsService metricsService) { var filter = new FilterRegistrationBean<>(new ApplicationResponsesMetricsFilter(metricsService)); filter.setOrder(1); return filter; diff --git a/sd-app/src/main/java/com/generoso/sd/filter/ApplicationResponsesMetricsFilter.java b/sd-app/src/main/java/com/generoso/sd/filter/ApplicationResponsesMetricsFilter.java index c23d63b..060e1df 100644 --- a/sd-app/src/main/java/com/generoso/sd/filter/ApplicationResponsesMetricsFilter.java +++ b/sd-app/src/main/java/com/generoso/sd/filter/ApplicationResponsesMetricsFilter.java @@ -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; diff --git a/sd-app/src/main/java/com/generoso/sd/filter/RequestLoggingFilter.java b/sd-app/src/main/java/com/generoso/sd/filter/RequestLoggingFilter.java index 6473fed..a56fcdd 100644 --- a/sd-app/src/main/java/com/generoso/sd/filter/RequestLoggingFilter.java +++ b/sd-app/src/main/java/com/generoso/sd/filter/RequestLoggingFilter.java @@ -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(); diff --git a/sd-app/src/main/java/com/generoso/sd/metrics/MetricsService.java b/sd-app/src/main/java/com/generoso/sd/metrics/MetricsService.java index dcbba6d..7b88d67 100644 --- a/sd-app/src/main/java/com/generoso/sd/metrics/MetricsService.java +++ b/sd-app/src/main/java/com/generoso/sd/metrics/MetricsService.java @@ -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(); } } diff --git a/sd-ft/src/test/java/com/generoso/ft/sd/client/GetAppsRequestTemplate.java b/sd-ft/src/test/java/com/generoso/ft/sd/client/GetAppsRequestTemplate.java index 15bcc39..d4587e5 100644 --- a/sd-ft/src/test/java/com/generoso/ft/sd/client/GetAppsRequestTemplate.java +++ b/sd-ft/src/test/java/com/generoso/ft/sd/client/GetAppsRequestTemplate.java @@ -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); } diff --git a/sd-ft/src/test/java/com/generoso/ft/sd/client/model/Application.java b/sd-ft/src/test/java/com/generoso/ft/sd/client/model/Application.java index 3ed6bd1..b447367 100644 --- a/sd-ft/src/test/java/com/generoso/ft/sd/client/model/Application.java +++ b/sd-ft/src/test/java/com/generoso/ft/sd/client/model/Application.java @@ -4,7 +4,8 @@ import java.util.List; -public record Application(@JsonProperty("versions__delta") String version, - @JsonProperty("apps__hashcode") String appHashCode, - List application) { +public record Application( + @JsonProperty("versions__delta") String version, + @JsonProperty("apps__hashcode") String appHashCode, + List application) { } diff --git a/sd-ft/src/test/java/com/generoso/ft/sd/steps/MetricsStepDefinitions.java b/sd-ft/src/test/java/com/generoso/ft/sd/steps/MetricsStepDefinitions.java index fae4577..b5a0f5f 100644 --- a/sd-ft/src/test/java/com/generoso/ft/sd/steps/MetricsStepDefinitions.java +++ b/sd-ft/src/test/java/com/generoso/ft/sd/steps/MetricsStepDefinitions.java @@ -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); } @@ -61,9 +61,9 @@ private double getResourceAndStatusCounterValue(List metrics, Stri private double getResourceAndStatusCounterValue(List 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 metricFamilies, String metricName, List> filters) { @@ -73,15 +73,15 @@ private double sumCounterMetric(List metricFamilies, String metric private double sumMetric(List metricFamilies, String metricName, MetricType metricType, List> 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 getMetricsStreamWithNameAndType(List 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 applyFilters(Stream metricsStream, List> filters) { diff --git a/sd-ft/src/test/java/com/generoso/ft/sd/steps/ResponseStepDefinitions.java b/sd-ft/src/test/java/com/generoso/ft/sd/steps/ResponseStepDefinitions.java index 33b45f0..285ae7a 100644 --- a/sd-ft/src/test/java/com/generoso/ft/sd/steps/ResponseStepDefinitions.java +++ b/sd-ft/src/test/java/com/generoso/ft/sd/steps/ResponseStepDefinitions.java @@ -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 {