Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: track usage of organizations in telemetry #16323

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

Merged
merged 8 commits into from
Jan 29, 2025

Conversation

hugodutka
Copy link
Contributor

@hugodutka hugodutka commented Jan 29, 2025

Addresses coder/internal#317.

Changes

Requirements are quoted below:

how many orgs does deployment have

Adds the Organization entity to telemetry.

ensuring resources are associated with orgs

All resources that reference an org already report the org id to telemetry. Adds a test to check that.

whether org sync is configured

Adds the IDPOrgSync boolean field to the Deployment entity.

Implementation of the org sync check

While there's an OrganizationSyncEnabled method on the IDPSync interface, I decided not to use it directly and implemented a counterpart just for telemetry purposes. It's a compromise I'm not happy about, but I found that it's a simpler approach than the alternative. There are multiple reasons:

  1. The telemetry package cannot statically access the IDPSync interface due to a circular import.
  2. We can't dynamically pass a reference to the OrganizationSyncEnabled function at the time of instantiating the telemetry object, because our server initialization logic depends on the telemetry object being created before the IDPSync object.
  3. If we circumvent that problem by passing the reference as an initially empty pointer, initializing telemetry, then IDPSync, then updating the pointer to point to OrganizationSyncEnabled, we have to refactor the initialization logic of the telemetry object itself to avoid a race condition where the first telemetry report is performed without a valid reference.

I actually implemented that approach in #16307, but realized I'm unable to fully test it. It changed the initialization order in the server command, and I wanted to test our CLI with Org Sync configured with a premium license. As far as I'm aware, we don't have the tooling to do that. I couldn't figure out a way to start the CLI with a mock license, and I didn't want to go down further into the refactoring rabbit hole.

So I decided that reimplementing the org sync checking logic is simpler.

@hugodutka hugodutka marked this pull request as ready for review January 29, 2025 13:28
@hugodutka hugodutka requested a review from Emyrk January 29, 2025 13:29
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

I see the initialization order of IDP sync in server.go

Telemetry happens before coderd, and coderd inits the IDPsync.

I also see the import cycle.


If you want to fix the import cycle, we can just move ReportCLITelemetry to the telemetry package. It is the only code in httpmw that requires telemetry, and it does not need any other httpmw code.

The initialization order is a bit tricky, as you mentioned. I do not know if moving the idp sync init outside the coderd.New would cause issues.

In general, I wish our init code was easier to read and maintain 😢


I'll defer to your judgement. Since this is just telemetry, and the implementation will be relatively static, I am fine with this 👍

Comment on lines +568 to +571
// Warning: When an organization is deleted, it's completely removed from
// the database. It will no longer be reported, and there will be no other
// indicator that it was deleted. This requires special handling when
// interpreting the telemetry data later.
Copy link
Member

Choose a reason for hiding this comment

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

We do intend to fix that with soft deletes.

#16166

@Emyrk
Copy link
Member

Emyrk commented Jan 29, 2025

Note: httpmw is quite bloated. Imo middleware should live in the packages that defines it. Calling telemetry.ReportCLITelemetry for the middleware is more idiomatic imo.

@hugodutka
Copy link
Contributor Author

If you want to fix the import cycle

To avoid code duplication, we'd have to fix both the import cycle and the init order, and the latter is tricky. I'd rather not do that now, but it'd be great to eventually fix it.

@hugodutka hugodutka merged commit 92d22e2 into main Jan 29, 2025
32 checks passed
@hugodutka hugodutka deleted the hugodutka/org-telemetry-2 branch January 29, 2025 14:54
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2025
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.

2 participants