-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from logchange/24-git-info-default-values
added git-info default values
- Loading branch information
Showing
12 changed files
with
292 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
title: Simplified configuration of metric `hofund_git_info` by reading values from `git.properties` file instead of defining `hofund.git-info`. You can still use this to define custom values for this metric. | ||
authors: | ||
- name: Peter Zmilczak | ||
nick: marwin1991 | ||
url: https://github.com/marwin1991 | ||
type: changed #[added/changed/deprecated/removed/fixed/security/other] | ||
issues: | ||
- 24 | ||
merge_requests: | ||
- 25 |
51 changes: 51 additions & 0 deletions
51
...ava/dev/logchange/hofund/git/springboot/autoconfigure/HofundDefaultGitInfoProperties.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,51 @@ | ||
package dev.logchange.hofund.git.springboot.autoconfigure; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Getter | ||
@Setter | ||
@Component | ||
@PropertySource(value = "git.properties", ignoreResourceNotFound = true) | ||
@RequiredArgsConstructor | ||
public class HofundDefaultGitInfoProperties { | ||
|
||
private final Environment env; | ||
|
||
public String getCommitId(){ | ||
return get("git.commit.id"); | ||
} | ||
|
||
public String getCommitIdAbbrev(){ | ||
return get("git.commit.id.abbrev"); | ||
} | ||
|
||
public String getDirty(){ | ||
return get("git.dirty"); | ||
} | ||
|
||
public String getBranch(){ | ||
return get("git.branch"); | ||
} | ||
|
||
public String getBuildHost(){ | ||
return get("git.build.host"); | ||
} | ||
|
||
public String getBuildTime(){ | ||
return get("git.build.time"); | ||
} | ||
|
||
private String get(String key){ | ||
String value = env.getProperty(key); | ||
if (value == null){ | ||
return ""; | ||
} | ||
|
||
return value; | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
hofund-spring-boot-e2e/src/main/resources/application.properties
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 +1,2 @@ | ||
server.port=8626 | ||
management.endpoints.web.exposure.include=prometheus |
50 changes: 50 additions & 0 deletions
50
...d-spring-boot-e2e/src/test/java/dev/logchange/hofund/git/HofundDefaultGitInfoE2ETest.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 @@ | ||
package dev.logchange.hofund.git; | ||
|
||
|
||
import lombok.extern.slf4j.Slf4j; | ||
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; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
|
||
@Slf4j | ||
@AutoConfigureObservability | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class HofundDefaultGitInfoE2ETest { | ||
|
||
private final TestRestTemplate template = new TestRestTemplate(); | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@DynamicPropertySource | ||
static void registerPgProperties(DynamicPropertyRegistry registry) { | ||
registry.add("git.commit.id", () -> 123456); | ||
registry.add("git.commit.id.abbrev", () -> "abcdef"); | ||
registry.add("git.dirty", () -> false); | ||
registry.add("git.branch", () -> "alaMaKota"); | ||
registry.add("git.build.host", () -> "someHostName"); | ||
registry.add("git.build.time", () -> "11:12:33T17-02-2023"); | ||
} | ||
|
||
@Test | ||
void shouldContainsHofundDefaultGitInfoWithValuesFromGitProperties() { | ||
//given: | ||
String path = "http://localhost:" + port + "/actuator/prometheus"; | ||
|
||
String expected = "# HELP hofund_git_info Basic information about application based on git\n" + | ||
"# TYPE hofund_git_info gauge\n" + | ||
"hofund_git_info{branch=\"alaMaKota\",build_host=\"someHostName\",build_time=\"11:12:33T17-02-2023\",commit_id=\"abcdef\",dirty=\"false\",} 1.0"; | ||
|
||
//when: | ||
String response = template.getForObject(path, String.class); | ||
|
||
//then: | ||
log.info("Expecting: \n{}\nResponse: \n{}", expected, response); | ||
Assertions.assertTrue(response.contains(expected)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
hofund-spring-boot-e2e/src/test/java/dev/logchange/hofund/git/HofundGitInfoE2ETest.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,46 @@ | ||
package dev.logchange.hofund.git; | ||
|
||
|
||
import lombok.extern.slf4j.Slf4j; | ||
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, properties = { | ||
"hofund.git-info.commit.id=SomeIdForTest", | ||
"hofund.git-info.commit.id-abbrev=someAbbrevIdForE2eTest", | ||
"hofund.git-info.dirty=true", | ||
"hofund.git-info.branch=feature-1-for-test-e2e", | ||
"hofund.git-info.build.host=someHostForTest", | ||
"hofund.git-info.build.time=14:12:13T11-11-2023" | ||
}) | ||
public class HofundGitInfoE2ETest { | ||
|
||
private final TestRestTemplate template = new TestRestTemplate(); | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@Test | ||
void shouldContainsHofundDefaultGitInfoWithValuesFromGitProperties() { | ||
//given: | ||
String path = "http://localhost:" + port + "/actuator/prometheus"; | ||
|
||
String expected = | ||
"# HELP hofund_git_info Basic information about application based on git\n" + | ||
"# TYPE hofund_git_info gauge\n" + | ||
"hofund_git_info{branch=\"feature-1-for-test-e2e\",build_host=\"someHostForTest\",build_time=\"14:12:13T11-11-2023\",commit_id=\"someAbbrevIdForE2eTest\",dirty=\"true\",} 1.0"; | ||
|
||
//when: | ||
String response = template.getForObject(path, String.class); | ||
|
||
//then: | ||
log.info("Expecting: \n{}\nResponse: \n{}", expected, response); | ||
Assertions.assertTrue(response.contains(expected)); | ||
} | ||
} |
Oops, something went wrong.