Skip to content

Instantly share code, notes, and snippets.

@nancystodd
Forked from iamwill/debugging_cheatsheet.md
Created October 25, 2019 23:59
Show Gist options
  • Save nancystodd/7068a94208b7f8ea87b5424671b2248c to your computer and use it in GitHub Desktop.
Save nancystodd/7068a94208b7f8ea87b5424671b2248c to your computer and use it in GitHub Desktop.
Debugging on the Glide Platform

Debugging tips and tricks

Platform Troubleshooting

Console output too chatty?
Set com.glide.util.Log.developer_filter = true to cut down on non-interactive console log entries such as scheduled workers. (Don't forget to remove it when you're done!)

Utility urls

Note: Fast! These don't need a database.

Page Description
/stats.do Stats and Info for the current node
/xmlstats.do Same as stats.do in xml format
/xmlstats.do?include=cache Cache stats in xml format
/thread_pool_stats.do Thread queue depth and AMB queue
/sn_agent_workspace_stats.do Agent workspace build and component versions
/cancel_my_transaction.do Name says it all
/side_door.do Bypass SSO redirect and go to login.do
/logout.do Immediately log out

Useful Tables

Table Description
sys_db_object All of the physical database tables
sys_dictionary Tables and columns and their attributes
sys_glide_object Field/Element types, extensions, and class mapping

Note: All element defaults come from sys_glide_object.

Debug modules

Administrators can use these navigator modules: System Diagnostics & System Logs. Below are some highlights:

⬇️

Application Module Description
System Diagnostics Session Debug These items display output at the bottom of the page
  Enable All Enable all debug options
  Debug Business Rule Show all business rule evaluations
  Debug Log Show script log messages
  Debug SQL Show SQL queries and execution time
  Debug Security Show ACL evaluations
System Logs   Shortcut to logs
  Transactions All transactions with summaries of SQL, business rule, and response time
  All All syslog entries
  Script Log Statements Script log messages
  Node Log File Browser JVM node output (equivelant to Eclipse console)

Security

Can't edit an ACL?
Elevate your role from the User Menu.

Troubleshooting issues for a specific user?

  • First, enable any debug modules such as Debug SQL and Debug Security.
  • Impersonate the different user from the User Menu.

ACL Types

Type Description
processor Restrict execution of a processor
record Restrict Execute/CRUD operations on Tables and Columns
REST_Endpoint Restrict execution of rest endpoints
ui_page Restrict access to UI pages by name
ux_page Restrict access to paths provided by UX builder

Localization

glide.ui.i18n_test (Note: this is system wide)
Set this property = true to enable prefixes on all translated text.

Plugin: I18N: Internationalization
Activate this plugin to test localization prefixes for just your session! Use Enable I18N Debugging in the navigator.

Translations are stored in the following tables:

Table Debug Prefix Description
sys_choice CHC Choice list options
sys_documentation GMLD Field labels
sys_translated TRF Values for field types: Translated Name & Translated Field
sys_translated_txt TXT Values for field type: Translated Text
sys_ui_message MSG Values for getMessage(key)

Plugin shortcuts ⬇️

Is plugin active?

gs.info(pm.isRegistered("com.glide.i18n")); //true

Activate/Upgrade plugin

pm.registerPlugin("com.glide.i18n"); // Activate a plugin and all nested dependencies

Load a plugin's demo data

pm.loadDemoData("com.glide.service-portal.esm")

Zboot

Find Zboot date & time

var gr = new GlideRecord("sys_db_object");
gr.get("name", "sys_dictionary");
gs.print(gr.getDisplayValue("sys_created_on")); // 2019-06-18 03:10:14

Client Scripting

Useful Tables

Table Description
sys_ui_script UI Scripts. Note: scripts where global=true are included on every ui page.
sys_script_client Table based client scripts (onChange, onLoad, onSubmit)

gs.setProperty('glide.ui.js_includes', false);
While this property is false, JS include bundling and whitespace removal is disabled and every javascript file is downloaded separately and untouched.

ctrl + shift + j ⬇️
Launch the JavascriptExecutor to evaluate some js on the current ui page.

g_form.setValue('short_description', 'Hello World');

Remember! ⬇️
In many parts of our platform we include prototypeJS.

  • $ = getElementById
  • $j is jQuery.

Chrome dev tools (command + option + J)

Important! Target the gsft_main frame
When using the javascript console, make sure you are picking the frame named: gsft_main

breakpoint;
Pause javascript execution and launch the script debugger in your browser. Only works when your browser dev tools are open.

function onSubmit() {
	breakpoint; // Your script execution will pause and automatically launch the debugger.
}
Shortcut Description
$0 Currently selected dom element
$1 Previously selected dom element
console.dir(obj) Prints a JSON representation of an object
console.log(obj) Prints a message or object to the console

Angular scope ⬇️
Some of our applications are using angular. Use this shortcut to view the scope of the current angular directive.

  1. Using the element inspector, select an element.
  2. Type this in the console: angular.element($0).scope()

Break On
What code is changing the dom? Right click on the parent element in the element inspector and select Break On -> Subtree Modifications.

When the dom changes, it will pause the script execution so you can examine the stack trace.

Server Scripting

/sys.scripts.do
Write and execute freeform script on the server. You will also find scripts from all of your active plugin */sys.scripts/ folders.

Useful Tables

Table Description
sys_script Business rules
sys_script_include Server Script includes

GlideSystem APIs

Method Description
gs.info(String msg, [String params]) Log an info message, and print the message to the console. Include optional params in log message.
gs.log(String msg, [String source]) Log a message to the system log with an optional source argument.
gs.breaker(obj) Put a breakpoint in GlideSystem.js_breaker() to stop here whenever you use gs.breaker() in a server script.
gs.getCurrentScopeName() Returns the current application scope name.
gs.addInfoMessage(String msg) Render an info message at the top of a ui page.
gs.setProperty(String key, String value) Set the value of a Glide property.
gs.trace(Bool onOff) Start/Stop sql tracing. See Example.

gs.trace()
Dump SQL statements to the Eclipse console or Transaction log

try {   
  gs.trace(true); // Turn on sql tracing for the following statements
  var gr = new GlideRecord('sc_cat_item');  
  gr.get('bd6fa75a4f334200086eeed18110c79e');  
  if(gr.isValid()) {      
    gs.info(gr.getDisplayValue('name'));
    gs.info(gr.getDisplayValue('short_description'));  
  }
} finally {   
  gs.trace(false); // Turn off sql tracing
}

GlideStopWatch ⬇️

A convenient utility for calculating script run time.

Method Description
start() (Optional) Start the timer. The constructor automatically starts the timer
stop() Stop the timer
getTime() Returns the time in milliseconds
toString() Returns formatted time elapsed
var t = new GlideStopWatch();
var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.query();
gr.getRowCount();
gs.print(t.getTime()); // 2

Jelly

<g:breakpoint />
Use this tag to dump all jelly variables in scope to the transaction log.

gs.setProperty('glide.ui.template.trace', true);
While this property is true, the entire jelly template include structure is dumped to the transaction log.

⬇️

		 ->html_page.xml
		 -->html_page_css.xml
		 <--html_page_css.xml 0:00:00.003
		 -->html_page_javascript.xml
		 --->html_page_javascript_db.xml
		 <---html_page_javascript_db.xml 0:00:00.005
		 <--html_page_javascript.xml 0:00:00.025
		 -->output_messages2.xml
		 <--output_messages2.xml 0:00:00.006
		 -->sys_report_template0.xml

Cache

GlideCacheManager ⬇️

The primary caching api in the platform, a Java static Hashtable. See CacheManager.java.

GlideCacheManager.get(String catalog, String key)
Get an item from the cache.

GlideCacheManager.flush()
Flush the cache. Same as going to /cache.do.

GlideCacheManager.put(String catalog, Object key, Object value)
Put an item in the cache.

Utility urls

Page Description
/cache_inspect.do Browse the Private and Shared caches
/cache.do Flush all the caches (Do not do on customer instance without approval!)

Useful Tables

Table Description
sys_db_cache Database-backed cache records are stored here. (Such as syscache_realform with phase 1 jelly output)
sys_cache_flush Cache flushes are written here to sync cache flushing across nodes.

Java

Overview of a Server Request

  1. GlideServlet.doRequest() <- It all starts here
    1. GlideServletQuickTransaction.process()
      1. doStaticContent()      - Serve static content: .cssdbx,.gif,.jpg,.htm
      2. doCancelRequest()      - Cancel running transaction
      3. DiagnosticTransaction      - /stats.do
    2. GlideServletTransaction.process()
      1. ProcessorRegistry.process()
        1. See Which Processor?
      2. GlideServletUITransaction
        1. RedirectTransaction      - Handles form save
        2. NavigationTransaction      - Displays UI pages
          1. See GlideForm

Which processor?

This is the order that processors are determined:

  1. Finds processor by Parameter (abc_list.do?XML, abc_list.do?EXCEL, abc_list.do?CHART)
  2. Find processor by exact path (PATH.do)
  3. Find processor by extension (/incident.EXTENSION)
  4. Otherwise, default processor is GlideServletUITransaction

GlideForm

The GlideForm class constructs nearly all Jelly based UI pages, including forms & lists!

Default page template: html_page_template.xml

Note: Direct UI pages don't use default page template.

Direct UI pages:

  • $ prefix ($vtb.do)
  • ?sysparm_direct=true
  • UI pages where direct=true

Remote Debugging (Connect to a remote node) ⬇️

Taken from KB0536116 on BuildTools1

  1. Permission: ask customer for permission before conducting remote debugging. Nobody else can use the instance during that time because any action on the instance will potentially trigger your breakpoint.
  2. Ask SRE to change JVM parameter and restart customer instance (Customer support action).
  3. You should have a good understanding of the problem you are trying to solve before conducting remote debugging.
  4. When you request remote debugging, you are asked to specify an app node on the instance. That's the one you'll attach to.
  5. Hop2node on customer's instance
  6. Go to /xmlstats.do
  7. find the jvm.java_opts parameters
  8. Locate the debug port, eg: -Xdebug -Xrunjdwp:transport=dt_socket,address=10001,server=y,suspend=n
  9. Configure your IDE to launch a Remote Java Application using that port, eg 10001

Performance

All instances include a performance dashboard for monitoring: ⬇️

  • Transaction counts & response time
  • Memory usage
  • Errors & logs
  • Slow queries & more

Useful Tables

Table Description
sys_query_pattern Slow queries for later optimization
syslog_transaction User transaction log
syslog_cancellation Logs cancelled transactions
syslog All system logs (Info, Warning, Error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment