generated from it-at-m/oss-repository-en-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enabled metrics endpoint * added dependency * added dependencies * Standard metrics can be opened * Monitoring the inflight metric * Monitoring the count of Ereignistyp * Fixed metrics name * Spotless * Processing time metric not working * Time metric works * Spotless * Checkstyle * Added license * Configuration of metric names * Configuration of metric names * reformated the file * Tests fixed * Maximum file size metric * Tests fixed * Spotless * RELEASENOTES * Tests fixed * Removed unused constructor
- Loading branch information
Showing
11 changed files
with
278 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/de/muenchen/mobidam/config/MetricsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* The MIT License | ||
* Copyright © 2024 Landeshauptstadt München | it@M | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package de.muenchen.mobidam.config; | ||
|
||
import de.muenchen.mobidam.security.FileSizeProcessor; | ||
import io.micrometer.core.instrument.Counter; | ||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Timer; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.camel.CamelContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Getter | ||
@Setter | ||
public class MetricsConfiguration { | ||
|
||
private final MeterRegistry meterRegistry; | ||
private final MetricsNameConfig metricsNameConfig; | ||
private final CamelContext camelContext; | ||
private final FileSizeProcessor fileSizeProcessor; | ||
|
||
private final Counter beginnCounter; | ||
private final Counter endeCounter; | ||
private final Counter fehlerCounter; | ||
private final Counter erfolgCounter; | ||
private final Counter warnungenCounter; | ||
private final Gauge inflightExchanges; | ||
private final Gauge maxFileSize; | ||
private Timer processingTime; | ||
|
||
public MetricsConfiguration(final MeterRegistry meterRegistry, MetricsNameConfig metricsNameConfig, CamelContext camelContext, | ||
FileSizeProcessor fileSizeProcessor) { | ||
this.meterRegistry = meterRegistry; | ||
this.metricsNameConfig = metricsNameConfig; | ||
this.camelContext = camelContext; | ||
this.fileSizeProcessor = fileSizeProcessor; | ||
this.beginnCounter = Counter.builder(metricsNameConfig.getBeginnCounterMetric()).register(meterRegistry); | ||
this.endeCounter = Counter.builder(metricsNameConfig.getEndCounterMetric()).register(meterRegistry); | ||
this.fehlerCounter = Counter.builder(metricsNameConfig.getFehlerCounterMetric()).register(meterRegistry); | ||
this.erfolgCounter = Counter.builder(metricsNameConfig.getErfolgCounterMetric()).register(meterRegistry); | ||
this.warnungenCounter = Counter.builder(metricsNameConfig.getWarnungenCounterMetric()).register(meterRegistry); | ||
this.inflightExchanges = Gauge.builder(metricsNameConfig.getInflightExchangesMetric(), camelContext, context -> context.getInflightRepository().size()) | ||
.register(meterRegistry); | ||
this.processingTime = Timer.builder(metricsNameConfig.getProcessingTimeMetric()).register(meterRegistry); | ||
this.maxFileSize = Gauge.builder(metricsNameConfig.getMaxFileSizeMetric(), fileSizeProcessor::getMaxStreamSize).register(meterRegistry); | ||
|
||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/de/muenchen/mobidam/config/MetricsNameConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* The MIT License | ||
* Copyright © 2024 Landeshauptstadt München | it@M | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package de.muenchen.mobidam.config; | ||
|
||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@Getter | ||
public class MetricsNameConfig { | ||
|
||
@Value("${mobidam.metrics.beginn-counter-metric}") | ||
private String beginnCounterMetric; | ||
@Value("${mobidam.metrics.ende-counter-metric}") | ||
private String endCounterMetric; | ||
@Value("${mobidam.metrics.erfolg-counter-metric}") | ||
private String erfolgCounterMetric; | ||
@Value("${mobidam.metrics.fehler-counter-metric}") | ||
private String fehlerCounterMetric; | ||
@Value("${mobidam.metrics.warnungen-counter-metric}") | ||
private String warnungenCounterMetric; | ||
@Value("${mobidam.metrics.processing-time-metric}") | ||
private String processingTimeMetric; | ||
@Value("${mobidam.metrics.inflight-exchanges-metric}") | ||
private String inflightExchangesMetric; | ||
@Value("${mobidam.metrics.max-file-size-metric}") | ||
private String maxFileSizeMetric; | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/de/muenchen/mobidam/config/SecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* The MIT License | ||
* Copyright © 2024 Landeshauptstadt München | it@M | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package de.muenchen.mobidam.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | ||
|
||
/** | ||
* The central class for configuration of all security aspects. | ||
*/ | ||
@Configuration | ||
@Profile("!no-security") | ||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) | ||
public class SecurityConfiguration { | ||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception { | ||
|
||
return http | ||
.authorizeHttpRequests((requests) -> requests.requestMatchers( | ||
// allow access to /actuator/info | ||
AntPathRequestMatcher.antMatcher("/actuator/info"), | ||
// allow access to /actuator/health for OpenShift Health Check | ||
AntPathRequestMatcher.antMatcher("/actuator/health"), | ||
// allow access to single metrics values | ||
AntPathRequestMatcher.antMatcher("/actuator/metrics/*"), | ||
// allow access to /actuator/metrics for Prometheus monitoring in OpenShift | ||
AntPathRequestMatcher.antMatcher("/actuator/metrics")) | ||
.permitAll()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/de/muenchen/mobidam/security/FileSizeProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* The MIT License | ||
* Copyright © 2024 Landeshauptstadt München | it@M | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package de.muenchen.mobidam.security; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.Processor; | ||
import org.apache.camel.converter.stream.InputStreamCache; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@NoArgsConstructor | ||
@Slf4j | ||
@Getter | ||
public class FileSizeProcessor implements Processor { | ||
|
||
private long maxStreamSize = 0L; | ||
|
||
@Override | ||
public void process(Exchange exchange) throws Exception { | ||
InputStreamCache stream = exchange.getMessage().getBody(InputStreamCache.class); | ||
stream.reset(); | ||
maxStreamSize = Math.max(maxStreamSize, stream.length()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters