generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 7
chore: Improve metrics format #116
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,69 +23,47 @@ describe('PanoramaClient', () => { | |
| }); | ||
|
|
||
| test('sends simple metrics', () => { | ||
| panorama.sendMetric({ eventType: 'custom', eventValue: 'value' }); | ||
| panorama.sendMetric({ eventValue: 'value' }); | ||
|
|
||
| expect(window.panorama).toHaveBeenCalledWith( | ||
| 'trackCustomEvent', | ||
| expect.objectContaining({ eventType: 'custom', eventValue: 'value' }) | ||
| expect.objectContaining({ eventType: 'awsui', eventValue: 'value' }) | ||
| ); | ||
| }); | ||
|
|
||
| test('converts objects to strings', () => { | ||
| panorama.sendMetric({ eventType: 'custom', eventValue: { test: 'value' }, eventDetail: { test: 'detail' } }); | ||
| panorama.sendMetric({ eventValue: { test: 'value' }, eventDetail: { test: 'detail' } }); | ||
|
|
||
| expect(window.panorama).toHaveBeenCalledWith( | ||
| 'trackCustomEvent', | ||
| expect.objectContaining({ eventType: 'custom', eventValue: '{"test":"value"}', eventDetail: '{"test":"detail"}' }) | ||
| expect.objectContaining({ eventValue: '{"test":"value"}', eventDetail: '{"test":"detail"}' }) | ||
| ); | ||
| }); | ||
|
|
||
| test('prints an error when event details are too long', () => { | ||
| const eventDetail = 'a'.repeat(4001); | ||
| panorama.sendMetric({ eventType: 'custom', eventDetail }); | ||
| panorama.sendMetric({ eventContext: 'custom', eventDetail }); | ||
|
|
||
| expect(window.panorama).toHaveBeenCalledTimes(1); | ||
| expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', { | ||
| eventName: 'awsui-metric-error', | ||
| eventType: 'awsui', | ||
| eventContext: 'awsui-metric-error', | ||
| eventDetail: expect.stringMatching(/Event detail for metric is too long:.*/), | ||
| timestamp: expect.any(Number), | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith(`Event detail for metric is too long: ${eventDetail}`); | ||
| }); | ||
|
|
||
| test('prints an error when event type is too long', () => { | ||
| const eventType = 'a'.repeat(51); | ||
| const errorMessage = `Event type for metric is too long: ${eventType}`; | ||
| panorama.sendMetric({ eventType }); | ||
|
|
||
| expect(window.panorama).toHaveBeenCalledTimes(1); | ||
| expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', { | ||
| eventName: 'awsui-metric-error', | ||
| eventDetail: errorMessage, | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith(errorMessage); | ||
| }); | ||
|
|
||
| test('prints an error when event name is too long', () => { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed this test, because "eventName" attribute is not supported anymore |
||
| const eventName = 'a'.repeat(1001); | ||
| const errorMessage = `Event name for metric is too long: ${eventName}`; | ||
| panorama.sendMetric({ eventName }); | ||
|
|
||
| expect(window.panorama).toHaveBeenCalledTimes(1); | ||
| expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', { | ||
| eventName: 'awsui-metric-error', | ||
| eventDetail: errorMessage, | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith(errorMessage); | ||
| }); | ||
|
|
||
| test('prints an error when event value is too long', () => { | ||
| const eventValue = 'a'.repeat(4001); | ||
| panorama.sendMetric({ eventValue }); | ||
|
|
||
| expect(window.panorama).toHaveBeenCalledTimes(1); | ||
| expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', { | ||
| eventName: 'awsui-metric-error', | ||
| eventType: 'awsui', | ||
| eventContext: 'awsui-metric-error', | ||
| eventDetail: expect.stringMatching(/Event value for metric is too long:.*/), | ||
| timestamp: expect.any(Number), | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith(`Event value for metric is too long: ${eventValue}`); | ||
| }); | ||
|
|
@@ -96,8 +74,10 @@ describe('PanoramaClient', () => { | |
|
|
||
| expect(window.panorama).toHaveBeenCalledTimes(1); | ||
| expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', { | ||
| eventName: 'awsui-metric-error', | ||
| eventType: 'awsui', | ||
| eventContext: 'awsui-metric-error', | ||
| eventDetail: expect.stringMatching(/Event context for metric is too long:.*/), | ||
| timestamp: expect.any(Number), | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith(`Event context for metric is too long: ${eventContext}`); | ||
| }); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removed this test, because setting a custom type is not possible anymore (it is always "awsui")