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

feat(internal-plugin-metrics): allow for delayed submission of client events #4121

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

jor-row
Copy link
Contributor

@jor-row jor-row commented Feb 28, 2025

… events

COMPLETES #SPARK-623039

https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-623039

As part of the preload feature on web client we need to delay sending all client events until the user decides to join via web. So, we need a mechanism to delay these events in the sdk.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

@jor-row jor-row requested review from a team as code owners February 28, 2025 00:48
Copy link

coderabbitai bot commented Feb 28, 2025

📝 Walkthrough

Walkthrough

The changes add support for delaying the submission of client events within the metrics system. In the CallDiagnosticMetrics class, a new private array stores delayed events, and the submitClientEvent method is updated with an optional flag to delay submission. When this flag is active, the event along with its timestamp is stored rather than being sent immediately. A new method, submitDelayedClientEvents, processes and clears these delayed events by invoking the standard submission logic. Additionally, an interface (DelayedClientEvent) is introduced to define the structure for delayed events. The Metrics class is also updated with a boolean property to control event delay, alongside methods to toggle this behavior and trigger delayed event submission. Test cases have been added or updated to verify the behavior of the new delay logic and the inclusion of the webClientPreload property in event payloads.

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning glob@7.2.3: Glob versions prior to v9 are no longer supported
warning intern > glob@7.1.7: Glob versions prior to v9 are no longer supported
warning intern > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jasmine > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning mocha > glob@7.2.0: Glob versions prior to v9 are no longer supported
warning mocha > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning sinon@9.2.4: 16.1.1
warning sinon > @sinonjs/samsam > lodash.get@4.4.2: This package is deprecated. Use the optional chaining (?.) operator instead.
warning wd > q@1.5.1: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning wd > request@2.88.0: request has been deprecated, see request/request#3142
warning wd > archiver > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning wd > request > uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning wd > request > har-validator@5.1.5: this library is no longer supported
warning wd > archiver > archiver-utils > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @babel/cli > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning @babel/plugin-proposal-export-namespace-from@7.18.9: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning @babel/runtime-corejs2 > core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning babel-plugin-lodash > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > sinon@9.2.4: 16.1.1
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/plugin-proposal-export-namespace-from@7.18.9: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning workspace-aggregator-d1c25205-fe9c-4671-8dd8-d82097523cc5 > @babel/polyfill@7.12.1: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
[2/4] Fetching packages...
error eslint-plugin-jsdoc@40.3.0: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (8)
packages/@webex/internal-plugin-metrics/src/metrics.types.ts (1)

323-328: Add a descriptive doc comment for this interface.

Adding a JSDoc or a short documentation snippet for DelayedClientEvent might help maintain clarity and context around its usage.

packages/@webex/internal-plugin-metrics/test/unit/spec/new-metrics.ts (2)

263-276: Thorough test for toggling delayed submission.

This test confirms that setting delaySubmitClientEvents behaves as expected. Consider including an additional test for quickly toggling the setting multiple times in succession.


278-286: Properly verifying the submitDelayedClientEvents invocation.

Ensures that the method is called once, matching expectations. You could expand the test to assert the promise resolution or returned values if needed.

packages/@webex/internal-plugin-metrics/src/new-metrics.ts (2)

48-52: Consider clarifying uses for delaySubmitClientEvents.

The doc comment is concise. Optionally, expand on scenarios (e.g., preload) where deferring event submissions offers tangible benefits.


402-417: Handle or log potential errors during bulk submission.

submitDelayedClientEvents() returns a promise that could fail if any delayed event submissions fail. Consider catching and logging partial errors for clarity.

packages/@webex/internal-plugin-metrics/src/call-diagnostic/call-diagnostic-metrics.ts (3)

863-863: Doc comment additions are helpful.

Providing a brief example of how delaySubmitEvent might be used could further improve clarity for future maintainers.


877-891: Buffering events instead of sending immediately.

By pushing to delayedClientEvents before returning, you ensure minimal overhead for delayed submissions. For critical events, consider implementing fallback or logging if the queue becomes large.


909-929: Bulk submission logic seems solid.

submitDelayedClientEvents() correctly iterates over the stored events. If partial failures matter, consider capturing individual errors from Promise.all().

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6802b46 and 4a431bd.

📒 Files selected for processing (5)
  • packages/@webex/internal-plugin-metrics/src/call-diagnostic/call-diagnostic-metrics.ts (6 hunks)
  • packages/@webex/internal-plugin-metrics/src/metrics.types.ts (1 hunks)
  • packages/@webex/internal-plugin-metrics/src/new-metrics.ts (3 hunks)
  • packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts (21 hunks)
  • packages/@webex/internal-plugin-metrics/test/unit/spec/new-metrics.ts (3 hunks)
🔇 Additional comments (9)
packages/@webex/internal-plugin-metrics/test/unit/spec/new-metrics.ts (2)

62-62: Test stub initialization looks good.

Stubbing submitDelayedClientEvents ensures the invocation can be easily tracked without making actual calls.


124-124: Explicitly setting the delaySubmitEvent property is good practice.

Declaring delaySubmitEvent: false clarifies the default immediate-submission scenario for readability and maintainability.

packages/@webex/internal-plugin-metrics/src/new-metrics.ts (1)

298-303: Properly routing the delaySubmitEvent flag.

Passing the delaySubmitEvent property ensures consistent handling in callDiagnosticMetrics. This is a clean integration point.

packages/@webex/internal-plugin-metrics/src/call-diagnostic/call-diagnostic-metrics.ts (1)

99-99: Initializing an array for delayed events looks good.

Storing delayed events in-memory is straightforward. Double-check concurrency scenarios if multiple calls might happen in parallel.

packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts (5)

16-17: LGTM - New imports for testing

These imports are appropriate for enhanced test functionality.


142-142: Good practice to reset global state

Properly resetting global.window.webClientPreload after each test prevents test state from leaking between test cases.


848-848: LGTM - Added webClientPreload property to event payloads

The new webClientPreload property is consistently added to all relevant event payloads, which aligns with the PR objective of supporting the preload feature.

Also applies to: 874-874, 911-911, 985-985, 1012-1012, 1050-1050, 1168-1169, 1190-1190, 1264-1265, 1292-1292, 1445-1446, 1467-1468, 1539-1539, 1619-1619, 1691-1691, 1765-1765, 1848-1848


1403-1480: Good test coverage for webClientPreload functionality

This test case properly verifies that the webClientPreload property is included in event payloads when the feature is enabled through the global window object.


3053-3126: Well-structured tests for delayed event submission

These tests thoroughly validate the new submitDelayedClientEvents functionality:

  1. Verifies no action is taken when there are no delayed events
  2. Confirms each delayed event is properly submitted with its original timestamp
  3. Ensures the delayed events array is cleared after submission

The implementation follows good practices by preserving the original triggered time of each event.

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4121.d3m3l2kee0btzx.amplifyapp.com

@jor-row jor-row added the validated If the pull request is validated for automation. label Feb 28, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
packages/@webex/internal-plugin-metrics/src/new-metrics.ts (2)

48-52: Consider adding an explicit type annotation.

Although this property is clearly assigned a boolean, adding : boolean explicitly can improve clarity and help avoid unintentional type changes in the future.


402-417: Consider robust error handling on delayed submissions.

When shouldDelay transitions from true to false, submitDelayedClientEvents() is invoked. If submissions fail, it might be beneficial to catch and handle errors (e.g., retry or log).

packages/@webex/internal-plugin-metrics/src/call-diagnostic/call-diagnostic-metrics.ts (1)

911-931: Consider handling async outcomes when clearing delayed events.

After calling submitClientEvent for each delayed event, failures, if any, may silently skip logging or future retries. It might be worthwhile to handle promise rejections to avoid losing critical diagnostics.

packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts (2)

16-17: Remove unused import if not required.

It appears glob is not actually referenced. You can safely remove it to keep the test file tidy.

-import { glob } from 'glob';
 import { expect } from 'chai';

3050-3123: Add negative test cases.

The new tests confirm that delayed events are submitted correctly. You might consider a scenario where submissions fail to ensure graceful handling of rejections or retries.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a431bd and 96c7e86.

📒 Files selected for processing (4)
  • packages/@webex/internal-plugin-metrics/src/call-diagnostic/call-diagnostic-metrics.ts (6 hunks)
  • packages/@webex/internal-plugin-metrics/src/new-metrics.ts (3 hunks)
  • packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts (20 hunks)
  • packages/@webex/internal-plugin-metrics/test/unit/spec/new-metrics.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@webex/internal-plugin-metrics/test/unit/spec/new-metrics.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Packages
  • GitHub Check: AWS Amplify Console Web Preview
🔇 Additional comments (5)
packages/@webex/internal-plugin-metrics/src/new-metrics.ts (1)

298-303: Looks good and straightforward.

Passing delaySubmitEvent: this.delaySubmitClientEvents cleanly integrates the delay submission logic without altering existing function signatures.

packages/@webex/internal-plugin-metrics/src/call-diagnostic/call-diagnostic-metrics.ts (3)

43-44: Import statement confirmed.

Importing DelayedClientEvent from metrics.types is aligned with the new delayed submission feature.


99-99: Good use of a typed array.

Storing delayed events in delayedClientEvents is a straightforward approach.


865-893: Documentation and parameter usage look solid.

The delaySubmitEvent parameter and corresponding doc block are consistent. Preserving a timestamp before deferring the event submission is a neat solution for accurate event chronologies.

packages/@webex/internal-plugin-metrics/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts (1)

1402-1477: Test coverage for webClientPreload looks thorough.

The new test effectively verifies payload fields and ensures the property is included in event submissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants