From 4a97df3768eee06e9ea8eb5fa408eae0932e3778 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 5 Jan 2026 11:44:06 -0900 Subject: [PATCH] chore: rename flag to disable template insights (#21329) Because this affects more than just the template insights page (specifically it also affects the deployment stats endpoint which is shown on bottom bar and Prometheus), the group is being renamed generically to just "stats collection". In the future if we need to affect the other stats we can put those options here. Then, because this change only affects a portion of stats, specifically usage stats like connection and application time, bytes sent, etc, add a new sub-group called "usage stats". Then finally add back the "enable" flag. This also gives us a place to one day place an "anonymize" flag if we need to go that route. --- cli/testdata/coder_server_--help.golden | 16 +++-- cli/testdata/server-config.yaml.golden | 18 +++--- coderd/apidoc/docs.go | 30 +++++---- coderd/apidoc/swagger.json | 30 +++++---- coderd/coderd.go | 5 +- coderd/insights_test.go | 6 +- codersdk/deployment.go | 33 ++++++---- docs/reference/api/general.md | 8 ++- docs/reference/api/schemas.md | 62 ++++++++++++------- docs/reference/cli/server.md | 16 ++--- .../cli/testdata/coder_server_--help.golden | 16 +++-- site/src/api/typesGenerated.ts | 17 +++-- 12 files changed, 154 insertions(+), 103 deletions(-) diff --git a/cli/testdata/coder_server_--help.golden b/cli/testdata/coder_server_--help.golden index 13900f7687..5486f51b0a 100644 --- a/cli/testdata/coder_server_--help.golden +++ b/cli/testdata/coder_server_--help.golden @@ -291,15 +291,13 @@ INTROSPECTION / PROMETHEUS OPTIONS: --prometheus-enable bool, $CODER_PROMETHEUS_ENABLE Serve prometheus metrics on the address defined by prometheus address. -INTROSPECTION / TEMPLATE INSIGHTS OPTIONS: - --template-insights-enable bool, $CODER_TEMPLATE_INSIGHTS_ENABLE (default: true) - Enable the collection and display of template insights along with the - associated API endpoints. This will also enable aggregating these - insights into daily active users, application usage, and transmission - rates for overall deployment stats. When disabled, these values will - be zero, which will also affect what the bottom deployment overview - bar displays. Disabling will also prevent Prometheus collection of - these values. +INTROSPECTION / STATS COLLECTION / USAGE STATS OPTIONS: + --stats-collection-usage-stats-enable bool, $CODER_STATS_COLLECTION_USAGE_STATS_ENABLE (default: true) + Enable the collection of application and workspace usage along with + the associated API endpoints and the template insights page. Disabling + this will also disable traffic and connection insights in the + deployment stats shown to admins in the bottom bar of the Coder UI, + and will prevent Prometheus collection of these values. INTROSPECTION / TRACING OPTIONS: --trace-logs bool, $CODER_TRACE_LOGS diff --git a/cli/testdata/server-config.yaml.golden b/cli/testdata/server-config.yaml.golden index 63a28ff3b9..deca918036 100644 --- a/cli/testdata/server-config.yaml.golden +++ b/cli/testdata/server-config.yaml.golden @@ -191,15 +191,15 @@ autobuildPollInterval: 1m0s # (default: 1m0s, type: duration) jobHangDetectorInterval: 1m0s introspection: - templateInsights: - # Enable the collection and display of template insights along with the associated - # API endpoints. This will also enable aggregating these insights into daily - # active users, application usage, and transmission rates for overall deployment - # stats. When disabled, these values will be zero, which will also affect what the - # bottom deployment overview bar displays. Disabling will also prevent Prometheus - # collection of these values. - # (default: true, type: bool) - enable: true + statsCollection: + usageStats: + # Enable the collection of application and workspace usage along with the + # associated API endpoints and the template insights page. Disabling this will + # also disable traffic and connection insights in the deployment stats shown to + # admins in the bottom bar of the Coder UI, and will prevent Prometheus collection + # of these values. + # (default: true, type: bool) + enable: true prometheus: # Serve prometheus metrics on the address defined by prometheus address. # (default: , type: bool) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index fcee015a12..7259e99990 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -14385,6 +14385,9 @@ const docTemplate = `{ "ssh_keygen_algorithm": { "type": "string" }, + "stats_collection": { + "$ref": "#/definitions/codersdk.StatsCollectionConfig" + }, "strict_transport_security": { "type": "integer" }, @@ -14403,9 +14406,6 @@ const docTemplate = `{ "telemetry": { "$ref": "#/definitions/codersdk.TelemetryConfig" }, - "template_insights": { - "$ref": "#/definitions/codersdk.TemplateInsightsConfig" - }, "terms_of_service_url": { "type": "string" }, @@ -18051,6 +18051,14 @@ const docTemplate = `{ } } }, + "codersdk.StatsCollectionConfig": { + "type": "object", + "properties": { + "usage_stats": { + "$ref": "#/definitions/codersdk.UsageStatsConfig" + } + } + }, "codersdk.SupportConfig": { "type": "object", "properties": { @@ -18706,14 +18714,6 @@ const docTemplate = `{ } } }, - "codersdk.TemplateInsightsConfig": { - "type": "object", - "properties": { - "enable": { - "type": "boolean" - } - } - }, "codersdk.TemplateInsightsIntervalReport": { "type": "object", "properties": { @@ -19659,6 +19659,14 @@ const docTemplate = `{ } } }, + "codersdk.UsageStatsConfig": { + "type": "object", + "properties": { + "enable": { + "type": "boolean" + } + } + }, "codersdk.User": { "type": "object", "required": [ diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index b3bc29d7bf..625c8a5273 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -12967,6 +12967,9 @@ "ssh_keygen_algorithm": { "type": "string" }, + "stats_collection": { + "$ref": "#/definitions/codersdk.StatsCollectionConfig" + }, "strict_transport_security": { "type": "integer" }, @@ -12985,9 +12988,6 @@ "telemetry": { "$ref": "#/definitions/codersdk.TelemetryConfig" }, - "template_insights": { - "$ref": "#/definitions/codersdk.TemplateInsightsConfig" - }, "terms_of_service_url": { "type": "string" }, @@ -16501,6 +16501,14 @@ } } }, + "codersdk.StatsCollectionConfig": { + "type": "object", + "properties": { + "usage_stats": { + "$ref": "#/definitions/codersdk.UsageStatsConfig" + } + } + }, "codersdk.SupportConfig": { "type": "object", "properties": { @@ -17134,14 +17142,6 @@ } } }, - "codersdk.TemplateInsightsConfig": { - "type": "object", - "properties": { - "enable": { - "type": "boolean" - } - } - }, "codersdk.TemplateInsightsIntervalReport": { "type": "object", "properties": { @@ -18030,6 +18030,14 @@ } } }, + "codersdk.UsageStatsConfig": { + "type": "object", + "properties": { + "enable": { + "type": "boolean" + } + } + }, "codersdk.User": { "type": "object", "required": ["created_at", "email", "id", "username"], diff --git a/coderd/coderd.go b/coderd/coderd.go index 5101800e4d..2d0c222dc6 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -776,7 +776,7 @@ func New(options *Options) *API { UsageTracker: options.WorkspaceUsageTracker, UpdateAgentMetricsFn: options.UpdateAgentMetrics, AppStatBatchSize: workspaceapps.DefaultStatsDBReporterBatchSize, - DisableDatabaseInserts: !options.DeploymentValues.TemplateInsights.Enable.Value(), + DisableDatabaseInserts: !options.DeploymentValues.StatsCollection.UsageStats.Enable.Value(), }) workspaceAppsLogger := options.Logger.Named("workspaceapps") if options.WorkspaceAppsStatsCollectorOptions.Logger == nil { @@ -1535,7 +1535,8 @@ func New(options *Options) *API { r.Use( func(next http.Handler) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - if !options.DeploymentValues.TemplateInsights.Enable.Value() { + // Template insights depend on the usage stats. + if !options.DeploymentValues.StatsCollection.UsageStats.Enable.Value() { httpapi.Write(context.Background(), rw, http.StatusNotFound, codersdk.Response{ Message: "Not Found.", Detail: "Template insights are disabled.", diff --git a/coderd/insights_test.go b/coderd/insights_test.go index 4fef80df29..f2db023ea1 100644 --- a/coderd/insights_test.go +++ b/coderd/insights_test.go @@ -2401,8 +2401,10 @@ func TestGenericInsights_Disabled(t *testing.T) { dbrollup.WithInterval(time.Millisecond*100), ), DeploymentValues: coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) { - dv.TemplateInsights = codersdk.TemplateInsightsConfig{ - Enable: false, + dv.StatsCollection = codersdk.StatsCollectionConfig{ + UsageStats: codersdk.UsageStatsConfig{ + Enable: false, + }, } }), }) diff --git a/codersdk/deployment.go b/codersdk/deployment.go index 218cf94eca..87f5cd06f1 100644 --- a/codersdk/deployment.go +++ b/codersdk/deployment.go @@ -511,7 +511,7 @@ type DeploymentValues struct { Prebuilds PrebuildsConfig `json:"workspace_prebuilds,omitempty" typescript:",notnull"` HideAITasks serpent.Bool `json:"hide_ai_tasks,omitempty" typescript:",notnull"` AI AIConfig `json:"ai,omitempty"` - TemplateInsights TemplateInsightsConfig `json:"template_insights,omitempty" typescript:",notnull"` + StatsCollection StatsCollectionConfig `json:"stats_collection,omitempty" typescript:",notnull"` Config serpent.YAMLConfigPath `json:"config,omitempty" typescript:",notnull"` WriteConfig serpent.Bool `json:"write_config,omitempty" typescript:",notnull"` @@ -611,10 +611,14 @@ type DERPConfig struct { Path serpent.String `json:"path" typescript:",notnull"` } -type TemplateInsightsConfig struct { +type UsageStatsConfig struct { Enable serpent.Bool `json:"enable" typescript:",notnull"` } +type StatsCollectionConfig struct { + UsageStats UsageStatsConfig `json:"usage_stats" tyescript:",notnull"` +} + type PrometheusConfig struct { Enable serpent.Bool `json:"enable" typescript:",notnull"` Address serpent.HostPort `json:"address" typescript:",notnull"` @@ -1080,7 +1084,7 @@ func (c *DeploymentValues) Options() serpent.OptionSet { } deploymentGroupIntrospection = serpent.Group{ Name: "Introspection", - Description: `Configure logging, tracing, and metrics exporting.`, + Description: `Configure logging, tracing, stat collection, and metrics exporting.`, YAML: "introspection", } deploymentGroupIntrospectionPPROF = serpent.Group{ @@ -1088,10 +1092,15 @@ func (c *DeploymentValues) Options() serpent.OptionSet { Name: "pprof", YAML: "pprof", } - deploymentGroupIntrospectionTemplateInsights = serpent.Group{ + deploymentGroupIntrospectionStatsCollection = serpent.Group{ Parent: &deploymentGroupIntrospection, - Name: "Template Insights", - YAML: "templateInsights", + Name: "Stats Collection", + YAML: "statsCollection", + } + deploymentGroupIntrospectionStatsCollectionUsageStats = serpent.Group{ + Parent: &deploymentGroupIntrospectionStatsCollection, + Name: "Usage Stats", + YAML: "usageStats", } deploymentGroupIntrospectionPrometheus = serpent.Group{ Parent: &deploymentGroupIntrospection, @@ -1718,13 +1727,13 @@ func (c *DeploymentValues) Options() serpent.OptionSet { YAML: "configPath", }, { - Name: "Enable Template Insights", - Description: "Enable the collection and display of template insights along with the associated API endpoints. This will also enable aggregating these insights into daily active users, application usage, and transmission rates for overall deployment stats. When disabled, these values will be zero, which will also affect what the bottom deployment overview bar displays. Disabling will also prevent Prometheus collection of these values.", - Flag: "template-insights-enable", - Env: "CODER_TEMPLATE_INSIGHTS_ENABLE", + Name: "Stats Collection Usage Stats Enable", + Description: "Enable the collection of application and workspace usage along with the associated API endpoints and the template insights page. Disabling this will also disable traffic and connection insights in the deployment stats shown to admins in the bottom bar of the Coder UI, and will prevent Prometheus collection of these values.", + Flag: "stats-collection-usage-stats-enable", + Env: "CODER_STATS_COLLECTION_USAGE_STATS_ENABLE", Default: "true", - Value: &c.TemplateInsights.Enable, - Group: &deploymentGroupIntrospectionTemplateInsights, + Value: &c.StatsCollection.UsageStats.Enable, + Group: &deploymentGroupIntrospectionStatsCollectionUsageStats, YAML: "enable", }, // TODO: support Git Auth settings. diff --git a/docs/reference/api/general.md b/docs/reference/api/general.md index 83dae06688..2358aaf842 100644 --- a/docs/reference/api/general.md +++ b/docs/reference/api/general.md @@ -491,6 +491,11 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \ "refresh_default_duration": 0 }, "ssh_keygen_algorithm": "string", + "stats_collection": { + "usage_stats": { + "enable": true + } + }, "strict_transport_security": 0, "strict_transport_security_options": [ "string" @@ -527,9 +532,6 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \ "user": {} } }, - "template_insights": { - "enable": true - }, "terms_of_service_url": "string", "tls": { "address": { diff --git a/docs/reference/api/schemas.md b/docs/reference/api/schemas.md index 494b2d30ac..d893741744 100644 --- a/docs/reference/api/schemas.md +++ b/docs/reference/api/schemas.md @@ -2951,6 +2951,11 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o "refresh_default_duration": 0 }, "ssh_keygen_algorithm": "string", + "stats_collection": { + "usage_stats": { + "enable": true + } + }, "strict_transport_security": 0, "strict_transport_security_options": [ "string" @@ -2987,9 +2992,6 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o "user": {} } }, - "template_insights": { - "enable": true - }, "terms_of_service_url": "string", "tls": { "address": { @@ -3488,6 +3490,11 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o "refresh_default_duration": 0 }, "ssh_keygen_algorithm": "string", + "stats_collection": { + "usage_stats": { + "enable": true + } + }, "strict_transport_security": 0, "strict_transport_security_options": [ "string" @@ -3524,9 +3531,6 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o "user": {} } }, - "template_insights": { - "enable": true - }, "terms_of_service_url": "string", "tls": { "address": { @@ -3631,12 +3635,12 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o | `scim_api_key` | string | false | | | | `session_lifetime` | [codersdk.SessionLifetime](#codersdksessionlifetime) | false | | | | `ssh_keygen_algorithm` | string | false | | | +| `stats_collection` | [codersdk.StatsCollectionConfig](#codersdkstatscollectionconfig) | false | | | | `strict_transport_security` | integer | false | | | | `strict_transport_security_options` | array of string | false | | | | `support` | [codersdk.SupportConfig](#codersdksupportconfig) | false | | | | `swagger` | [codersdk.SwaggerConfig](#codersdkswaggerconfig) | false | | | | `telemetry` | [codersdk.TelemetryConfig](#codersdktelemetryconfig) | false | | | -| `template_insights` | [codersdk.TemplateInsightsConfig](#codersdktemplateinsightsconfig) | false | | | | `terms_of_service_url` | string | false | | | | `tls` | [codersdk.TLSConfig](#codersdktlsconfig) | false | | | | `trace` | [codersdk.TraceConfig](#codersdktraceconfig) | false | | | @@ -7445,6 +7449,22 @@ Only certain features set these fields: - FeatureManagedAgentLimit| | `name` | string | false | | | | `organization_id` | string | false | | | +## codersdk.StatsCollectionConfig + +```json +{ + "usage_stats": { + "enable": true + } +} +``` + +### Properties + +| Name | Type | Required | Restrictions | Description | +|---------------|--------------------------------------------------------|----------|--------------|-------------| +| `usage_stats` | [codersdk.UsageStatsConfig](#codersdkusagestatsconfig) | false | | | + ## codersdk.SupportConfig ```json @@ -8177,20 +8197,6 @@ Restarts will only happen on weekdays in this list on weeks which line up with W |----------|----------------| | `role` | `admin`, `use` | -## codersdk.TemplateInsightsConfig - -```json -{ - "enable": true -} -``` - -### Properties - -| Name | Type | Required | Restrictions | Description | -|----------|---------|----------|--------------|-------------| -| `enable` | boolean | false | | | - ## codersdk.TemplateInsightsIntervalReport ```json @@ -9260,6 +9266,20 @@ If the schedule is empty, the user will be updated to use the default schedule.| | `issued_at` | string | false | | | | `start` | string | false | | | +## codersdk.UsageStatsConfig + +```json +{ + "enable": true +} +``` + +### Properties + +| Name | Type | Required | Restrictions | Description | +|----------|---------|----------|--------------|-------------| +| `enable` | boolean | false | | | + ## codersdk.User ```json diff --git a/docs/reference/cli/server.md b/docs/reference/cli/server.md index d3ea11879d..e41caf4af8 100644 --- a/docs/reference/cli/server.md +++ b/docs/reference/cli/server.md @@ -269,16 +269,16 @@ URL to fetch a DERP mapping on startup. See: https://tailscale.com/kb/1118/custo Path to read a DERP mapping from. See: https://tailscale.com/kb/1118/custom-derp-servers/. -### --template-insights-enable +### --stats-collection-usage-stats-enable -| | | -|-------------|----------------------------------------------------| -| Type | bool | -| Environment | $CODER_TEMPLATE_INSIGHTS_ENABLE | -| YAML | introspection.templateInsights.enable | -| Default | true | +| | | +|-------------|--------------------------------------------------------------| +| Type | bool | +| Environment | $CODER_STATS_COLLECTION_USAGE_STATS_ENABLE | +| YAML | introspection.statsCollection.usageStats.enable | +| Default | true | -Enable the collection and display of template insights along with the associated API endpoints. This will also enable aggregating these insights into daily active users, application usage, and transmission rates for overall deployment stats. When disabled, these values will be zero, which will also affect what the bottom deployment overview bar displays. Disabling will also prevent Prometheus collection of these values. +Enable the collection of application and workspace usage along with the associated API endpoints and the template insights page. Disabling this will also disable traffic and connection insights in the deployment stats shown to admins in the bottom bar of the Coder UI, and will prevent Prometheus collection of these values. ### --prometheus-enable diff --git a/enterprise/cli/testdata/coder_server_--help.golden b/enterprise/cli/testdata/coder_server_--help.golden index 7e09efc337..3b8393a286 100644 --- a/enterprise/cli/testdata/coder_server_--help.golden +++ b/enterprise/cli/testdata/coder_server_--help.golden @@ -292,15 +292,13 @@ INTROSPECTION / PROMETHEUS OPTIONS: --prometheus-enable bool, $CODER_PROMETHEUS_ENABLE Serve prometheus metrics on the address defined by prometheus address. -INTROSPECTION / TEMPLATE INSIGHTS OPTIONS: - --template-insights-enable bool, $CODER_TEMPLATE_INSIGHTS_ENABLE (default: true) - Enable the collection and display of template insights along with the - associated API endpoints. This will also enable aggregating these - insights into daily active users, application usage, and transmission - rates for overall deployment stats. When disabled, these values will - be zero, which will also affect what the bottom deployment overview - bar displays. Disabling will also prevent Prometheus collection of - these values. +INTROSPECTION / STATS COLLECTION / USAGE STATS OPTIONS: + --stats-collection-usage-stats-enable bool, $CODER_STATS_COLLECTION_USAGE_STATS_ENABLE (default: true) + Enable the collection of application and workspace usage along with + the associated API endpoints and the template insights page. Disabling + this will also disable traffic and connection insights in the + deployment stats shown to admins in the bottom bar of the Coder UI, + and will prevent Prometheus collection of these values. INTROSPECTION / TRACING OPTIONS: --trace-logs bool, $CODER_TRACE_LOGS diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index f55bff3a3d..41f784c040 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1783,7 +1783,7 @@ export interface DeploymentValues { readonly workspace_prebuilds?: PrebuildsConfig; readonly hide_ai_tasks?: boolean; readonly ai?: AIConfig; - readonly template_insights?: TemplateInsightsConfig; + readonly stats_collection?: StatsCollectionConfig; readonly config?: string; readonly write_config?: boolean; /** @@ -4593,6 +4593,11 @@ export interface SlimRole { readonly organization_id?: string; } +// From codersdk/deployment.go +export interface StatsCollectionConfig { + readonly usage_stats: UsageStatsConfig; +} + // From codersdk/client.go /** * SubdomainAppSessionTokenCookie is the name of the cookie that stores an @@ -5105,11 +5110,6 @@ export interface TemplateGroup extends Group { readonly role: TemplateRole; } -// From codersdk/deployment.go -export interface TemplateInsightsConfig { - readonly enable: boolean; -} - // From codersdk/insights.go /** * TemplateInsightsIntervalReport is the report from the template insights @@ -5677,6 +5677,11 @@ export interface UsagePeriod { readonly end: string; } +// From codersdk/deployment.go +export interface UsageStatsConfig { + readonly enable: boolean; +} + // From codersdk/users.go /** * User represents a user in Coder.