diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index 47597723a7f1d..b5a7e8a4bd0c0 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -8493,19 +8493,20 @@ func (q *sqlQuerier) GetChatMessagesForPromptByChatID(ctx context.Context, chatI } const getChatModelConfigsForTelemetry = `-- name: GetChatModelConfigsForTelemetry :many -SELECT cmc.id, ap.type::text AS provider, cmc.model, cmc.context_limit, cmc.enabled, cmc.is_default +SELECT cmc.id, ap.type::text AS provider, cmc.model, cmc.context_limit, cmc.enabled, cmc.is_default, cmc.organization_id FROM chat_model_configs cmc JOIN ai_providers ap ON ap.id = cmc.ai_provider_id WHERE cmc.deleted = false ` type GetChatModelConfigsForTelemetryRow struct { - ID uuid.UUID `db:"id" json:"id"` - Provider string `db:"provider" json:"provider"` - Model string `db:"model" json:"model"` - ContextLimit int64 `db:"context_limit" json:"context_limit"` - Enabled bool `db:"enabled" json:"enabled"` - IsDefault bool `db:"is_default" json:"is_default"` + ID uuid.UUID `db:"id" json:"id"` + Provider string `db:"provider" json:"provider"` + Model string `db:"model" json:"model"` + ContextLimit int64 `db:"context_limit" json:"context_limit"` + Enabled bool `db:"enabled" json:"enabled"` + IsDefault bool `db:"is_default" json:"is_default"` + OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"` } // Returns all model configurations for telemetry snapshot collection. @@ -8526,6 +8527,7 @@ func (q *sqlQuerier) GetChatModelConfigsForTelemetry(ctx context.Context) ([]Get &i.ContextLimit, &i.Enabled, &i.IsDefault, + &i.OrganizationID, ); err != nil { return nil, err } diff --git a/coderd/database/queries/chats.sql b/coderd/database/queries/chats.sql index 290e0c17f9dc9..5f3d9aa4cac44 100644 --- a/coderd/database/queries/chats.sql +++ b/coderd/database/queries/chats.sql @@ -2291,7 +2291,7 @@ GROUP BY cm.chat_id; -- name: GetChatModelConfigsForTelemetry :many -- Returns all model configurations for telemetry snapshot collection. -- deleted = false guarantees ai_provider_id is non-null, so INNER JOIN is safe. -SELECT cmc.id, ap.type::text AS provider, cmc.model, cmc.context_limit, cmc.enabled, cmc.is_default +SELECT cmc.id, ap.type::text AS provider, cmc.model, cmc.context_limit, cmc.enabled, cmc.is_default, cmc.organization_id FROM chat_model_configs cmc JOIN ai_providers ap ON ap.id = cmc.ai_provider_id WHERE cmc.deleted = false; diff --git a/coderd/telemetry/telemetry.go b/coderd/telemetry/telemetry.go index 28e69a248b342..f35873a98c2f6 100644 --- a/coderd/telemetry/telemetry.go +++ b/coderd/telemetry/telemetry.go @@ -2318,12 +2318,13 @@ func ConvertChatMessageSummary(dbRow database.GetChatMessageSummariesPerChatRow) // telemetry ChatModelConfig. func ConvertChatModelConfig(dbRow database.GetChatModelConfigsForTelemetryRow) ChatModelConfig { return ChatModelConfig{ - ID: dbRow.ID, - Provider: dbRow.Provider, - Model: dbRow.Model, - ContextLimit: dbRow.ContextLimit, - Enabled: dbRow.Enabled, - IsDefault: dbRow.IsDefault, + ID: dbRow.ID, + OrganizationID: dbRow.OrganizationID, + Provider: dbRow.Provider, + Model: dbRow.Model, + ContextLimit: dbRow.ContextLimit, + Enabled: dbRow.Enabled, + IsDefault: dbRow.IsDefault, } } @@ -2611,12 +2612,13 @@ type ChatMessageSummary struct { // ChatModelConfig contains model configuration metadata for // telemetry. Sensitive fields like API keys are excluded. type ChatModelConfig struct { - ID uuid.UUID `json:"id"` - Provider string `json:"provider"` - Model string `json:"model"` - ContextLimit int64 `json:"context_limit"` - Enabled bool `json:"enabled"` - IsDefault bool `json:"is_default"` + ID uuid.UUID `json:"id"` + OrganizationID uuid.UUID `json:"organization_id"` + Provider string `json:"provider"` + Model string `json:"model"` + ContextLimit int64 `json:"context_limit"` + Enabled bool `json:"enabled"` + IsDefault bool `json:"is_default"` } // ChatDiffStatusSummary contains aggregate PR counts across all diff --git a/coderd/telemetry/telemetry_test.go b/coderd/telemetry/telemetry_test.go index 875882388f458..8be5f66559cf0 100644 --- a/coderd/telemetry/telemetry_test.go +++ b/coderd/telemetry/telemetry_test.go @@ -1935,6 +1935,7 @@ func TestChatsTelemetry(t *testing.T) { cfg1, ok := configMap[modelCfg.ID] require.True(t, ok) + assert.Equal(t, org.ID, cfg1.OrganizationID) assert.Equal(t, "anthropic", cfg1.Provider) assert.Equal(t, "claude-sonnet-4-20250514", cfg1.Model) assert.Equal(t, int64(200000), cfg1.ContextLimit) @@ -1943,6 +1944,7 @@ func TestChatsTelemetry(t *testing.T) { cfg2, ok := configMap[modelCfg2.ID] require.True(t, ok) + assert.Equal(t, org.ID, cfg2.OrganizationID) assert.Equal(t, "openai", cfg2.Provider) assert.Equal(t, "gpt-4o", cfg2.Model) assert.Equal(t, int64(128000), cfg2.ContextLimit)