Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Connect: Collect usage events#1451

Merged
gzdunek merged 31 commits intomasterfrom
gzdunek/collect-usage-events
Jan 10, 2023
Merged

Connect: Collect usage events#1451
gzdunek merged 31 commits intomasterfrom
gzdunek/collect-usage-events

Conversation

@gzdunek
Copy link
Copy Markdown
Contributor

@gzdunek gzdunek commented Dec 21, 2022

Part of gravitational/teleport#19000
Teleport counterpart gravitational/teleport#19564

This PR adds actual events collection in the UI/services.

TODO (in separate PRs):

  • show a dialog asking user about they job role
  • provide authClusterId - without it events can't be anonymized

@gzdunek gzdunek requested review from avatus and ravicious December 21, 2022 13:10
@gzdunek gzdunek force-pushed the gzdunek/collect-usage-events branch from eec7d51 to 3a682f9 Compare December 21, 2022 15:44

captureProtocolRun(
uri: ClusterOrResourceUri,
protocol: 'ssh' | 'kube' | 'db'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In the RFD I was planning proxy_db, but I think we can just send db, we will match other teleport events.

Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

I left some questions/comments on the details of the implementations, I'll leave a comment about the general approach soon – I'm not sure if here or under the teleport PR though.

Comment thread packages/teleterm/src/ui/AppInitializer.tsx Outdated
Comment thread packages/teleterm/src/ui/appContext.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/types.ts Outdated
Comment thread packages/teleterm/src/ui/services/clusters/clustersService.ts Outdated
@gzdunek gzdunek force-pushed the gzdunek/collect-usage-events branch from 2a85249 to 1e4505e Compare December 30, 2022 16:57
@gzdunek
Copy link
Copy Markdown
Contributor Author

gzdunek commented Dec 30, 2022

I incorporated the changes from #1464

Comment thread packages/teleterm/src/ui/initUi.ts
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/clusters/clustersService.ts Outdated
Comment thread packages/teleterm/src/ui/services/usageEvent/usageEventService.ts Outdated
Comment thread packages/teleterm/src/ui/services/clusters/clustersService.ts Outdated
Comment thread packages/teleterm/src/ui/types.ts Outdated
Comment thread packages/teleterm/src/services/tshd/types.ts Outdated
Comment thread packages/teleterm/src/services/tshd/mapUsageEvent.ts Outdated
Comment thread packages/teleterm/src/mainProcess/runtimeSettings.ts Outdated
Comment thread packages/teleterm/src/ui/services/usage/usageService.ts Outdated
return;
}

return this.tshClient.reportUsageEvent({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At the moment, every place that calls UsageService does so without checking if reportEvent returns an error.

In the dev version this will show that unhandled rejection modal, in the prod version there will be a log entry in the renderer log but otherwise it'll be silently ignored.

Also, in all cases at the moment the successful usage of a given feature doesn't hinge on successfully reporting the usage, that is when I'm connecting to a server, I don't really care if the usage is reported or not because it's not needed in order to connect to a server.


Any thoughts on how we should approach this?

I was thinking of sending warnings when this happens, OTOH this is not something the user can do anything about. Like imagine Teleport's reporting APIs fail but otherwise the cluster that the user is logged to works just fine.

What if we just logged the error and then ignored it, making it so that UsageService methods don't fail on the call to tshClient?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While writing this I realized that right now the calls to report the event fail only because authClusterId is missing. But it's not like the events are reported during the RPC that creates the event, that's a batched action.

In that case, perhaps sending warnings would be a good solution here? If tshClient.reportUsageEvent fails, it's due to a bug in our codebase and not a problem with our infrastructure.

In that case, I think surfacing it to the user is worthwhile. Otherwise it's possible that we'd never learn about the problem in the first place, we'd simply see a drop in events reported from Connect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I wasn't sure what to do about it, so I left it without handling (so we would be able to at least see it in dev mode). As you said an error is only shown when there is a problem between Electron and tshd, not because prehog is down for example (this problem will be visible in tshd logs only).
Adding a warning looks like the best option to handle this.

Comment thread packages/teleterm/src/ui/services/usage/usageService.ts Outdated
Comment on lines +75 to +77
this.logger.warn(
`Missing cluster data for ${uri}, skipping protocolUse event`
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd go with a single handler for this in reportEvent instead of repeating that in every event.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean it's fine for now but I'd probably refactor this later down the line.

// Allows running tsh in insecure mode (development)
const isInsecure = dev || argv.includes('--insecure');

const PREHOG_ADDR = 'https://reporting-staging.teleportinfra.dev'; // TODO(gzdunek): change to prod before going live
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@gzdunek gzdunek merged commit fe25846 into master Jan 10, 2023
@gzdunek gzdunek deleted the gzdunek/collect-usage-events branch January 10, 2023 17:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants