-
Notifications
You must be signed in to change notification settings - Fork 324
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(mv3): Tracking URL resolved/observed count. #1245
Merged
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ec638a2
fix(mv3): Reverting Telemetry Changes To Use PatchedCountlySDK
whizzzkid cf2ca84
fix(mv3): metrics build
whizzzkid f26abf0
fix: more reverts + fixing patch
whizzzkid 63bccae
feat: adding request view.
whizzzkid 1efcf61
Merge branch 'rc/3.0-mv3' into feature/track-url-count-served
whizzzkid e39a4eb
Reverting to mainline rc patch
whizzzkid dff1d6d
Reverting to mainline rc add-on/src/lib/ipfs-companion.js
whizzzkid 7794100
feat(telemetry):
whizzzkid bbde716
feat(telemetry): Implementing RequestTracker Event Handler
whizzzkid 7666925
feat(telemetry): hooking up events.
whizzzkid d50c9c6
fix(types): annotations
whizzzkid 7228821
fix(telemetry): :wastebasket: returning to previous state
whizzzkid 51c7dc6
fix(telemetry): :recycle: Refactor Request Tracker
whizzzkid dca45a2
fix(telemetry): hooking up requests
whizzzkid bf4dcb0
fix(telemetry): better types
whizzzkid 29d5a5e
fix(countly): :wastebasket: more stuff goes, because test need to pass.
whizzzkid d2dfc50
fix(lint): fixed
whizzzkid c954c28
feat(test): test tracker.
whizzzkid 5af0125
fix: remove only
whizzzkid 8c9e427
fix: :lipstick: line break
whizzzkid 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import debug from 'debug' | ||
import type browser from 'webextension-polyfill' | ||
import { trackEvent } from '../telemetry.js' | ||
|
||
export class RequestTracker { | ||
private readonly eventKey: 'url-observed' | 'url-resolved' | ||
private readonly flushInterval: number | ||
private readonly log: debug.Debugger & { error?: debug.Debugger } | ||
private lastSync: number = Date.now() | ||
private requestTypeStore: { [key in browser.WebRequest.ResourceType]?: number } = {} | ||
|
||
constructor (eventKey: 'url-observed' | 'url-resolved', flushInterval = 1000 * 60 * 5) { | ||
this.eventKey = eventKey | ||
this.log = debug(`ipfs-companion:request-tracker:${eventKey}`) | ||
this.log.error = debug(`ipfs-companion:request-tracker:${eventKey}:error`) | ||
this.flushInterval = flushInterval | ||
this.setupFlushScheduler() | ||
} | ||
|
||
track ({ type }: browser.WebRequest.OnBeforeRequestDetailsType): void { | ||
this.log(`track ${type}`, JSON.stringify(this.requestTypeStore)) | ||
this.requestTypeStore[type] = (this.requestTypeStore[type] ?? 0) + 1 | ||
} | ||
|
||
private flushStore (): void { | ||
this.log('flushing') | ||
const count = Object.values(this.requestTypeStore).reduce((a, b): number => a + b, 0) | ||
if (count === 0) { | ||
this.log('nothing to flush') | ||
return | ||
} | ||
trackEvent({ | ||
key: this.eventKey, | ||
count, | ||
dur: Date.now() - this.lastSync, | ||
segmentation: Object.assign({}, this.requestTypeStore) as unknown as Record<string, string> | ||
}) | ||
// reset | ||
this.lastSync = Date.now() | ||
this.requestTypeStore = {} | ||
} | ||
|
||
private setupFlushScheduler (): void { | ||
setTimeout(() => { | ||
this.flushStore() | ||
this.setupFlushScheduler() | ||
}, this.flushInterval) | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
declare module 'countly-web-sdk' { | ||
export interface CountlyEvent { | ||
key: string | ||
count?: number | ||
sum?: number | ||
dur?: number | ||
segmentation?: Record<string, string> | ||
} | ||
} |
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.
flushes events as combined entity on.