Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#648: switch to the regular toString for logging to prevent excessive memory usage #649

Merged
merged 1 commit into from
Nov 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -99,5 +100,15 @@ public List<AuthorizableConfigBean> getVirtualGroups() {
public void setVirtualGroups(List<AuthorizableConfigBean> virtualGroups) {
this.virtualGroups = virtualGroups;
}


@Override
public String toString() {
return new ToStringBuilder(this)
.append("globalConfiguration", globalConfiguration)
.append("authorizablesConfig", authorizablesConfig)
.append("aceBeansConfig", aceBeansConfig)
.append("obsoleteAuthorizables", obsoleteAuthorizables)
.append("virtualGroups", virtualGroups)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.apache.commons.lang3.time.StopWatch;
import org.osgi.service.cm.ConfigurationPlugin;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand Down Expand Up @@ -135,7 +134,7 @@ public AcConfiguration getMergedConfigurations(
yamlRootList = yamlMacroProcessor.processMacros(yamlRootList, globalVariables, installLog, session);
// set merged config per file to ensure it is there in case of validation errors (for success, the actual merged config is set
// after this loop)
installLog.setMergedAndProcessedConfig("# File " + sourceFile + "\n" + yamlParser.dump(yamlRootList));
installLog.setMergedAndProcessedConfig("# File " + sourceFile + "\n" + yamlRootList);

final Set<String> sectionIdentifiers = new LinkedHashSet<String>();

Expand Down Expand Up @@ -225,7 +224,7 @@ public AcConfiguration getMergedConfigurations(
}

installLog.setMergedAndProcessedConfig(
"# Merged configuration of " + configFileContentByFilename.size() + " files \n" + yamlParser.dump(acConfiguration));
"# Merged configuration of " + configFileContentByFilename.size() + " files \n" + acConfiguration);

installLog.addMessage(LOG, "Loaded configuration in " + msHumanReadable(System.currentTimeMillis() - wholeConfigStart));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void persistHistory(PersistableInstallationLogger installLog) {

String mergedAndProcessedConfig = installLog.getMergedAndProcessedConfig();
if (StringUtils.isNotBlank(mergedAndProcessedConfig)) {
JcrUtils.putFile(historyNode, "mergedConfig.yaml", "text/yaml",
JcrUtils.putFile(historyNode, "mergedConfig.txt", "text/plain",
Copy link
Member

Choose a reason for hiding this comment

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

so this is a shame to have only a "toString" representation saved - isn't it possible to somehow generate the yaml without too much memory impact? (IIRC today snippets of this file can be used to test things and do some "round-tripping")

Copy link
Member

Choose a reason for hiding this comment

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

suggestions welcome, SnakeYAML itself has huge overhead!

Copy link
Member

Choose a reason for hiding this comment

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

I suppose we could fairly easily write a toString method, that creates valid yaml (instead of just using ToStringBuilder) - but we can also do that separately, not the most important to have immediately

Copy link
Member Author

Choose a reason for hiding this comment

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

@ghenzler I've created #651 to improve toString. Hope it's fine.

new ByteArrayInputStream(mergedAndProcessedConfig.getBytes()));
}

Expand Down