Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions agent-module/agent/src/main/resources/pinpoint-root.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
# - -Dpinpoint.config=$MY_CONFIG_PATH/pinpoint.config
pinpoint.profiler.profiles.active=release

# Profile aliases
# If the active profile does not match any available profiles, it is resolved as an alias.
# Multiple aliases can be separated by commas.
# e.g. pinpoint.profiler.profiles.aliases.<profile>=<alias1>,<alias2>
pinpoint.profiler.profiles.aliases.release=
pinpoint.profiler.profiles.aliases.local=

# Pinpoint Disable (default : false)
# Using VM option or environmental variable will disable Pinpoint agent more strictly
pinpoint.disable=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.navercorp.pinpoint.bootstrap.BootLogger;
import com.navercorp.pinpoint.bootstrap.util.ProfileConstants;
import com.navercorp.pinpoint.bootstrap.util.StringUtils;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -116,12 +117,7 @@


private String getActiveProfile(Properties defaultProperties) {
// env option support??
// String envProfile = System.getenv(ACTIVE_PROFILE_KEY);
String profile = javaSystemProperty.getProperty(ProfileConstants.ACTIVE_PROFILE_KEY);
if (profile == null) {
profile = defaultProperties.getProperty(ProfileConstants.ACTIVE_PROFILE_KEY);
}
String profile = getProfileProperties(defaultProperties, ProfileConstants.ACTIVE_PROFILE_KEY);

Check warning on line 120 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L120 was not covered by tests
Copy link

Copilot AI May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty system or default property value will result in profile being an empty string (not null), which bypasses the null check and leads to an unhelpful exception. Consider using StringUtils.isEmpty(profile) to treat both null and empty as unset.

Copilot uses AI. Check for mistakes.
if (profile == null) {
throw new RuntimeException("Failed to detect pinpoint profile. Please add -D" +
ProfileConstants.ACTIVE_PROFILE_KEY +
Expand All @@ -134,11 +130,46 @@
return supportedProfile.toString();
}
}

// handle alias
for (Path supportedProfile : supportedProfiles) {
String supportedProfileName = supportedProfile.toString();
String aliasesStr = getProfileProperties(defaultProperties, ProfileConstants.PROFILE_ALIAS_KEY_PREFIX + supportedProfileName);

Check warning on line 137 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L136 - L137 were not covered by tests
if (containsAlias(aliasesStr, profile)) {
logger.info(String.format("resolved profile alias '%s' to supported profile '%s'", profile, supportedProfileName));
return supportedProfileName;

Check warning on line 140 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L139 - L140 were not covered by tests
}
}

Check warning on line 142 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L142 was not covered by tests
throw new IllegalStateException("unsupported profile:" + profile);
}

private String getProfileProperties(Properties defaultProperties, String key) {
// env option support??
// String envProfile = System.getenv(ACTIVE_PROFILE_KEY);
String value = javaSystemProperty.getProperty(key);

Check warning on line 149 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L149 was not covered by tests
if (value == null) {
value = defaultProperties.getProperty(key);

Check warning on line 151 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L151 was not covered by tests
}
return value;

Check warning on line 153 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L153 was not covered by tests
}


private void loadProperties(Properties dstProperties, Properties property) {
Map<Object, Object> copy = PropertyLoaderUtils.filterAllowedPrefix(property);
dstProperties.putAll(copy);
}

private boolean containsAlias(String aliasesStr, String profile) {
if (StringUtils.isEmpty(aliasesStr)) {
return false;

Check warning on line 164 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L164 was not covered by tests
}

String[] aliases = aliasesStr.split(",");

Check warning on line 167 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L167 was not covered by tests
for (String alias : aliases) {
if (profile.equalsIgnoreCase(alias.trim())) {
return true;

Check warning on line 170 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L170 was not covered by tests
}
}
return false;

Check warning on line 173 in agent-module/bootstraps/bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/config/ProfilePropertyLoader.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L173 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public enum CONFIG_LOAD_MODE {

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

public static final String PROFILE_ALIAS_KEY_PREFIX = "pinpoint.profiler.profiles.aliases.";

// 1. default config
public static final String CONFIG_FILE_NAME = "pinpoint-root.config";
// 2. profile config
Expand Down