Skip to content

Commit

Permalink
[#8580] Add Pinpoint Banner
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Jan 4, 2022
1 parent c95cdeb commit 5c04571
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 3 deletions.
27 changes: 27 additions & 0 deletions agent/src/main/resources/pinpoint-root.config
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,30 @@ profiler.server.tracerequestparam=true
profiler.server.realipheader=
# optional parameter, If the header value is ${profiler.server.realipemptyvalue}, Ignore header value.
profiler.server.realipemptyvalue=

###########################################################
# BANNER #
###########################################################
# Pinpoint Banner Settings
# Pinpoint banner mode : OFF, CONSOLE, LOG
pinpoint.banner.mode=console
pinpoint.banner.configs=pinpoint.profiler.profiles.active,\
pinpoint.applicationName,\
pinpoint.agentId,\
pinpoint.agentName,\
profiler.transport.module,\
profiler.transport.grpc.collector.ip,\
profiler.transport.grpc.agent.collector.port,\
profiler.transport.grpc.metadata.collector.port,\
profiler.transport.grpc.stat.collector.port,\
profiler.transport.grpc.span.collector.port,\
profiler.collector.ip,\
profiler.collector.span.port,\
profiler.collector.stat.port,\
profiler.collector.tcp.port,\
profiler.spandatasender.transport.type,\
profiler.statdatasender.transport.type,\
profiler.sampling.enable,\
profiler.sampling.type,\
profiler.sampling.counting.sampling-rate,\
profiler.sampling.percent.sampling-rate
22 changes: 21 additions & 1 deletion batch/src/main/resources/batch-root.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,24 @@ job.cleanup.inactive.agents=false
job.cleanup.inactive.agents.cron=

# Default value is 30 (minimum value is 30)
#job.cleanup.inactive.agents.duration.days=
#job.cleanup.inactive.agents.duration.days=

###########################################################
# BANNER #
###########################################################
# Pinpoint Banner Settings
# Pinpoint banner mode : OFF, CONSOLE, LOG
pinpoint.banner.mode=console
pinpoint.banner.configs=batch.server.env,\
pinpoint.url,\
alarm.mail.server.url,\
jdbc.url,\
meta.jdbc.url,\
batch.flink.server,\
job.cleanup.inactive.agents,\
job.cleanup.inactive.agents.cron,\
pinpoint.zookeeper.address,\
hbase.client.host,\
hbase.client.port,\
hbase.zookeeper.znode.parent,\
hbase.namespace
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.navercorp.pinpoint.bootstrap.config.PropertyLoader;
import com.navercorp.pinpoint.bootstrap.config.PropertyLoaderFactory;
import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.common.banner.PinpointBanner;
import com.navercorp.pinpoint.bootstrap.banner.PinpointBannerImpl;
import com.navercorp.pinpoint.common.util.OsEnvSimpleProperty;
import com.navercorp.pinpoint.common.util.PropertySnapshot;
import com.navercorp.pinpoint.common.util.SimpleProperty;
Expand Down Expand Up @@ -146,6 +148,11 @@ boolean start() {
pinpointAgent.registerStopHandler();

logger.info("pinpoint agent started normally.");

final PinpointBannerImpl banner = new PinpointBannerImpl(profilerConfig.readList("pinpoint.banner.configs"), logger);
banner.setPinpointBannerMode(PinpointBanner.Mode.valueOf(profilerConfig.readString("pinpoint.banner.mode", "CONSOLE").toUpperCase()));
banner.setPinpointBannerProperty(properties);
banner.printBanner();
} catch (Exception e) {
// unexpected exception that did not be checked above
logger.warn(ProductInfo.NAME + " start failed.", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.navercorp.pinpoint.bootstrap.banner;

import com.navercorp.pinpoint.bootstrap.BootLogger;
import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.common.banner.PinpointBanner;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.Objects;
import java.util.Properties;

public class PinpointBannerImpl extends PinpointBanner {
private BootLogger logger;
private Properties properties;

public PinpointBannerImpl(List<String> keysToPrint, BootLogger logger) {
this.pinpointBannerMode = Mode.CONSOLE;
this.logger = Objects.requireNonNull(logger, "logger");
this.keysToPrint = Objects.requireNonNull(keysToPrint, "keysToPrint");
}

public void setPinpointBannerProperty(Properties properties) {
this.properties = Objects.requireNonNull(properties, "properties");
}

@Override
public void setPinpointBannerMode(Mode mode) {
this.pinpointBannerMode = mode;
}

@Override
public void printBanner() {
if ( properties == null ) {
logger.warn("Property not ready for Pinpoint Banner");
return;
}

switch (this.pinpointBannerMode) {
case OFF:
return;
case LOG:
printBanner(logger);
return;
default:
printBanner(System.out);
return;
}
}

private void printBanner(PrintStream out) {
for (String line : BANNER) {
out.println(line);
}
out.println(format("Pinpoint Version", Version.VERSION));

for (String key: keysToPrint) {
String value = properties.getProperty(key);
if ( value != null ) {
out.println(format(key, value));
}
}

out.println();
}

private void printBanner(BootLogger logger) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(outputStream);
printBanner(ps);
logger.info(outputStream.toString());
}
}
56 changes: 55 additions & 1 deletion collector/src/main/resources/pinpoint-collector-root.properties
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,58 @@ collector.map-link.max.enable=true
flink.cluster.enable=false
flink.cluster.zookeeper.address=${pinpoint.zookeeper.address}
flink.cluster.zookeeper.znode_root=/pinpoint-cluster
flink.cluster.zookeeper.sessiontimeout=3000
flink.cluster.zookeeper.sessiontimeout=3000

###########################################################
# BANNER #
###########################################################
# Pinpoint Banner Settings
# Pinpoint banner mode : OFF, CONSOLE, LOG
pinpoint.banner.mode=console
pinpoint.banner.configs=spring.active.profile,\
pinpoint.zookeeper.address,\
collector.receiver.base.ip,\
collector.receiver.base.port,\
collector.receiver.stat.udp,\
collector.receiver.stat.udp.ip,\
collector.receiver.stat.udp.port,\
collector.receiver.stat.tcp,\
collector.receiver.stat.tcp.ip,\
collector.receiver.stat.tcp.port,\
collector.receiver.span.udp,\
collector.receiver.span.udp.ip,\
collector.receiver.span.udp.port,\
collector.receiver.span.tcp,\
collector.receiver.span.tcp.ip,\
collector.receiver.span.tcp.port,\
cluster.enable,\
cluster.zookeeper.address,\
cluster.zookeeper.znode_root,\
cluster.listen.ip,\
cluster.listen.port,\
flink.cluster.enable,\
flink.cluster.zookeeper.address,\
flink.cluster.zookeeper.znode_root,\
collector.receiver.grpc.agent.enable,\
collector.receiver.grpc.agent.bindaddress.ip,\
collector.receiver.grpc.agent.bindaddress.port,\
collector.receiver.grpc.stat.enable,\
collector.receiver.grpc.stat.bindaddress.ip,\
collector.receiver.grpc.stat.bindaddress.port,\
collector.receiver.grpc.span.enable,\
collector.receiver.grpc.span.bindaddress.ip,\
collector.receiver.grpc.span.bindaddress.port,\
collector.receiver.grpc.ssl.enable,\
collector.receiver.grpc.agent.ssl.enable,\
collector.receiver.grpc.agent.ssl.bindaddress.ip,\
collector.receiver.grpc.agent.ssl.bindaddress.port,\
collector.receiver.grpc.stat.ssl.enable,\
collector.receiver.grpc.stat.ssl.bindaddress.ip,\
collector.receiver.grpc.stat.ssl.bindaddress.port,\
collector.receiver.grpc.span.ssl.enable,\
collector.receiver.grpc.span.ssl.bindaddress.ip,\
collector.receiver.grpc.span.ssl.bindaddress.port,\
hbase.client.host,\
hbase.client.port,\
hbase.zookeeper.znode.parent,\
hbase.namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.navercorp.pinpoint.common.server.banner;

import com.navercorp.pinpoint.common.Version;
import com.navercorp.pinpoint.common.banner.PinpointBanner;
import com.navercorp.pinpoint.common.server.util.ServerBootLogger;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;

public class PinpointSpringBanner extends PinpointBanner implements ApplicationListener<ApplicationStartedEvent> {
private ServerBootLogger logger = ServerBootLogger.getLogger(PinpointSpringBanner.class);

private Environment environment;

public PinpointSpringBanner() {
this.pinpointBannerMode = Mode.CONSOLE;
}

@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
environment = event.getApplicationContext().getEnvironment();

String bannerMode = environment.getProperty("pinpoint.banner.mode");
String bannerConfigs = environment.getProperty("pinpoint.banner.configs");

Mode mode;
if (bannerMode == null) {
mode = Mode.CONSOLE;
} else {
mode = PinpointBanner.Mode.valueOf(bannerMode.toUpperCase());
}
this.setPinpointBannerMode(mode);

if (bannerConfigs == null) {
this.keysToPrint = new ArrayList<>();
} else {
this.keysToPrint = Arrays.asList(bannerConfigs.split(","));
}

printBanner();
}

@Override
public void printBanner() {
if ( environment == null ) {
logger.info("Environment not ready for banner.");
return;
}

switch (this.pinpointBannerMode) {
case OFF:
return;
case LOG:
printBanner(logger);
return;
default:
printBanner(System.out);
return;
}
}

private void printBanner(ServerBootLogger logger) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(outputStream);
printBanner(ps);
logger.info(outputStream.toString());
}

private void printBanner(PrintStream out) {
for (String line : BANNER) {
out.println(line);
}
out.println(format("Pinpoint Version", Version.VERSION));

for (String key: this.keysToPrint) {
String value = environment.getProperty(key);
if ( value != null ) {
out.println(format(key, value));
}
}

out.println();
}

@Override
public void setPinpointBannerMode(Mode mode) {
this.pinpointBannerMode = mode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.common.server.starter;

import com.navercorp.pinpoint.common.server.banner.PinpointSpringBanner;
import com.navercorp.pinpoint.common.server.env.EnvironmentLoggingListener;
import com.navercorp.pinpoint.common.server.env.ExternalEnvironmentListener;
import com.navercorp.pinpoint.common.server.env.ProfileResolveListener;
Expand Down Expand Up @@ -46,6 +47,7 @@ public void start(String[] args) {
builder.listeners(new ProfileResolveListener());
builder.listeners(new EnvironmentLoggingListener());
builder.listeners(new ExternalEnvironmentListener(externalPropertySourceName, externalConfigurationKey));
builder.listeners(new PinpointSpringBanner());

SpringApplication springApplication = builder.build();
springApplication.run(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.navercorp.pinpoint.common.banner;

import java.util.List;

public abstract class PinpointBanner {
protected Mode pinpointBannerMode;
protected List<String> keysToPrint;

protected final String BANNER[] = {
"",
" 88888888ba 88 888b 88 88888888ba ,ad8888ba, 88 888b 88 888888888888",
" 88 ,8P 88 88 `8b 88 88 ,8P d8' `8b 88 88 `8b 88 88",
" 88aaaaaa8P' 88 88 `8b 88 88aaaaaa8P' 88 da 88 88 88 `8b 88 88",
" 88 88 88 `8b 88 88 Y8, ,8P 88 88 `8b 88 88",
" 88 88 88 `888 88 `\"Y8888Y\"' 88 88 `888 88",
"",
" https://github.com/pinpoint-apm/pinpoint",
"",
};

public abstract void printBanner();
public abstract void setPinpointBannerMode(Mode mode);

protected String format(String key, String value) {
return String.format(" :: %55s :: %35s", key, value);
}

public static enum Mode {
OFF,
CONSOLE,
LOG;
}
}
22 changes: 21 additions & 1 deletion web/src/main/resources/pinpoint-web-root.properties
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,24 @@ web.installation.downloadUrl=
web.applicationList.cacheTime=30

# webhook config
webhook.enable=false
webhook.enable=false

###########################################################
# BANNER #
###########################################################
# Pinpoint Banner Settings
# Pinpoint banner mode : OFF, CONSOLE, LOG
pinpoint.banner.mode=console
pinpoint.banner.configs=spring.active.profile,\
pinpoint.zookeeper.address,\
jdbc.url,\
meta.jdbc.url,\
cluster.enable,\
cluster.zookeeper.address,\
cluster.zookeeper.znode_root,\
cluster.connect.address,\
hbase.client.host,\
hbase.client.port,\
hbase.zookeeper.znode.parent,\
hbase.namespace,\
websocket.allowedOrigins

0 comments on commit 5c04571

Please sign in to comment.