This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Connect: Collect usage events #1451
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
9e9e47b
Ask user about collecting data (disabled for now)
gzdunek 93b2558
Add `UsageEventService`, generate `IAppContext` basing on `AppContext`
gzdunek 40858ae
Add gRPC method to report usage events
gzdunek 7c55c5c
Extend `RuntimeSettings` with some os/connect info
gzdunek 3a682f9
Collect actual events
gzdunek ceb2097
Merge branch 'master' into gzdunek/collect-usage-events
gzdunek f985129
Revert adding `runBeforeUiIsVisible/runAfterUiIsVisible` to context, …
gzdunek febea18
Move logger to the class
gzdunek 5aac72c
Send events in dev mode
gzdunek 2b1093e
Revert changes to `IAppContext`
gzdunek 943ebb6
Remove tshd usage events, create Prehog events directly
gzdunek 1e4505e
Remove `connect.` from `distinctId` (it will be added in prehog)
gzdunek b97f5d7
Rename `UsageEventService` to `UsageService`
gzdunek 492fe48
Rename `UsageEventWithDate` to `ReportUsageEventRequest`
gzdunek 10a2977
Rename `prehogEvent`, `prehogApiEvent` etc
gzdunek c04639e
Add more comments
gzdunek 98dd193
Merge branch 'master' into gzdunek/collect-usage-events
gzdunek 3b27e8c
Read version from `package.json` in dev mode
gzdunek 1aca8f9
Fix tests
gzdunek b74a13d
Rename method and type in `UsageService`
gzdunek 7a6a408
Rename `ReportEvent` to `ReportUsageEvent` in gRPC service for better…
gzdunek d596be5
Move warning up, adjust some methods names to events names
gzdunek 207d623
Rename `connectVersion` to `appVersion`
gzdunek 02df49a
Show warning when reporting usage event fails
gzdunek a860fa9
Merge branch 'master' into gzdunek/collect-usage-events
gzdunek 97f8c63
Provide `authClusterId` in `getClusterProperties`
gzdunek e8e394d
Update protos to final version
gzdunek 7836241
Collect connector type
gzdunek 3330210
Pass prehog address to tshd
gzdunek a69c7af
Merge branch 'master' into gzdunek/collect-usage-events
gzdunek b3ac84d
Merge branch 'master' into gzdunek/collect-usage-events
gzdunek 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
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
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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb'; | ||
|
|
||
| import * as api from './v1/usage_events_pb'; | ||
| import * as prehogApi from './prehog/v1alpha/connect_pb'; | ||
|
|
||
| import * as types from './types'; | ||
|
|
||
| /** | ||
| * Maps a plain JS object into a gRPC request object. | ||
| */ | ||
| export function mapUsageEvent(event: types.ReportUsageEventRequest) { | ||
| return new api.ReportUsageEventRequest() | ||
| .setAuthClusterId(event.authClusterId) | ||
| .setPrehogReq(mapPrehogBody(event.prehogReq)); | ||
| } | ||
|
|
||
| function mapPrehogBody( | ||
| plainReq: types.ReportUsageEventRequest['prehogReq'] | ||
| ): prehogApi.SubmitConnectEventRequest { | ||
| const req = new prehogApi.SubmitConnectEventRequest() | ||
| .setTimestamp(Timestamp.fromDate(plainReq.timestamp)) | ||
| .setDistinctId(plainReq.distinctId); | ||
|
|
||
| // Non-anonymized events. | ||
| if (plainReq.userJobRoleUpdate) { | ||
| const event = plainReq.userJobRoleUpdate; | ||
| const reqEvent = new prehogApi.ConnectUserJobRoleUpdateEvent().setJobRole( | ||
| event.jobRole | ||
| ); | ||
|
|
||
| return req.setUserJobRoleUpdate(reqEvent); | ||
| } | ||
|
|
||
| // Anonymized events. | ||
| if (plainReq.clusterLogin) { | ||
| const event = plainReq.clusterLogin; | ||
| const reqEvent = new prehogApi.ConnectClusterLoginEvent() | ||
| .setClusterName(event.clusterName) | ||
| .setUserName(event.userName) | ||
| .setConnectorType(event.connectorType) | ||
| .setOs(event.os) | ||
| .setArch(event.arch) | ||
| .setOsVersion(event.osVersion) | ||
| .setAppVersion(event.appVersion); | ||
|
|
||
| return req.setClusterLogin(reqEvent); | ||
| } | ||
| if (plainReq.protocolUse) { | ||
| const event = plainReq.protocolUse; | ||
| const reqEvent = new prehogApi.ConnectProtocolUseEvent() | ||
| .setClusterName(event.clusterName) | ||
| .setUserName(event.userName) | ||
| .setProtocol(event.protocol); | ||
|
|
||
| return req.setProtocolUse(reqEvent); | ||
| } | ||
| if (plainReq.accessRequestCreate) { | ||
| const event = plainReq.accessRequestCreate; | ||
| const reqEvent = new prehogApi.ConnectAccessRequestCreateEvent() | ||
| .setClusterName(event.clusterName) | ||
| .setUserName(event.userName) | ||
| .setKind(event.kind); | ||
|
|
||
| return req.setAccessRequestCreate(reqEvent); | ||
| } | ||
| if (plainReq.accessRequestReview) { | ||
| const event = plainReq.accessRequestReview; | ||
| const reqEvent = new prehogApi.ConnectAccessRequestReviewEvent() | ||
| .setClusterName(event.clusterName) | ||
| .setUserName(event.userName); | ||
|
|
||
| return req.setAccessRequestReview(reqEvent); | ||
| } | ||
| if (plainReq.accessRequestAssumeRole) { | ||
| const event = plainReq.accessRequestAssumeRole; | ||
| const reqEvent = new prehogApi.ConnectAccessRequestAssumeRoleEvent() | ||
| .setClusterName(event.clusterName) | ||
| .setUserName(event.userName); | ||
|
|
||
| return req.setAccessRequestAssumeRole(reqEvent); | ||
| } | ||
| if (plainReq.fileTransferRun) { | ||
| const event = plainReq.fileTransferRun; | ||
| const reqEvent = new prehogApi.ConnectFileTransferRunEvent() | ||
| .setClusterName(event.clusterName) | ||
| .setUserName(event.userName) | ||
| .setIsUpload(event.isUpload); | ||
|
|
||
| return req.setFileTransferRun(reqEvent); | ||
| } | ||
|
|
||
| throw new Error(`Unrecognized event: ${JSON.stringify(plainReq)}`); | ||
| } |
42 changes: 42 additions & 0 deletions
42
packages/teleterm/src/services/tshd/prehog/v1alpha/connect_grpc_pb.d.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
packages/teleterm/src/services/tshd/prehog/v1alpha/connect_grpc_pb.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
See, if we had a proper config file for dev & prod, we could use staging in dev and the prod address in the packaged app.
We have to spend a little bit of time on that some time. I'm thinking of adding something like dotenv. Perhaps there are other libs which are better suited for the kind of app we're working on.
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.
Sure, I'm happy to do it in a proper way. I think for now we can leave it as it is (we don't have prod env for Connect yet) and I will fix it soon.