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

Lps 197325 glowroot plugin trace level configuration #5681

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
LPS-197325 glowroot proxy and freemarker plugin
  • Loading branch information
fabian-bouche-liferay authored and brianchandotcom committed Sep 29, 2023
commit 3e8c35fc82580a626343d584f7b966e67a01da2b
1 change: 1 addition & 0 deletions modules/apps/glowroot/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apply plugin: "com.liferay.app.defaults.plugin"
3 changes: 3 additions & 0 deletions modules/apps/glowroot/glowroot-freemarker-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle/
build/
target/
2 changes: 2 additions & 0 deletions modules/apps/glowroot/glowroot-freemarker-plugin/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bundle-SymbolicName: com.liferay.apm.glowroot.plugins.freemarker
Bundle-Version: 1.0.0
4 changes: 4 additions & 0 deletions modules/apps/glowroot/glowroot-freemarker-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compileInclude "org.glowroot:glowroot-agent-plugin-api:0.13.6"
compileInclude "javax.servlet:javax.servlet-api:3.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
package com.liferay.apm.glowroot.plugins.freemarker;

import java.util.Map;

import org.glowroot.agent.plugin.api.Agent;
import org.glowroot.agent.plugin.api.MessageSupplier;
import org.glowroot.agent.plugin.api.OptionalThreadContext;
import org.glowroot.agent.plugin.api.TimerName;
import org.glowroot.agent.plugin.api.TraceEntry;
import org.glowroot.agent.plugin.api.weaving.BindParameter;
import org.glowroot.agent.plugin.api.weaving.BindParameterArray;
import org.glowroot.agent.plugin.api.weaving.BindThrowable;
import org.glowroot.agent.plugin.api.weaving.BindTraveler;
import org.glowroot.agent.plugin.api.weaving.OnBefore;
import org.glowroot.agent.plugin.api.weaving.OnReturn;
import org.glowroot.agent.plugin.api.weaving.OnThrow;
import org.glowroot.agent.plugin.api.weaving.Pointcut;
import org.glowroot.agent.plugin.api.weaving.Shim;

public class TemplatesAspect {

@Shim("com.liferay.portal.kernel.theme.ThemeDisplay")
public interface ThemeDisplayShim {
long getCompanyId();
long getCompanyGroupId();
long getScopeGroupId();
long getSiteGroupId();
}

@Shim("com.liferay.journal.model.JournalArticle")
public interface JournalArticleShim {
}

@Shim("com.liferay.dynamic.data.mapping.model.DDMTemplate")
public interface DDMTemplateShim {
String getScript();
long getTemplateId();
}

@Shim("com.liferay.fragment.model.FragmentEntryLink")
public interface FragmentEntryLinkShim {
long getCompanyId();
long getGroupId();
long getFragmentEntryLinkId();
}

@Shim("com.liferay.fragment.processor.FragmentEntryProcessorContext")
public interface FragmentEntryProcessorContextShim {
}

@Pointcut(className = "com.liferay.portal.templateparser.Transformer",
methodName = "transform",
methodParameterTypes = {
"com.liferay.portal.kernel.theme.ThemeDisplay",
"java.util.Map",
"java.lang.String",
"java.lang.String",
"com.liferay.portal.kernel.io.unsync.UnsyncStringWriter",
"javax.servlet.http.HttpServletRequest",
"javax.servlet.http.HttpServletResponse"},
timerName = "Template Parser Transform")
public static class TransformAdvice {

private static final TimerName timer = Agent.getTimerName(TransformAdvice.class);

@OnBefore
public static TraceEntry onBefore(OptionalThreadContext context,
@BindParameter ThemeDisplayShim themeDisplay,
@BindParameter Map<String, Object> contextObjects,
@BindParameter String script,
@BindParameter String type) {

long companyId = themeDisplay.getCompanyId();
long siteGroupId = themeDisplay.getSiteGroupId();

String templateId = String.valueOf(contextObjects.get("template_id"));

StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Template Parser Transform [templateId: ");
messageBuilder.append(templateId);
messageBuilder.append(", companyId: ");
messageBuilder.append(companyId);
messageBuilder.append(", siteGroupId: ");
messageBuilder.append(siteGroupId);
messageBuilder.append("]");

if(TemplatesPluginProperties.captureAsOuterTransaction()) {
context.setTransactionOuter();

if(TemplatesPluginProperties.captureTemplateScriptInTransaction()) {
context.addTransactionAttribute("Template type", type);
context.addTransactionAttribute("Template script", script);
}

return context.startTransaction("Templates", messageBuilder.toString(), MessageSupplier.create(messageBuilder.toString()), timer);

} else {
return context.startTraceEntry(MessageSupplier.create(messageBuilder.toString()), timer);
}
}

@OnReturn
public static void onReturn(@BindTraveler TraceEntry traceEntry) {
traceEntry.end();
}

@OnThrow
public static void onThrow(@BindThrowable Throwable throwable,
@BindTraveler TraceEntry traceEntry) {
traceEntry.endWithError(throwable);
}
}

@Pointcut(className = "com.liferay.journal.internal.transformer.JournalTransformer",
methodName = "transform",
methodParameterTypes = {
"com.liferay.journal.model.JournalArticle",
"com.liferay.dynamic.data.mapping.model.DDMTemplate",
"com.liferay.journal.util.JournalHelper",
"java.lang.String",
"com.liferay.layout.display.page.LayoutDisplayPageProviderRegistry",
"java.util.List",
"com.liferay.portal.kernel.portlet.PortletRequestModel",
"boolean",
"java.lang.String",
"com.liferay.portal.kernel.theme.ThemeDisplay",
"java.lang.String"},
timerName = "Journal Template Parser Transform")
public static class JournalTransformAdvice {

private static final TimerName timer = Agent.getTimerName(JournalTransformAdvice.class);

@OnBefore
public static TraceEntry onBefore(OptionalThreadContext context,
@BindParameterArray Object[] parameters) {

ThemeDisplayShim themeDisplay = (ThemeDisplayShim) parameters[9];
DDMTemplateShim ddmTemplate = (DDMTemplateShim) parameters[1];

long companyId = themeDisplay.getCompanyId();
long siteGroupId = themeDisplay.getSiteGroupId();



StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Journal Template Parser Transform [templateId: ");
messageBuilder.append(ddmTemplate.getTemplateId());
messageBuilder.append(", companyId: ");
messageBuilder.append(companyId);
messageBuilder.append(", siteGroupId: ");
messageBuilder.append(siteGroupId);
messageBuilder.append("]");

if(TemplatesPluginProperties.captureAsOuterTransaction()) {
context.setTransactionOuter();

if(TemplatesPluginProperties.captureTemplateScriptInTransaction()) {
context.addTransactionAttribute("Template script", ddmTemplate.getScript());
}

return context.startTransaction("Templates", messageBuilder.toString(), MessageSupplier.create(messageBuilder.toString()), timer);

} else {
return context.startTraceEntry(MessageSupplier.create(messageBuilder.toString()), timer);
}
}

@OnReturn
public static void onReturn(@BindTraveler TraceEntry traceEntry) {
traceEntry.end();
}

@OnThrow
public static void onThrow(@BindThrowable Throwable throwable,
@BindTraveler TraceEntry traceEntry) {
traceEntry.endWithError(throwable);
}
}

@Pointcut(className = "com.liferay.fragment.entry.processor.freemarker.FreeMarkerFragmentEntryProcessor",
methodName = "processFragmentEntryLinkHTML",
methodParameterTypes = {
"com.liferay.fragment.model.FragmentEntryLink",
"java.lang.String",
"com.liferay.fragment.processor.FragmentEntryProcessorContext"},
timerName = "Fragment Entry Link Template Parser Transform")
public static class FragmentEntryLinkTransformAdvice {

private static final TimerName timer = Agent.getTimerName(JournalTransformAdvice.class);

@OnBefore
public static TraceEntry onBefore(OptionalThreadContext context,
@BindParameter FragmentEntryLinkShim fragmentEntryLink, @BindParameter String html,
@BindParameter FragmentEntryProcessorContextShim fragmentEntryProcessorContext) {

long companyId = fragmentEntryLink.getCompanyId();
long siteGroupId = fragmentEntryLink.getGroupId();



StringBuilder messageBuilder = new StringBuilder();
messageBuilder.append("Fragment Entry Link Template Parser Transform [fragmentEntryLinkId: ");
messageBuilder.append(fragmentEntryLink.getFragmentEntryLinkId());
messageBuilder.append(", companyId: ");
messageBuilder.append(companyId);
messageBuilder.append(", siteGroupId: ");
messageBuilder.append(siteGroupId);
messageBuilder.append("]");

if(TemplatesPluginProperties.captureAsOuterTransaction()) {
context.setTransactionOuter();

if(TemplatesPluginProperties.captureTemplateScriptInTransaction()) {
context.addTransactionAttribute("Fragment Entry Link html", html);
}

return context.startTransaction("Templates", messageBuilder.toString(), MessageSupplier.create(messageBuilder.toString()), timer);

} else {
return context.startTraceEntry(MessageSupplier.create(messageBuilder.toString()), timer);
}
}

@OnReturn
public static void onReturn(@BindTraveler TraceEntry traceEntry) {
traceEntry.end();
}

@OnThrow
public static void onThrow(@BindThrowable Throwable throwable,
@BindTraveler TraceEntry traceEntry) {
traceEntry.endWithError(throwable);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.liferay.apm.glowroot.plugins.freemarker;

import org.glowroot.agent.plugin.api.Agent;
import org.glowroot.agent.plugin.api.config.ConfigListener;
import org.glowroot.agent.plugin.api.config.ConfigService;

public class TemplatesPluginProperties {

private static final ConfigService configService = Agent.getConfigService("liferay-templates-plugin");

private static boolean captureAsOuterTransaction;
private static boolean captureTemplateScriptInTransaction;

static {
configService.registerConfigListener(new TemplatesPluginConfigListener());
}

public static boolean captureAsOuterTransaction() {
return captureAsOuterTransaction;
}

public static boolean captureTemplateScriptInTransaction() {
return captureTemplateScriptInTransaction;
}

private static class TemplatesPluginConfigListener implements ConfigListener {

@Override
public void onChange() {
recalculateProperties();
}

private static void recalculateProperties() {
captureAsOuterTransaction =
configService.getBooleanProperty("captureAsOuterTransaction").value();

captureTemplateScriptInTransaction =
configService.getBooleanProperty("captureTemplateScriptInTransaction").value();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Liferay Templates Plugin",
"id": "liferay-templates-plugin",
"properties": [
{
"name": "captureAsOuterTransaction",
"type": "boolean",
"label": "Capture Template transformations as an outer transaction",
"checkboxLabel": "Capture Template transformations as an outer transaction"
},
{
"name": "captureTemplateScriptInTransaction",
"type": "boolean",
"label": "Capture Template script when captured as an outer transaction",
"checkboxLabel": "Capture Template script when captured as an outer transaction"
}
],
"aspects": [
"com.liferay.apm.glowroot.plugins.freemarker.TemplatesAspect"
],
"collocate": true
}
3 changes: 3 additions & 0 deletions modules/apps/glowroot/glowroot-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle/
build/
target/
8 changes: 8 additions & 0 deletions modules/apps/glowroot/glowroot-proxy/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bundle-Name: Liferay APM Glowroot Proxy
Bundle-SymbolicName: com.liferay.apm.glowroot.proxy
Bundle-Version: 1.0.0

Import-Package:\
!org.apache.avalon.framework.logger,\
!org.apache.log,\
*
7 changes: 7 additions & 0 deletions modules/apps/glowroot/glowroot-proxy/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies {
compileInclude group: "org.mitre.dsmiley.httpproxy", name: "smiley-http-proxy-servlet", version: "1.12.1"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.impl", version: "default"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "default"
compileOnly group: "org.osgi", name: "org.osgi.annotation.versioning", version: "1.1.0"
compileOnly group: "org.osgi", name: "osgi.core", version: "6.0.0"
}
Loading