-
Notifications
You must be signed in to change notification settings - Fork 345
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): add business_metrics_wxcc_desktop #4000
base: next
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce a new private method Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options. (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) 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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (3)
packages/@webex/internal-plugin-metrics/src/business-metrics.ts (2)
65-71
: Fix typo in documentationThe JSDoc comment contains a typo in the word "buisness".
- * Submit a buisness metric to our metrics endpoint + * Submit a business metric to our metrics endpoint
72-89
: Consider refactoring to reduce code duplicationThe event construction logic is very similar across all submit methods. Consider extracting the common event construction logic into a shared private method.
Example refactor:
private createBaseEvent(name: string, payload: EventPayload, appType: string, options?: {indexHint?: string}) { return { type: ['business'], eventPayload: { key: name, client_timestamp: new Date().toISOString(), appType, ...(options?.indexHint && {indexHint: options.indexHint}), value: { ...this.getContext(), ...this.getBrowserDetails(), ...payload, }, }, }; } private submitWxccDesktopEvent({name, payload}: {name: string; payload: EventPayload}) { const event = this.createBaseEvent(name, payload, 'WxCC Desktop', {indexHint: 'wxccdesktop'}); return this.submitEvent({ kind: 'business-events:business_metrics_wxcc_desktop -> ', name, event, }); }packages/@webex/internal-plugin-metrics/src/metrics.types.ts (1)
172-177
: LGTM! Consider adding documentation.The addition of
'business_metrics_wxcc_desktop'
to theTable
type is well-structured and aligns with the FedRAMP compliance requirements. The change is non-breaking and follows the existing naming patterns.Consider adding a JSDoc comment above the
Table
type to document the purpose of each table, particularly the newbusiness_metrics_wxcc_desktop
table. This would improve maintainability and help other developers understand when to use each table type.+/** + * Defines the available metric table destinations + * @property business_metrics_wxcc_desktop - Table for FedRAMP compliance metrics from wxcc desktop client + * ... document other table types ... + */ export type Table = | 'wbxapp_callend_metrics' | 'business_metrics' | 'business_ucf' | 'business_metrics_wxcc_desktop' | 'default';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
packages/@webex/internal-plugin-metrics/src/business-metrics.ts
(2 hunks)packages/@webex/internal-plugin-metrics/src/metrics.types.ts
(1 hunks)packages/@webex/internal-plugin-metrics/test/unit/spec/business/business-metrics.ts
(1 hunks)
🧰 Additional context used
🪛 Biome
packages/@webex/internal-plugin-metrics/test/unit/spec/business/business-metrics.ts
[error] 208-208: This property value named locale is later overwritten by an object member with the same name.
Overwritten with this value.
If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named locale
(lint/suspicious/noDuplicateObjectKeys)
🔇 Additional comments (5)
packages/@webex/internal-plugin-metrics/src/business-metrics.ts (2)
141-142
: LGTM!
The switch case addition is clean and follows the established pattern.
Line range hint 65-142
: Verify test coverage for the new functionality
The PR objectives mention that unit tests were added, but they're not visible in the provided files. Please ensure that:
- Test cases cover the new
submitWxccDesktopEvent
method - Test cases verify the correct event structure including the
indexHint
andappType
fields - Test cases validate the new table option in
submitBusinessEvent
✅ Verification successful
Let me check the test file content to verify the test coverage.
Test coverage is complete and accurate
The test file includes comprehensive coverage for the new functionality:
- Test case verifies
submitWxccDesktopEvent
through thebusiness_metrics_wxcc_desktop
table option - Validates correct event structure including
indexHint: 'wxccdesktop'
andappType: 'WxCC Desktop'
- Asserts the proper payload structure and timestamp handling
- Confirms the integration with the table routing in
submitBusinessEvent
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for related test files and their coverage of the new functionality
fd -e test.ts -e spec.ts . | xargs rg -l "business_metrics_wxcc_desktop"
# Look for existing test patterns that should be followed
rg -A 5 "describe.*BusinessMetrics"
Length of output: 754
Script:
#!/bin/bash
# Check the content of the test file
cat "packages/@webex/internal-plugin-metrics/test/unit/spec/business/business-metrics.ts"
Length of output: 8712
packages/@webex/internal-plugin-metrics/src/metrics.types.ts (1)
172-177
: Verify handling of the new table type.
Let's ensure the new table type is properly handled throughout the codebase.
✅ Verification successful
Let me generate another script to check for switch statements handling the table type more specifically:
The new table type is properly handled throughout the codebase
The verification shows that:
- The new table type is properly handled in the switch statement with a dedicated case that maps to
submitWxccDesktopEvent
- The type is properly defined in metrics.types.ts
- The implementation includes proper documentation for the new table type
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify proper handling of the new table type
# Check for switch/case statements that handle table types
echo "Checking for switch statements handling table types..."
rg -A 5 "switch.*\(.*[tT]able.*\)"
# Check for hardcoded table type strings
echo "Checking for hardcoded table type strings..."
rg -i "business_metrics_wxcc_desktop"
# Check for type imports
echo "Checking for Table type imports..."
rg "import.*\{.*Table.*\}.*from.*metrics\.types"
Length of output: 132172
Script:
#!/bin/bash
# Check for switch statements handling table types in business-metrics.ts
echo "Checking switch statement handling of table types..."
rg -A 10 "switch.*\(.*table.*\)" packages/@webex/internal-plugin-metrics/src/business-metrics.ts
# Check for any other references to the table type
echo "Checking for other table type references..."
rg -A 2 "business_metrics_wxcc_desktop" packages/@webex/internal-plugin-metrics/src/
Length of output: 1793
packages/@webex/internal-plugin-metrics/test/unit/spec/business/business-metrics.ts (2)
185-219
: LGTM! Test structure follows established patterns.
The new test case is well-organized and follows the existing test structure, maintaining consistency with other table-specific tests.
🧰 Tools
🪛 Biome
[error] 208-208: This property value named locale is later overwritten by an object member with the same name.
Overwritten with this value.
If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named locale
(lint/suspicious/noDuplicateObjectKeys)
185-219
: Verify FedRAMP compliance requirements coverage.
While the test covers the basic functionality, please verify if there are any additional FedRAMP-specific requirements that need to be validated in the test case, such as:
- Required fields for compliance
- Data format validations
- Security-related assertions
Let me help verify the FedRAMP requirements:
🧰 Tools
🪛 Biome
[error] 208-208: This property value named locale is later overwritten by an object member with the same name.
Overwritten with this value.
If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named locale
(lint/suspicious/noDuplicateObjectKeys)
}, | ||
}; | ||
|
||
return this.submitEvent({kind: 'buisness-events:business_metrics -> ', name, event}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect metrics kind parameter
The kind
parameter in submitEvent
should reflect the correct table name:
- return this.submitEvent({kind: 'buisness-events:business_metrics -> ', name, event});
+ return this.submitEvent({kind: 'business-events:business_metrics_wxcc_desktop -> ', name, event});
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
return this.submitEvent({kind: 'buisness-events:business_metrics -> ', name, event}); | |
return this.submitEvent({kind: 'business-events:business_metrics_wxcc_desktop -> ', name, event}); |
locale: window.navigator.language, | ||
os: getOSNameInternal(), | ||
app: {version: 'webex-version'}, | ||
device: {id: 'deviceId'}, | ||
locale: 'language', | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix duplicate 'locale' property in test assertions.
The value
object contains duplicate locale
properties at lines 208 and 212, where the second one overwrites the first. This could mask potential issues in the actual implementation.
Apply this diff to fix the duplicate property:
locale: window.navigator.language,
os: getOSNameInternal(),
app: {version: 'webex-version'},
device: {id: 'deviceId'},
- locale: 'language',
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
locale: window.navigator.language, | |
os: getOSNameInternal(), | |
app: {version: 'webex-version'}, | |
device: {id: 'deviceId'}, | |
locale: 'language', | |
} | |
locale: window.navigator.language, | |
os: getOSNameInternal(), | |
app: {version: 'webex-version'}, | |
device: {id: 'deviceId'}, | |
} |
🧰 Tools
🪛 Biome
[error] 208-208: This property value named locale is later overwritten by an object member with the same name.
Overwritten with this value.
If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored.
Unsafe fix: Remove this property value named locale
(lint/suspicious/noDuplicateObjectKeys)
* @param {EventPayload} payload payload of the metric | ||
* @returns {Promise<any>} | ||
*/ | ||
private submitWxccDesktopEvent({name, payload}: {name: string; payload: EventPayload}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that we shouldnt have product specific APIs. Can we achieve the same in a generic way? eg some "transform" mechanism that we can inject, or by setting config centrally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API the SDK currently exposes is
submitBusinessEvent({
name: string;
payload: EventPayload;
table?: Table;
})
(we can't make a breaking change or else we have to bump the major version number of the SDK)
We could add a second method like:
submitBusinessEvent({
name: string;
payload: EventPayload;
eventMetadata: EventPayload;
})
where eventMetadata
contains the appType
and indexHint
, or anything else, for future generic use
COMPLETES #CX-17090
This pull request addresses CX-17090
by making the following changes, we allow consumers of the SDK to send metrics to the
business_metrics_wxcc_desktop
talbe in Pinot.Add a new value to the
Table
enum, which describes which table in Pinot a business metric event should be sent to:business_metrics_wxcc_desktop
; and corresponding method inbusiness-metrics.ts
to send the metric with the appropriate metadata.Change Type
The following scenarios were tested
Sent a metric event from the wxcc_desktop client using this new code path, and observed it in Pinot in the desired table. Added unit test.
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.
Summary by CodeRabbit
New Features
Bug Fixes
Tests