-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
12 changed files
with
198 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
title: Added new metric `hofund_web_server_info` with information about type and version of web server. | ||
authors: | ||
- name: Peter Zmilczak | ||
nick: marwin1991 | ||
url: https://github.com/marwin1991 | ||
type: added #[added/changed/deprecated/removed/fixed/security/other] | ||
issues: | ||
- 26 | ||
merge_requests: | ||
- 27 |
31 changes: 31 additions & 0 deletions
31
hofund-core/src/main/java/dev/logchange/hofund/web/HofundWebServerInfo.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,31 @@ | ||
package dev.logchange.hofund.web; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Getter | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class HofundWebServerInfo { | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
public static HofundWebServerInfo create(String name, String version) { | ||
log.info("Server name: " + name + " version: " + version); | ||
|
||
return HofundWebServerInfo.builder() | ||
.name(name) | ||
.version(version) | ||
.build(); | ||
} | ||
|
||
|
||
|
||
} | ||
|
42 changes: 42 additions & 0 deletions
42
hofund-core/src/main/java/dev/logchange/hofund/web/HofundWebServerInfoMeter.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,42 @@ | ||
package dev.logchange.hofund.web; | ||
|
||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class HofundWebServerInfoMeter implements MeterBinder { | ||
|
||
private static final String NAME = "hofund_web_server_info"; | ||
private static final String DESCRIPTION = "Basic information about web server that is running this application"; | ||
|
||
private final HofundWebServerInfo info; | ||
private final AtomicInteger atomicInteger; | ||
|
||
public HofundWebServerInfoMeter(HofundWebServerInfoProvider provider) { | ||
this.info = provider.get(); | ||
this.atomicInteger = new AtomicInteger(1); | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry meterRegistry) { | ||
Gauge.builder(NAME, atomicInteger, AtomicInteger::doubleValue) | ||
.description(DESCRIPTION) | ||
.tags(tags()) | ||
.register(meterRegistry); | ||
} | ||
|
||
private List<Tag> tags() { | ||
List<Tag> tags = new LinkedList<>(); | ||
|
||
tags.add(Tag.of("name", info.getName())); | ||
tags.add(Tag.of("version", info.getVersion())); | ||
|
||
return tags; | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
hofund-core/src/main/java/dev/logchange/hofund/web/HofundWebServerInfoProvider.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,8 @@ | ||
package dev.logchange.hofund.web; | ||
|
||
public interface HofundWebServerInfoProvider { | ||
|
||
HofundWebServerInfo get(); | ||
|
||
} | ||
|
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
34 changes: 34 additions & 0 deletions
34
...v/logchange/hofund/web/springboot/autoconfigure/HofundWebServerInfoAutoConfiguration.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,34 @@ | ||
package dev.logchange.hofund.web.springboot.autoconfigure; | ||
|
||
import dev.logchange.hofund.web.HofundWebServerInfo; | ||
import dev.logchange.hofund.web.HofundWebServerInfoMeter; | ||
import dev.logchange.hofund.web.HofundWebServerInfoProvider; | ||
import io.micrometer.prometheus.PrometheusMeterRegistry; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.catalina.util.ServerInfo; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration(proxyBeanMethods = false) | ||
//available since spring boot 2.4.0 | ||
//@ConditionalOnEnabledMetricsExport(value="prometheus") | ||
@ConditionalOnClass(PrometheusMeterRegistry.class) | ||
public class HofundWebServerInfoAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public HofundWebServerInfoMeter hofundWebServerInfoMeter(HofundWebServerInfoProvider provider) { | ||
return new HofundWebServerInfoMeter(provider); | ||
} | ||
|
||
|
||
@Bean | ||
@ConditionalOnClass(ServerInfo.class) | ||
public HofundWebServerInfoProvider tomcatHofundWebServerInfoProvider(){ | ||
return () -> HofundWebServerInfo.create("Apache Tomcat", ServerInfo.getServerNumber()); | ||
} | ||
|
||
} |
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
5 changes: 4 additions & 1 deletion
5
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
dev.logchange.hofund.info.springboot.autoconfigure.HofundInfoAutoConfiguration | ||
dev.logchange.hofund.git.springboot.autoconfigure.HofundGitInfoAutoConfiguration | ||
dev.logchange.hofund.connection.springboot.autoconfigure.HofundConnectionAutoConfiguration | ||
dev.logchange.hofund.graph.springboot.autoconfigure.HofundGraphAutoConfiguration | ||
dev.logchange.hofund.graph.springboot.autoconfigure.HofundGraphAutoConfiguration | ||
dev.logchange.hofund.java.springboot.autoconfigure.HofundJavaInfoAutoConfiguration | ||
dev.logchange.hofund.os.springboot.autoconfigure.HofundOsInfoAutoConfiguration | ||
dev.logchange.hofund.web.springboot.autoconfigure.HofundWebServerInfoAutoConfiguration |
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
43 changes: 43 additions & 0 deletions
43
...nd-spring-boot-e2e/src/test/java/dev/logchange/hofund/web/HofundWebServerInfoE2ETest.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,43 @@ | ||
package dev.logchange.hofund.web; | ||
|
||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.catalina.util.ServerInfo; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
|
||
@Slf4j | ||
@AutoConfigureObservability | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class HofundWebServerInfoE2ETest { | ||
|
||
private final TestRestTemplate template = new TestRestTemplate(); | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@Test | ||
void shouldContainsHofundOsInfo() { | ||
//given: | ||
String path = "http://localhost:" + port + "/actuator/prometheus"; | ||
|
||
String version = ServerInfo.getServerNumber(); | ||
|
||
String expected = | ||
"# HELP hofund_web_server_info Basic information about web server that is running this application\n" + | ||
"# TYPE hofund_web_server_info gauge\n" + | ||
"hofund_web_server_info{name=\"Apache Tomcat\",version=\"{version}\",} 1.0" | ||
.replace("{version}", version); | ||
|
||
//when: | ||
String response = template.getForObject(path, String.class); | ||
|
||
//then: | ||
log.info("Expecting: \n{}\nResponse: \n{}", expected, response); | ||
Assertions.assertTrue(response.contains(expected)); | ||
} | ||
} |
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