Skip to content

Commit fc1dbdc

Browse files
committed
[#11758] Separate banner into module
1 parent 692bbf5 commit fc1dbdc

File tree

17 files changed

+264
-174
lines changed

17 files changed

+264
-174
lines changed

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/PinpointStarter.java

-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.navercorp.pinpoint.ProductInfo;
1818
import com.navercorp.pinpoint.bootstrap.agentdir.AgentDirectory;
1919
import com.navercorp.pinpoint.bootstrap.agentdir.LogDirCleaner;
20-
import com.navercorp.pinpoint.bootstrap.banner.PinpointBannerImpl;
2120
import com.navercorp.pinpoint.bootstrap.classloader.PinpointClassLoaderFactory;
2221
import com.navercorp.pinpoint.bootstrap.classloader.ProfilerLibs;
2322
import com.navercorp.pinpoint.bootstrap.config.DefaultProfilerConfig;
@@ -26,7 +25,6 @@
2625
import com.navercorp.pinpoint.bootstrap.config.PropertyLoader;
2726
import com.navercorp.pinpoint.bootstrap.config.PropertyLoaderFactory;
2827
import com.navercorp.pinpoint.common.Version;
29-
import com.navercorp.pinpoint.common.banner.PinpointBanner;
3028
import com.navercorp.pinpoint.common.util.OsEnvSimpleProperty;
3129
import com.navercorp.pinpoint.common.util.PropertySnapshot;
3230
import com.navercorp.pinpoint.common.util.SimpleProperty;
@@ -152,11 +150,6 @@ boolean start() {
152150
pinpointAgent.registerStopHandler();
153151

154152
logger.info("pinpoint agent started normally.");
155-
156-
final PinpointBannerImpl banner = new PinpointBannerImpl(profilerConfig.readList("pinpoint.banner.configs"), logger);
157-
banner.setPinpointBannerMode(PinpointBanner.Mode.valueOf(profilerConfig.readString("pinpoint.banner.mode", "CONSOLE").toUpperCase()));
158-
banner.setPinpointBannerProperty(properties);
159-
banner.printBanner();
160153
} catch (Exception e) {
161154
// unexpected exception that did not be checked above
162155
logger.warn(ProductInfo.NAME + " start failed.", e);

agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/banner/PinpointBannerImpl.java

-61
This file was deleted.

agent-module/profiler/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
<groupId>com.navercorp.pinpoint</groupId>
3939
<artifactId>pinpoint-annotations</artifactId>
4040
</dependency>
41+
<dependency>
42+
<groupId>com.navercorp.pinpoint</groupId>
43+
<artifactId>pinpoint-banner</artifactId>
44+
</dependency>
4145
<dependency>
4246
<groupId>com.navercorp.pinpoint</groupId>
4347
<artifactId>pinpoint-commons</artifactId>

agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/DefaultAgent.java

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.navercorp.pinpoint.profiler;
1818

1919
import com.navercorp.pinpoint.ProductInfo;
20+
import com.navercorp.pinpoint.banner.PinpointBanner;
2021
import com.navercorp.pinpoint.bootstrap.Agent;
2122
import com.navercorp.pinpoint.bootstrap.AgentOption;
2223
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
@@ -37,6 +38,7 @@
3738

3839
import java.nio.file.Path;
3940
import java.nio.file.Paths;
41+
import java.util.List;
4042
import java.util.Map;
4143
import java.util.Objects;
4244
import java.util.Properties;
@@ -158,8 +160,18 @@ public void start() {
158160
return;
159161
}
160162
}
163+
161164
logger.info("Starting {} Agent.", ProductInfo.NAME);
162165
this.applicationContext.start();
166+
printBanner();
167+
}
168+
169+
private void printBanner() {
170+
List<String> dumpKeys = profilerConfig.readList("pinpoint.banner.configs");
171+
PinpointBanner.Mode mode = PinpointBanner.Mode.valueOf(profilerConfig.readString("pinpoint.banner.mode", "CONSOLE").toUpperCase());
172+
Properties properties = profilerConfig.getProperties();
173+
final PinpointBanner banner = new PinpointBanner(mode, dumpKeys, properties::getProperty, logger::info);
174+
banner.printBanner();
163175
}
164176

165177
@Override

banner/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# pinpoint-banner

banner/pom.xml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>com.navercorp.pinpoint</groupId>
7+
<artifactId>pinpoint</artifactId>
8+
<version>3.1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>pinpoint-banner</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<dependencies>
15+
16+
<!-- Logging dependencies -->
17+
<dependency>
18+
<groupId>org.apache.logging.log4j</groupId>
19+
<artifactId>log4j-api</artifactId>
20+
<scope>test</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.logging.log4j</groupId>
24+
<artifactId>log4j-core</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
28+
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.codehaus.mojo</groupId>
35+
<artifactId>templating-maven-plugin</artifactId>
36+
</plugin>
37+
</plugins>
38+
</build>
39+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.navercorp.pinpoint.banner;
2+
3+
class BannerVersionTemplate {
4+
static final String VERSION = "${project.version}";
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.navercorp.pinpoint.banner;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.io.InputStreamReader;
7+
import java.io.Reader;
8+
import java.nio.charset.Charset;
9+
import java.nio.charset.StandardCharsets;
10+
11+
class BannerUtils {
12+
13+
static String readAllString(InputStream inputStream, Charset charset) throws IOException {
14+
try (Reader inputStreamReader = new InputStreamReader(inputStream, charset);
15+
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
16+
StringBuilder buffer = new StringBuilder(64);
17+
String line;
18+
while ((line = bufferedReader.readLine()) != null) {
19+
buffer.append(line);
20+
buffer.append(System.lineSeparator());
21+
}
22+
return buffer.toString();
23+
}
24+
}
25+
26+
static String banner() {
27+
return banner("/pinpoint-banner/banner.txt");
28+
}
29+
30+
private static String banner(String bannerFile) {
31+
try (InputStream inputStream = BannerUtils.class.getResourceAsStream(bannerFile)) {
32+
return BannerUtils.readAllString(inputStream, StandardCharsets.UTF_8);
33+
} catch (IOException e) {
34+
throw new RuntimeException("banner IO failed", e);
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.navercorp.pinpoint.banner;
2+
3+
import java.util.Collection;
4+
import java.util.Objects;
5+
import java.util.function.Consumer;
6+
import java.util.function.Function;
7+
8+
public class PinpointBanner {
9+
private final Mode bannerMode;
10+
private final Collection<String> dumpKeys;
11+
private final Function<String, String> properties;
12+
private final Consumer<String> consoleWriter = System.out::println;
13+
private final Consumer<String> loggerWriter;
14+
15+
public PinpointBanner(Mode bannerMode,
16+
Collection<String> dumpKeys,
17+
Function<String, String> properties,
18+
Consumer<String> loggerWriter) {
19+
this.bannerMode = Objects.requireNonNull(bannerMode, "bannerMode");
20+
this.dumpKeys = Objects.requireNonNull(dumpKeys, "dumpKeys");
21+
this.properties = Objects.requireNonNull(properties, "properties");
22+
this.loggerWriter = Objects.requireNonNull(loggerWriter, "loggerWriter");
23+
}
24+
25+
26+
public void printBanner() {
27+
switch (bannerMode) {
28+
case OFF:
29+
return;
30+
case LOG:
31+
loggerWriter.accept(buildBannerString());
32+
return;
33+
default:
34+
consoleWriter.accept(buildBannerString());
35+
}
36+
}
37+
38+
private String buildBannerString() {
39+
StringBuilder banner = new StringBuilder(128);
40+
banner.append(BannerUtils.banner());
41+
banner.append(format("Pinpoint Version", BannerVersionTemplate.VERSION));
42+
banner.append(System.lineSeparator());
43+
44+
for (String key : dumpKeys) {
45+
String value = properties.apply(key);
46+
if (value != null) {
47+
banner.append(format(key, value));
48+
banner.append(System.lineSeparator());
49+
}
50+
}
51+
return banner.toString();
52+
}
53+
54+
protected String format(String key, String value) {
55+
return String.format(" :: %55s :: %35s", key, value);
56+
}
57+
58+
public enum Mode {
59+
OFF,
60+
CONSOLE,
61+
LOG;
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
88888888ba 88 888b 88 88888888ba ,ad8888ba, 88 888b 88 888888888888
3+
88 ,8P 88 88 `8b 88 88 ,8P d8' `8b 88 88 `8b 88 88
4+
88aaaaaa8P' 88 88 `8b 88 88aaaaaa8P' 88 da 88 88 88 `8b 88 88
5+
88 88 88 `8b 88 88 Y8, ,8P 88 88 `8b 88 88
6+
88 88 88 `888 88 `"Y8888Y"' 88 88 `888 88
7+
8+
https://github.com/pinpoint-apm/pinpoint
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.navercorp.pinpoint.banner;
2+
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
import org.junit.jupiter.api.Test;
6+
7+
8+
class BannerUtilsTest {
9+
private final Logger logger = LogManager.getLogger(this.getClass());
10+
11+
@Test
12+
void banner() {
13+
String banner = BannerUtils.banner();
14+
logger.debug("--------");
15+
logger.debug(banner);
16+
logger.debug("--------");
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.navercorp.pinpoint.banner;
2+
3+
import org.apache.logging.log4j.LogManager;
4+
import org.apache.logging.log4j.Logger;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Collections;
8+
import java.util.Enumeration;
9+
import java.util.List;
10+
import java.util.Properties;
11+
12+
class PinpointBannerTest {
13+
private final Logger logger = LogManager.getLogger(this.getClass());
14+
15+
@Test
16+
void printBanner() {
17+
Properties properties = new Properties();
18+
properties.put("aaa", "111");
19+
properties.put("bbb", "222");
20+
List<String> dumpKeys = keyList(properties);
21+
22+
PinpointBanner banner = new PinpointBanner(PinpointBanner.Mode.LOG, dumpKeys,
23+
properties::getProperty, logger::info);
24+
banner.printBanner();
25+
}
26+
27+
private List<String> keyList(Properties properties) {
28+
@SuppressWarnings("unchecked")
29+
Enumeration<String> enumeration = (Enumeration<String>) properties.propertyNames();
30+
return Collections.list(enumeration);
31+
}
32+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Configuration status="INFO">
3+
<Properties>
4+
<Property name="console_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %clr{%-5level} %clr{%-40.40logger{1.}}{cyan}:%3L -- %msg{nolookups}%n</Property>
5+
<Property name="file_message_pattern">%d{MM-dd HH:mm:ss.sss} [%15.15t] %-5level %-40.40logger{1.}:%3L -- %msg{nolookups}%n</Property>
6+
</Properties>
7+
8+
<Appenders>
9+
<Console name="console" target="system_out">
10+
<PatternLayout pattern="${file_message_pattern}"/>
11+
</Console>
12+
</Appenders>
13+
14+
<Loggers>
15+
<Logger name="com.navercorp.pinpoint" level="DEBUG" additivity="false">
16+
<AppenderRef ref="console"/>
17+
</Logger>
18+
19+
<Root level="DEBUG">
20+
<AppenderRef ref="console"/>
21+
</Root>
22+
</Loggers>
23+
</Configuration>

commons-server/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
<artifactId>pinpoint-commons</artifactId>
5252
<scope>compile</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>com.navercorp.pinpoint</groupId>
56+
<artifactId>pinpoint-banner</artifactId>
57+
<scope>compile</scope>
58+
</dependency>
5459
<dependency>
5560
<groupId>com.navercorp.pinpoint</groupId>
5661
<artifactId>pinpoint-commons-profiler</artifactId>

0 commit comments

Comments
 (0)