- Notifications
You must be signed in to change notification settings - Fork1k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
deansheather commentedJul 30, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This stack of pull requests is managed byGraphite. Learn more aboutstacking. |
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.
I have some non-blocking comments below but might need to take another pass.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
enterprise/coderd/usage/publisher.go Outdated
const ( | ||
CoderLicenseJWTHeader="Coder-License-JWT" | ||
tallymanURL="https://tallyman-ingress.coder.com" |
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.
I can see an argument for making this avar
so it's configurable at build time.
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.
If we do need that we can add it very easily in the future.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
Obligatory reminder to check migration number before merging!
Uh oh!
There was an error while loading.Please reload this page.
coderd/database/migrations/000353_create_usage_events_table.up.sql OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
coderd/database/migrations/000353_create_usage_events_table.up.sql OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
e376311
to82ea8e1
Compare
johnstcn left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
LGTM modulogen
failures
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.
No blockers from me! 👍
} | ||
func (s*MethodTestSuite)TestUsageEvents() { | ||
s.Run("InsertUsageEvent",s.Mocked(func(db*dbmock.MockStore,faker*gofakeit.Faker,check*expects) { |
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.
Mocked! Nice! Been slowly converting them all 👍
-- 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')), |
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.
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
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.
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.
-- 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. |
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.
👍 Good trick
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[]); |
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.
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 ... */}
Uh oh!
There was an error while loading.Please reload this page.
Versionuint64`json:"version"` | ||
FeaturesFeatures`json:"features"` | ||
RequireTelemetrybool`json:"require_telemetry,omitempty"` | ||
PublishUsageDatabool`json:"publish_usage_data,omitempty"` |
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.
Interesting this is not an entitlement?
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.
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.
Uh oh!
There was an error while loading.Please reload this page.
dca0890
to2529c80
Comparea25d856
intomainUh oh!
There was an error while loading.Please reload this page.
Merge activity
|
Uh oh!
There was an error while loading.Please reload this page.
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 AGPLenterprise/coderd/usage
: provides an interface for the "Publisher" as well as a Tallyman implementationRelates tocoder/internal#814