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

[scout] improve logs readability by using unique logger context per playwright worker #213218

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

dmlemeshko
Copy link
Member

@dmlemeshko dmlemeshko commented Mar 5, 2025

Summary

Part of #203591

Our current logs are confusing as it is unclear to which worker message is related. E.g.

 proc [playwright]  debg [scout] Creating new local SAML session for role 'admin'
 proc [playwright]  debg [scout] Creating new local SAML session for role 'admin'

it is not clear if the messages are coming from the same worker or 2 different ones.

Before

[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
 debg [scout] applying update to kibana config: {"timepicker:timeDefaults":"{ \"from\": \"2015-09-19T06:31:44.000Z\", \"to\": \"2015-09-23T18:31:44.000Z\"}"}
 debg [scout] Requesting url (redacted): [http://localhost:5620/s/test-space-0/internal/kibana/settings]
 debg [scout] scoutSpace:test-space-0 'uiSettings.setDefaultTime' took 116.66ms
...
 debg [scout] [service] browserAuth
 debg [scout] Creating new local SAML session for role 'viewer'
[chromium] › saved_searches.spec.ts:66:14 › Discover app - saved searches › should customize time range on dashboards @ess @svlSearch @svlOblt
 succ [scout] import success
 debg [scout] scoutSpace:test-space-1 'savedObjects.load' took 1028.17ms
 ...
 debg [scout] [service] browserAuth
 debg [scout] Creating new local SAML session for role 'editor'
 debg [scout] [service] scoutPage:test-space-1
 debg [scout] [service] pageObjects:test-space-1

After:

[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
 debg [scout-worker-1] applying update to kibana config: {"timepicker:timeDefaults":"{ \"from\": \"2015-09-19T06:31:44.000Z\", \"to\": \"2015-09-23T18:31:44.000Z\"}"}
 debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/s/test-space-1/internal/kibana/settings]
 debg [scout-worker-1] test-space-1: 'uiSettings.setDefaultTime' took 131.30ms
...
 debg [scout-worker-1] [service] browserAuth
 debg [scout-worker-1] Creating new local SAML session for role 'viewer'
[chromium] › saved_searches.spec.ts:66:14 › Discover app - saved searches › should customize time range on dashboards @ess @svlSearch @svlOblt
 debg [scout-worker-2] test-space-2: 'savedObjects.load' took 1005.91ms
...
 debg [scout-worker-2] [service] browserAuth
 debg [scout-worker-2] Creating new local SAML session for role 'editor'
 debg [scout-worker-2] [service] scoutPage
 debg [scout-worker-2] [service] pageObjects

Note: single thread run will still log under scout context, let me know if it is preferable to have it similar to parallel run, e.g. [scout-worker] [service] scoutPage

How to verify:

  1. start servers - node scripts/scout.js start-server --stateful
  2. run tests - npx playwright test --config x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts

const corePageObjects = createCorePageObjects(page);
log.serviceLoaded(`pageObjects:${scoutSpace.id}`);
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it is redundant: logger context helps to understand the space we use, there is a 1 to 1 match.

Copy link

@csr csr Mar 5, 2025

Choose a reason for hiding this comment

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

Sounds good about the test space ID being redundant.

A possible improvement for the future (possibly out of scope for this PR): instead of logging just pageObjects (the service name), we could log pageObjects loaded or perhaps pageObjects service loaded to make it clear the service was loaded (successfully). What do you think?

Copy link
Member Author

@dmlemeshko dmlemeshko Mar 5, 2025

Choose a reason for hiding this comment

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

I was thinking about it too, how about having it this way (actually it was in PoC like that):

  /**
   * Used to log when a service/fixture is loaded
   * @param name unique name of the service
   */
  public serviceLoaded(name: string) {
    this.debug(`[${name}] loaded`);
  }

  /**
   * Used to log a message for a service/fixture
   */
  public serviceMessage(name: string, message) {
    this.debug(`[${name}] ${name}`);
  }

output

debg [scout-worker-2] [scoutPage] loaded
debg [scout-worker-2] [pageObjects] loaded
debg [scout-worker-2] [scoutPage] just a random message from service

alternatively

debg [scout-worker-2] [service] 'scoutPage' loaded
debg [scout-worker-2] [service] 'pageObjects' loaded
debg [scout-worker-2]  [service] [pageObjects] just a random message from service

but maybe we don't need that [service] context assuming we know that it is coming from playwright worker?

Copy link
Member Author

Choose a reason for hiding this comment

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

locally run

[chromium] › saved_searches.spec.ts:66:14 › Discover app - saved searches › should customize time range on dashboards @ess @svlSearch @svlOblt
 debg [scout-worker-2] [logger] loaded
 info [scout-worker-2] [config] Reading test servers confiuration from file: /Users/dmle/github/kibana/.scout/servers/local.json
 debg [scout-worker-2] [config] loaded
 debg [scout-worker-2] [kbnClient] loaded
 debg [scout-worker-2] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
 debg [scout-worker-1] [logger] loaded
 info [scout-worker-1] [config] Reading test servers confiuration from file: /Users/dmle/github/kibana/.scout/servers/local.json
 debg [scout-worker-1] [config] loaded
 debg [scout-worker-1] [kbnClient] loaded
 debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/api/spaces/space]

@@ -33,7 +33,7 @@ export const scoutPageParallelFixture = base.extend<
extendedPage.gotoApp = (appName: string, pathOptions?: PathOptions) =>
page.goto(kbnUrl.app(appName, { space: scoutSpace.id, pathOptions }));

log.serviceLoaded(`scoutPage:${scoutSpace.id}`);
Copy link
Member Author

Choose a reason for hiding this comment

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

same here, scout-worker-N logger context is good enough

@@ -19,46 +19,42 @@ export const scoutSpaceParallelFixture = coreWorkerFixtures.extend<
>({
scoutSpace: [
async ({ log, kbnClient }, use, workerInfo) => {
const spaceId = `test-space-${workerInfo.workerIndex}`;
const spaceId = `test-space-${workerInfo.parallelIndex + 1}`;
Copy link
Member Author

@dmlemeshko dmlemeshko Mar 5, 2025

Choose a reason for hiding this comment

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

workerIndex vs parallelIndex:

Playwright created new worker after failure, workerIndex will be increased. Since we delete Kibana space on fixture tear down, we can and should use persistent index - parallelIndex

https://playwright.dev/docs/api/class-workerinfo#worker-info-parallel-index

// will create new copies of saved objects with unique ids
createNewCopies: true,
});
return measurePerformanceAsync(log, `${spaceId}: 'savedObjects.load'`, async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

simplifying message, as we know the worker index now

@dmlemeshko dmlemeshko self-assigned this Mar 5, 2025
@dmlemeshko dmlemeshko added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 backport:version Backport to applied version labels test:scout v9.1.0 v8.19.0 labels Mar 5, 2025
@dmlemeshko dmlemeshko marked this pull request as ready for review March 5, 2025 11:14
@dmlemeshko dmlemeshko requested a review from a team as a code owner March 5, 2025 11:14
>({
log: [
({}, use) => {
use(getLogger('scout'));
Copy link
Member Author

Choose a reason for hiding this comment

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

when tests are run sequentially we will keep using "scout" context

>({
log: [
({}, use, workerInfo) => {
const loggerContext = `scout-worker-${workerInfo.workerIndex + 1}`;
Copy link

Choose a reason for hiding this comment

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

Should we use the parallelIndex instead of the workerIndex here, too? Perhaps (and most likely) it makes no difference, but I wonder what you think.

Copy link
Member Author

Choose a reason for hiding this comment

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

we should ;) thanks for paying attention, I assumed I did it right.

);
return measurePerformanceAsync(log, `${spaceId}: 'uiSettings.setDefaultTime'`, async () => {
const utcFrom = isValidUTCDate(from) ? from : formatTime(from);
const untcTo = isValidUTCDate(to) ? to : formatTime(to);
Copy link

Choose a reason for hiding this comment

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

A typo here, most likely: untcTo should be utcTo.

@csr
Copy link

csr commented Mar 5, 2025

It's nice to now see the worker number next to the log, it seems to be working well with 1, 2, and 3 parallel workers:

✅ 1 Worker
Running 9 tests using 1 worker

[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
debg [scout-worker-1] [service] logger
info [scout-worker-1] [config] Reading test servers configuration from file: /Users/cesaredecal/dev/kibana/.scout/servers/local.json
debg [scout-worker-1] [service] config
debg [scout-worker-1] [service] kbnClient
debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
...
✅ 2 Workers
Running 9 tests using 2 workers

[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
debg [scout-worker-1] [service] logger
[chromium] › saved_searches.spec.ts:66:14 › Discover app - saved searches › should customize time range on dashboards @ess @svlSearch @svlOblt
debg [scout-worker-2] [service] logger
info [scout-worker-1] [config] Reading test servers configuration from file: /Users/cesaredecal/dev/kibana/.scout/servers/local.json
debg [scout-worker-1] [service] config
info [scout-worker-2] [config] Reading test servers configuration from file: /Users/cesaredecal/dev/kibana/.scout/servers/local.json
debg [scout-worker-2] [service] config
debg [scout-worker-1] [service] kbnClient
debg [scout-worker-2] [service] kbnClient
debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
debg [scout-worker-2] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
debg [scout-worker-1] test-space-1: 'spaces.create' took 816.28ms
debg [scout-worker-1] [service] new Kibana space test-space-1 created
...
✅ 3 Workers
Running 9 tests using 3 workers



[chromium] › saved_searches.spec.ts:66:14 › Discover app - saved searches › should customize time range on dashboards @ess @svlSearch @svlOblt
 debg [scout-worker-2] [service] logger
 info [scout-worker-2] [config] Reading test servers confiuration from file: /Users/cesaredecal/dev/kibana/.scout/servers/local.json
 debg [scout-worker-2] [service] config
 debg [scout-worker-2] [service] kbnClient
[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
 debg [scout-worker-1] [service] logger
 info [scout-worker-1] [config] Reading test servers confiuration from file: /Users/cesaredecal/dev/kibana/.scout/servers/local.json
 debg [scout-worker-1] [service] config
 debg [scout-worker-1] [service] kbnClient
[chromium] › saved_searches.spec.ts:66:14 › Discover app - saved searches › should customize time range on dashboards @ess @svlSearch @svlOblt
 debg [scout-worker-2] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
[chromium] › error_handling.spec.ts:30:12 › Discover app - errors › should render invalid scripted field error @ess
 debg [scout-worker-1] Requesting url (redacted): [http://localhost:5620/api/spaces/space]
...

@dmlemeshko dmlemeshko requested a review from csr March 5, 2025 16:11
@@ -130,11 +118,12 @@ export const scoutSpaceParallelFixture = coreWorkerFixtures.extend<
setDefaultTime,
};

log.serviceLoaded(`scoutSpace:${spaceId}`);
log.serviceLoaded(`new Kibana space ${spaceId} created`);
Copy link

@csr csr Mar 5, 2025

Choose a reason for hiding this comment

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

Now that we updated the serviceLoaded function to print loaded at the end of the string (thanks for making the change), this may not make much sense anymore (the log would end with created loaded). Perhaps we want to use log.debug here instead of log.serviceLoaded?

Copy link
Member Author

Choose a reason for hiding this comment

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

you got me again :) as it is important to know space name to better understand error logs / screenshot, we can use

serviceMessage('scoutSpace', `new Kibana space '${spaceId}' created`)

to see

 debg [scout-worker-1] [scoutSpace] new Kibana space 'test-space-1' created

Copy link

@csr csr Mar 5, 2025

Choose a reason for hiding this comment

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

Neat! Nit, non-blocking at all: perhaps new can be New(uppercase N).

@dmlemeshko dmlemeshko requested a review from csr March 5, 2025 16:30
@elasticmachine
Copy link
Contributor

💔 Build Failed

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/scout 99 102 +3
@kbn/scout-oblt 71 74 +3
total +6
Unknown metric groups

API count

id before after diff
@kbn/scout 389 393 +4
@kbn/scout-oblt 361 365 +4
total +8

History

cc @dmlemeshko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes test:scout v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants