Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add usage tracking package#19095

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deansheather merged 5 commits intomainfrom07-30-chore_add_usage_tracking_package
Aug 15, 2025

Conversation

deansheather
Copy link
Member

@deansheatherdeansheather commentedJul 30, 2025
edited
Loading

Not used in coderd yet, see stack.

Adds two new packages:

  • coderd/usage: provides an interface for the "Collector" as well as a stub implementation for AGPL
  • enterprise/coderd/usage: provides an interface for the "Publisher" as well as a Tallyman implementation

Relates tocoder/internal#814

@deansheatherGraphite App
Copy link
MemberAuthor

deansheather commentedJul 30, 2025
edited
Loading

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

I have some non-blocking comments below but might need to take another pass.

const (
CoderLicenseJWTHeader="Coder-License-JWT"

tallymanURL="https://tallyman-ingress.coder.com"
Copy link
Member

Choose a reason for hiding this comment

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

I can see an argument for making this avar so it's configurable at build time.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

If we do need that we can add it very easily in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Obligatory reminder to check migration number before merging!

@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelAug 7, 2025
@deansheatherdeansheather removed the staleThis issue is like stale bread. labelAug 12, 2025
@deansheatherdeansheatherforce-pushed the07-30-chore_add_usage_tracking_package branch frome376311 to82ea8e1CompareAugust 15, 2025 09:28
Copy link
Member

@johnstcnjohnstcn left a comment
edited
Loading

Choose a reason for hiding this comment

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

I don't have any further blocking comments and the dbauthz stuff looks OK to me. I'd like a +1 from Spike before merging though. You probably also need to runmake gen again.

Copy link
Contributor

@spikecurtisspikecurtis left a comment

Choose a reason for hiding this comment

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

LGTM modulogen failures

Copy link
Member

@EmyrkEmyrk left a comment

Choose a reason for hiding this comment

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

No blockers from me! 👍

}

func (s*MethodTestSuite)TestUsageEvents() {
s.Run("InsertUsageEvent",s.Mocked(func(db*dbmock.MockStore,faker*gofakeit.Faker,check*expects) {
Copy link
Member

Choose a reason for hiding this comment

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

Mocked! Nice! Been slowly converting them all 👍

deansheather reacted with heart emoji
Comment on lines +3 to +6
-- We use a TEXT column with a CHECK constraint rather than an enum because of
-- the limitations with adding new values to an enum and using them in the
-- same transaction.
event_typeTEXTNOT NULLCONSTRAINT usage_event_type_checkCHECK (event_typeIN ('dc_managed_agents_v1')),
Copy link
Member

Choose a reason for hiding this comment

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

Adding enum values is actually easy now:

ALTERTYPE notification_method ADD VALUE IF NOT EXISTS'inbox';

Removing them though is a problem:

-- The migration is about an enum value change
-- As we can not remove a value from an enum, we can let the down migration empty
-- In order to avoid any failure, we use ADD VALUE IF NOT EXISTS to add the value

(Although we never run down migrations so....)


Making it an enum generates the proper Golang enum

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Spike asked me to not do this in a prior comment because you can't add a value and then reference it in the same transaction unless you're on pg 17. We run all migrations in a single transaction (for good reason, to avoid partial upgrades), which means we can never reference enum types in future transactions.

Comment on lines +59 to +61
-- Note that this selects from the CTE, not the original table. The CTE is named
-- the same as the original table to trick sqlc into reusing the existing struct
-- for the table.
Copy link
Member

Choose a reason for hiding this comment

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

👍 Good trick

Comment on lines +74 to +86
SELECT
UNNEST(@ids::text[])AS id,
UNNEST(@failure_messages::text[])AS failure_message,
UNNEST(@set_published_ats::boolean[])AS set_published_at
) input
WHERE
input.id=usage_events.id
-- If the number of ids, failure messages, and set published ats are not the
-- same, do not do anything. Unfortunately you can't really throw from a
-- query without writing a function or doing some jank like dividing by
-- zero, so this is the best we can do.
AND cardinality(@ids::text[])= cardinality(@failure_messages::text[])
AND cardinality(@ids::text[])= cardinality(@set_published_ats::boolean[]);
Copy link
Member

Choose a reason for hiding this comment

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

Yea, if we ever switch to PGX, it has batch operations:https://docs.sqlc.dev/en/latest/reference/changelog.html#batch-operation-improvements

Then we get type safety and the inputs are[]struct{ /* ... Fields ... */}

deansheather reacted with eyes emoji
Versionuint64`json:"version"`
FeaturesFeatures`json:"features"`
RequireTelemetrybool`json:"require_telemetry,omitempty"`
PublishUsageDatabool`json:"publish_usage_data,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Interesting this is not an entitlement?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It's not really a feature, rather a flag to send usage data (which will always get collected in enterprise builds) to a server. So it makes sense that it goes whereRequireTelemetry goes since they're very similar.

@deansheatherdeansheatherforce-pushed the07-30-chore_add_usage_tracking_package branch fromdca0890 to2529c80CompareAugust 15, 2025 15:19
@deansheatherdeansheather merged commita25d856 intomainAug 15, 2025
50 of 53 checks passed
@deansheatherGraphite App
Copy link
MemberAuthor

Merge activity

@deansheatherdeansheather deleted the 07-30-chore_add_usage_tracking_package branchAugust 15, 2025 15:31
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 15, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@EmyrkEmyrkEmyrk left review comments

@spikecurtisspikecurtisspikecurtis approved these changes

Assignees

@deansheatherdeansheather

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@deansheather@johnstcn@spikecurtis@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp