Skip to content

Commit

Permalink
✨ info git/build info at startup #249
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Jun 3, 2024
1 parent 32a2cef commit 82ce6a6
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 55 deletions.
2 changes: 1 addition & 1 deletion observe/docs
2 changes: 1 addition & 1 deletion observe/mirana
Submodule mirana updated 27 files
+9 −5 src/main/java/pro/fessional/mirana/best/Param.java
+3 −3 src/main/java/pro/fessional/mirana/bits/Base64.java
+3 −3 src/main/java/pro/fessional/mirana/bits/Bytes.java
+2 −2 src/main/java/pro/fessional/mirana/bits/Md5.java
+4 −4 src/main/java/pro/fessional/mirana/bits/MdHelp.java
+1 −1 src/main/java/pro/fessional/mirana/code/Crc8Long.java
+2 −2 src/main/java/pro/fessional/mirana/code/Crc8LongUtil.java
+10 −10 src/main/java/pro/fessional/mirana/code/RandCode.java
+3 −3 src/main/java/pro/fessional/mirana/dync/Java.java
+1 −1 src/main/java/pro/fessional/mirana/func/Lam.java
+5 −5 src/main/java/pro/fessional/mirana/id/Ulid.java
+1 −1 src/main/java/pro/fessional/mirana/io/InputStreams.java
+4 −4 src/main/java/pro/fessional/mirana/math/ComparableUtil.java
+1 −1 src/main/java/pro/fessional/mirana/netx/SslTrustAll.java
+16 −16 src/main/java/pro/fessional/mirana/page/PageResult.java
+1 −1 src/main/java/pro/fessional/mirana/pain/ThrowableUtil.java
+16 −14 src/main/java/pro/fessional/mirana/stat/GitStat.java
+2 −2 src/main/java/pro/fessional/mirana/stat/JvmStat.java
+11 −11 src/main/java/pro/fessional/mirana/text/BarString.java
+37 −15 src/main/java/pro/fessional/mirana/text/FormatUtil.java
+4 −4 src/main/java/pro/fessional/mirana/text/HalfCharUtil.java
+34 −34 src/main/java/pro/fessional/mirana/text/WhiteUtil.java
+1 −1 src/main/java/pro/fessional/mirana/text/Wildcard.java
+1 −1 src/main/java/pro/fessional/mirana/time/DateFormatter.java
+4 −4 src/main/java/pro/fessional/mirana/time/DateParser.java
+2 −2 src/main/java/pro/fessional/mirana/tk/TicketHelp.java
+6 −1 src/test/java/pro/fessional/mirana/text/FormatUtilTest.java
12 changes: 7 additions & 5 deletions observe/scripts/wings-starter.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash -e
THIS_VERSION=2024-03-05
THIS_VERSION=2024-06-01
################ system env to use ################
# JAVA_HOME # if JDK_HOME is not valid
# JAVA_OPTS # prepend to java args
Expand Down Expand Up @@ -590,11 +590,13 @@ case "$ARGS_RUN" in

if id | grep -q '(sudo)'; then
if which jhsdb &> /dev/null; then
echo -e "\033[37;42;1mINFO: sudo $(which jhsdb) jmap --heap --pid $cid \033[m"
sudo jhsdb jmap --heap --pid "$cid"
_jhsdb=$(which jhsdb)
echo -e "\033[37;42;1mINFO: sudo $_jhsdb jmap --heap --pid $cid \033[m"
sudo "$_jhsdb" jmap --heap --pid "$cid"
else
echo -e "\033[37;42;1mINFO: sudo $(which jmap) -heap $cid \033[m"
sudo jmap -heap "$cid"
_jmap=$(which jmap)
echo -e "\033[37;42;1mINFO: sudo $_jmap -heap $cid \033[m"
sudo "$_jmap" -heap "$cid"
fi
else
if which jhsdb &> /dev/null; then
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,12 @@
<includeOnlyProperty>git.branch</includeOnlyProperty>
<includeOnlyProperty>git.build.(host|time|version|user.name|number.*)</includeOnlyProperty>
<includeOnlyProperty>git.closest.*</includeOnlyProperty>
<includeOnlyProperty>git.commit.(time|user.name|id.abbrev|id.full|message.full)</includeOnlyProperty>
<includeOnlyProperty>git.commit.(time|user.name|id|id.abbrev|id.full|message.full)</includeOnlyProperty>
<includeOnlyProperty>git.dirty</includeOnlyProperty>
<includeOnlyProperty>git.local.*</includeOnlyProperty>
<includeOnlyProperty>git.tags</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
<commitIdGenerationMode>flat</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.apache.commons.logging.LogFactory;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.info.GitProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pro.fessional.wings.silencer.modulate.RuntimeMode;
Expand All @@ -17,6 +19,7 @@
import pro.fessional.wings.silencer.spring.WingsOrdered;
import pro.fessional.wings.silencer.spring.boot.ConditionalWingsEnabled;
import pro.fessional.wings.silencer.spring.help.ApplicationContextHelper;
import pro.fessional.wings.silencer.spring.help.VersionInfoHelper;
import pro.fessional.wings.silencer.spring.prop.SilencerAutoLogProp;
import pro.fessional.wings.silencer.spring.prop.SilencerEnabledProp;
import pro.fessional.wings.silencer.spring.prop.SilencerRuntimeProp;
Expand Down Expand Up @@ -46,7 +49,7 @@ public class SilencerCurseConfiguration {
@ConditionalWingsEnabled(abs = SilencerEnabledProp.Key$auditProp, value = false)
public ApplicationInspectRunner auditPropRunner() {
log.info("SilencerCurse spring-bean auditPropRunner");
return new ApplicationInspectRunner(WingsOrdered.Lv5Supervisor, ignored -> {
return new ApplicationInspectRunner(WingsOrdered.Lv4Application, ignored -> {
final Map<String, List<String>> map = ApplicationContextHelper.listPropertySource();
final Map<String, List<String>> key = new LinkedHashMap<>();

Expand Down Expand Up @@ -74,15 +77,38 @@ public ApplicationInspectRunner auditPropRunner() {
});
}

@Bean
@ConditionalWingsEnabled
public ApplicationInspectRunner infoGitJvmRunner(ApplicationContext context) {
log.info("Silencer spring-runs infoGitJvmRunner");
return new ApplicationInspectRunner(WingsOrdered.Lv1Config, args -> {


log.info("jvm-name=" + VersionInfoHelper.jvmName());
log.info("jvm-version=" + VersionInfoHelper.jvmVersion());
log.info("jvm-vendor=" + VersionInfoHelper.jvmVendor());

var git = context.getBean(GitProperties.class);
log.info("git-branch=" + VersionInfoHelper.branch(git));
log.info("git-id=" + VersionInfoHelper.commitId(git));
log.info("git-time=" + VersionInfoHelper.commitDateTime(git));
log.info("git-build=" + VersionInfoHelper.buildDateTime(git));
log.info("git-version=" + VersionInfoHelper.buildVersion(git));
log.info("git-message=" + VersionInfoHelper.commitMessage(git));
});
}

public static final int OrderMuteConsoleRunner = WingsOrdered.Lv5Supervisor + WingsOrdered.PrDog;

/**
* Configuration is complete and the log is switched before the service starts
* Configuration is complete and the log is switched before the service starts, should run at last
*/
@Bean
@ConditionalWingsEnabled(abs = SilencerEnabledProp.Key$muteConsole)
@ConditionalOnClass(ConsoleAppender.class)
public ApplicationReadyEventRunner muteConsoleRunner(SilencerAutoLogProp autoLog) {
log.info("SilencerCurse spring-runs muteConsoleRunner");
return new ApplicationReadyEventRunner(WingsOrdered.Lv1Config, ignored -> {
return new ApplicationReadyEventRunner(OrderMuteConsoleRunner, ignored -> {
final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
final Set<String> targets = autoLog.getTarget();
final Set<String> exists = autoLog.getExists();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package pro.fessional.wings.silencer.spring.help;

import org.springframework.boot.info.GitProperties;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import static pro.fessional.wings.silencer.datetime.DateTimePattern.FMT_DATE_10;
import static pro.fessional.wings.silencer.datetime.DateTimePattern.FMT_FULL_19Z;

/**
* @author trydofor
* @since 2024-06-03
*/
public class VersionInfoHelper {

public static String jvmName() {
return System.getProperty("java.vm.name");
}

public static String jvmVersion() {
return System.getProperty("java.vm.version");
}

public static String jvmVendor() {
return System.getProperty("java.vm.vendor");
}

////
public static String branch(GitProperties git) {
return git == null ? null : git.getBranch();
}

public static String commitIdShort(GitProperties git) {
return git == null ? null : git.getShortCommitId();
}

public static String commitId(GitProperties git) {
if (git == null) return null;
String id = git.getCommitId();
return id != null ? id : git.get("commit.id.full");
}

public static String commitDateTime(GitProperties git) {
return git == null ? null : toDatetime(git.getCommitTime());
}
public static String commitDate(GitProperties git) {
return git == null ? null : toDate(git.getCommitTime());
}

public static String commitMessage(GitProperties git) {
return git == null ? null : git.get("commit.message.full");
}

public static String buildDateTime(GitProperties git) {
return git == null ? null : toDatetime(git.getInstant("build.time"));
}
public static String buildDate(GitProperties git) {
return git == null ? null : toDate(git.getInstant("build.time"));
}

public static String buildVersion(GitProperties git) {
return git == null ? null : git.get("build.version");
}

private static String toDatetime(Instant time) {
if (time == null) return null;
ZonedDateTime zdt = ZonedDateTime.ofInstant(time, ZoneId.systemDefault());
return FMT_FULL_19Z.format(zdt);
}

private static String toDate(Instant time) {
if (time == null) return null;
ZonedDateTime zdt = ZonedDateTime.ofInstant(time, ZoneId.systemDefault());
return FMT_DATE_10.format(zdt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package pro.fessional.wings.silencer.spring.help;

import io.qameta.allure.TmsLink;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.info.GitProperties;
import org.springframework.boot.info.JavaInfo;
import org.springframework.boot.test.context.SpringBootTest;

/**
* @author trydofor
* @since 2024-06-03
*/
@SpringBootTest
@Slf4j
class VersionInfoHelperTest {

@Setter(onMethod_ = { @Autowired })
private BuildProperties buildProperties;

@Setter(onMethod_ = {@Autowired})
private GitProperties gitProperties;

@Test
@TmsLink("C11004")
public void infoBuildAndGit() {
JavaInfo javaInfo = new JavaInfo();
log.info("java={}", javaInfo);
log.info("build={}", buildProperties);
log.info("git={}", gitProperties);

Assertions.assertEquals("pro.fessional.wings",buildProperties.getGroup());
Assertions.assertEquals("silencer-curse",buildProperties.getArtifact());
Assertions.assertNotNull(gitProperties.getBranch());
// spring use git.commit.id, need commitIdGenerationMode=flat
Assertions.assertNotNull(gitProperties.getCommitId());
Assertions.assertNotNull(gitProperties.getCommitTime());

// safe and format
Assertions.assertNotNull(VersionInfoHelper.jvmName());
Assertions.assertNotNull(VersionInfoHelper.jvmVersion());
Assertions.assertNotNull(VersionInfoHelper.jvmVendor());
Assertions.assertNotNull(VersionInfoHelper.commitIdShort(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.commitId(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.commitDate(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.commitDateTime(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.commitMessage(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.branch(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.buildDate(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.buildDateTime(gitProperties));
Assertions.assertNotNull(VersionInfoHelper.buildVersion(gitProperties));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.Map;
import java.util.function.Consumer;

import static pro.fessional.wings.silencer.datetime.DateTimePattern.FMT_FULL_19Z;

/**
* <a href="https://developers.dingtalk.com/document/app/custom-robot-access">Dingtalk robot</a>
*
Expand All @@ -27,6 +29,8 @@ public class DingTalkReport implements WarnReport {
private final String dingConfig;
private final DingTalkNotice dingTalkNotice;

protected String gitInfo = null;

public DingTalkReport(DingTalkNotice notice, String config) {
this.dingTalkNotice = notice;
this.dingConfig = config;
Expand Down Expand Up @@ -85,17 +89,20 @@ public String buildMkContent(String app, String jvm, Consumer<StringBuilder> bui
StringBuilder sb = new StringBuilder();
mkTitleH2(sb, app);
mkItemText(sb, jvm, "jvm-name");
mkItemText(sb, Now.zonedDateTime().toString(), "rpt-time");
mkItemText(sb, gitInfo, "git-info");
mkItemText(sb, FMT_FULL_19Z.format(Now.zonedDateTime()), "rpt-time");
builder.accept(sb);
return sb.toString();
}

protected void mkTitleH2(StringBuilder sb, String str) {
if (str == null) return;
sb.append("\n\n## ■ ")
.append(str);
}

protected void mkItemText(StringBuilder sb, String value, String key) {
if (value == null) return;
sb.append("\n- ")
.append(value)
.append(" | ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.info.GitProperties;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -26,6 +27,10 @@
import java.io.File;
import java.util.Map;

import static pro.fessional.wings.silencer.spring.help.VersionInfoHelper.branch;
import static pro.fessional.wings.silencer.spring.help.VersionInfoHelper.buildDate;
import static pro.fessional.wings.silencer.spring.help.VersionInfoHelper.commitIdShort;

/**
* @author trydofor
* @since 2019-06-29
Expand Down Expand Up @@ -116,10 +121,12 @@ public JvmMetric jvmMonitor(SlardarMonitorProp prop) {

@Bean
@ConditionalWingsEnabled
public DingTalkReport dingTalkReport(DingTalkNotice dingTalkNotice, SlardarMonitorProp prop) {
public DingTalkReport dingTalkReport(DingTalkNotice dingTalkNotice, SlardarMonitorProp prop, GitProperties git) {
final String name = prop.getDingNotice();
log.info("Slardar spring-bean dingTalkReport, conf=" + name);
return new DingTalkReport(dingTalkNotice, name);
DingTalkReport bean = new DingTalkReport(dingTalkNotice, name);
bean.setGitInfo(commitIdShort(git) + " " + buildDate(git) + " " + branch(git));
return bean;
}

@Bean
Expand Down

0 comments on commit 82ce6a6

Please sign in to comment.