Skip to content

Commit 00b095c

Browse files
committed
[#12502] Add alias support for agent profiles
1 parent 8583890 commit 00b095c

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

agent-module/agent/src/main/resources/pinpoint-root.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# - -Dpinpoint.config=$MY_CONFIG_PATH/pinpoint.config
1313
pinpoint.profiler.profiles.active=release
1414

15+
# Profile aliases
16+
# If the active profile does not match any available profiles, it is resolved as an alias.
17+
# Multiple aliases can be separated by commas.
18+
# e.g. pinpoint.profiler.profiles.aliases.<profile>=<alias1>,<alias2>
19+
pinpoint.profiler.profiles.aliases.release=
20+
pinpoint.profiler.profiles.aliases.local=
21+
1522
# Pinpoint Disable (default : false)
1623
# Using VM option or environmental variable will disable Pinpoint agent more strictly
1724
pinpoint.disable=false

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.navercorp.pinpoint.bootstrap.BootLogger;
2020
import com.navercorp.pinpoint.bootstrap.util.ProfileConstants;
21+
import com.navercorp.pinpoint.bootstrap.util.StringUtils;
2122

2223
import java.nio.file.Path;
2324
import java.nio.file.Paths;
@@ -116,12 +117,7 @@ private void saveAgentRootPath(Path agentRootPath, Properties properties) {
116117

117118

118119
private String getActiveProfile(Properties defaultProperties) {
119-
// env option support??
120-
// String envProfile = System.getenv(ACTIVE_PROFILE_KEY);
121-
String profile = javaSystemProperty.getProperty(ProfileConstants.ACTIVE_PROFILE_KEY);
122-
if (profile == null) {
123-
profile = defaultProperties.getProperty(ProfileConstants.ACTIVE_PROFILE_KEY);
124-
}
120+
String profile = getProfileProperties(defaultProperties, ProfileConstants.ACTIVE_PROFILE_KEY);
125121
if (profile == null) {
126122
throw new RuntimeException("Failed to detect pinpoint profile. Please add -D" +
127123
ProfileConstants.ACTIVE_PROFILE_KEY +
@@ -134,11 +130,46 @@ private String getActiveProfile(Properties defaultProperties) {
134130
return supportedProfile.toString();
135131
}
136132
}
133+
134+
// handle alias
135+
for (Path supportedProfile : supportedProfiles) {
136+
String supportedProfileName = supportedProfile.toString();
137+
String aliasesStr = getProfileProperties(defaultProperties, ProfileConstants.PROFILE_ALIAS_KEY_PREFIX + supportedProfileName);
138+
if (containsAlias(aliasesStr, profile)) {
139+
logger.info(String.format("resolved profile alias '%s' to supported profile '%s'", profile, supportedProfileName));
140+
return supportedProfileName;
141+
}
142+
}
137143
throw new IllegalStateException("unsupported profile:" + profile);
138144
}
139145

146+
private String getProfileProperties(Properties defaultProperties, String key) {
147+
// env option support??
148+
// String envProfile = System.getenv(ACTIVE_PROFILE_KEY);
149+
String value = javaSystemProperty.getProperty(key);
150+
if (value == null) {
151+
value = defaultProperties.getProperty(key);
152+
}
153+
return value;
154+
}
155+
156+
140157
private void loadProperties(Properties dstProperties, Properties property) {
141158
Map<Object, Object> copy = PropertyLoaderUtils.filterAllowedPrefix(property);
142159
dstProperties.putAll(copy);
143160
}
161+
162+
private boolean containsAlias(String aliasesStr, String profile) {
163+
if (StringUtils.isEmpty(aliasesStr)) {
164+
return false;
165+
}
166+
167+
String[] aliases = aliasesStr.split(",");
168+
for (String alias : aliases) {
169+
if (profile.equalsIgnoreCase(alias.trim())) {
170+
return true;
171+
}
172+
}
173+
return false;
174+
}
144175
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public enum CONFIG_LOAD_MODE {
1212

1313
public static final String ACTIVE_PROFILE_KEY = "pinpoint.profiler.profiles.active";
1414

15+
public static final String PROFILE_ALIAS_KEY_PREFIX = "pinpoint.profiler.profiles.aliases.";
16+
1517
// 1. default config
1618
public static final String CONFIG_FILE_NAME = "pinpoint-root.config";
1719
// 2. profile config

0 commit comments

Comments
 (0)