Skip to content

Commit

Permalink
Xceptance#390: Issues with the new timer recorder plugin for Chrome (X…
Browse files Browse the repository at this point in the history
…ceptance#440)

* Revert "Revert "GH Xceptance#141: Timerrecorder extension: migrate to manifest v3 (Xceptance#244)""

This reverts commit 7549bfa.

* small bug fixes and improvements

* temporarily use zip to pack the extension until the bug in Chrome 119 is fixed

* Chrome Timer Recorder
* upped minimum chrome version to 116 (see https://developer.chrome.com/docs/extensions/mv3/service_workers/service-worker-lifecycle/#chrome-116)
* installed a periodic task that sends a dummy message to XLT to keep the service worker alive
* made the usage of the session storage configurable (off by default)
* added a helper function to calculate the size of the request line
* minor optimizations
* added some useful logger functions

XLT
* made the usage of the session storage in the chrome timer recorder configurable (off by default)
* handle new keep-alive messages by ignoring them
* adjusted logging when receiving timer data

* feedback from reviewer

* feedback from reviewer

Co-authored-by: h-arlt <[email protected]>

* Revert "temporarily use zip to pack the extension until the bug in Chrome 119 is fixed"

This reverts commit 53d03e5.

---------

Co-authored-by: h-arlt <[email protected]>
  • Loading branch information
2 people authored and DK committed Apr 18, 2024
1 parent ce5d2df commit 727413d
Show file tree
Hide file tree
Showing 4 changed files with 475 additions and 273 deletions.
18 changes: 15 additions & 3 deletions src/main/java/com/xceptance/xlt/api/webdriver/XltChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ public class XltChromeDriver extends ChromeDriver
*/
private static final boolean RECORD_INCOMPLETE_ENABLED;

/**
* The (hidden) XLT property to enable the use of the session storage in the Chrome timer recorder extension.
*/
private static final String PROPERTY_USE_SESSION_STORAGE = PROPERTY_DOMAIN + "useSessionStorage";

/**
* Whether the Chrome timer recorder extension should use the session storage. Defaults to false.
*/
private static final boolean USE_SESSION_STORAGE;

/**
* The base name of the extension file.
*/
Expand Down Expand Up @@ -177,6 +187,7 @@ public class XltChromeDriver extends ChromeDriver

HEADLESS_ENABLED = props.getProperty(PROPERTY_HEADLESS, false);
RECORD_INCOMPLETE_ENABLED = props.getProperty(PROPERTY_RECORD_INCOMPLETE, false);
USE_SESSION_STORAGE = props.getProperty(PROPERTY_USE_SESSION_STORAGE, false);
IGNORE_MISSING_DATA = props.getProperty(PROPERTY_IGNORE_MISSING_DATA, true);

// unpack the extension file to the temp directory
Expand Down Expand Up @@ -300,8 +311,9 @@ private void init()
*/
private void initConnect(final int retryCount)
{
final String url = "data:,xltParameters?xltPort=" + connectionHandler.getPort() + "&clientID=" + connectionHandler.getID() +
"&recordIncompleted=" + RECORD_INCOMPLETE_ENABLED;
final String url = String.format("data:,xltParameters?xltPort=%d&clientID=%s&recordIncompleted=%b&useSessionStorage=%b",
connectionHandler.getPort(), connectionHandler.getID(), RECORD_INCOMPLETE_ENABLED,
USE_SESSION_STORAGE);

long timeout = CONNECT_RETRY_BASE_TIMEOUT;

Expand Down Expand Up @@ -363,7 +375,7 @@ private static ChromeDriverService modifyService(ChromeDriverService service, fi

// read the environment settings
final Map<String, String> environment = ReflectionUtils.readField(ChromeDriverService.class, service,
FIELD_NAME_ENVIRONMENT);
FIELD_NAME_ENVIRONMENT);

// create the new environment settings including the DISPLAY variable
final ImmutableMap.Builder<String, String> mapBuilder = new ImmutableMap.Builder<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,20 @@ public void onConnect(ClientPerformanceExtensionConnector connector, ClientPerfo
@Override
public void onMessage(ClientPerformanceExtensionConnection connection, JSONObject data, Responder responder)
{
if (LOG.isTraceEnabled())
{
LOG.trace("Message received: " + data);
}
final String action = data.optString("action");

LOG.debug("Message received for action: {}", action);

try
{
if ("DUMP_PERFORMANCE_DATA".equals(data.optString("action")))
if ("DUMP_PERFORMANCE_DATA".equals(action))
{
dumpPerformanceData(data.optString("performanceData"));
}
else if ("KEEP_ALIVE_PING".equals(action))
{
// ignore for now
}
}
catch (Throwable t)
{
Expand Down Expand Up @@ -213,12 +216,21 @@ private void dumpPerformanceData(String rawData)
{
final List<ClientPerformanceData> performanceData = PerformanceDataTransformator.getTransformedPerformanceDataList(rawData);

ClientPerformanceMetrics.updatePerformanceData(session, performanceData);

if (LOG.isDebugEnabled())
{
LOG.debug("Dumped client-performance metrics: " + rawData);
int requestTimings = 0;
int pageLoadTimings = 0;

for (final ClientPerformanceData clientPerformanceData : performanceData)
{
requestTimings += clientPerformanceData.getRequestList().size();
pageLoadTimings += clientPerformanceData.getCustomDataList().size();
}

LOG.debug("Received client-performance metrics (requests: {}, page load timings: {})", requestTimings, pageLoadTimings);
}

ClientPerformanceMetrics.updatePerformanceData(session, performanceData);
}
catch (final Throwable t)
{
Expand All @@ -229,7 +241,7 @@ private void dumpPerformanceData(String rawData)
/**
* Fetch the remaining timing data from the client which were not sent.
*/
public String fetchPerformanceData() throws JSONException, TimeoutException, CommunicationException, InterruptedException
private String fetchPerformanceData() throws JSONException, TimeoutException, CommunicationException, InterruptedException
{
ClientPerformanceExtensionConnection conn = currentConnection;
if (conn == null || !conn.isOpen())
Expand Down
Loading

0 comments on commit 727413d

Please sign in to comment.