mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add flag to disable template insights (#20940)
Closes #20399 To summarize the original commit messages: - Do not log stats to the database. - Return errors on the insight endpoints. - Update the frontend to show those errors. - Also fixes an issue with getting the user status count via codersdk, since I added a test to ensure it was not disabled by this flag and it was sending the wrong payload.
This commit is contained in:
@@ -511,6 +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"`
|
||||
|
||||
Config serpent.YAMLConfigPath `json:"config,omitempty" typescript:",notnull"`
|
||||
WriteConfig serpent.Bool `json:"write_config,omitempty" typescript:",notnull"`
|
||||
@@ -610,6 +611,10 @@ type DERPConfig struct {
|
||||
Path serpent.String `json:"path" typescript:",notnull"`
|
||||
}
|
||||
|
||||
type TemplateInsightsConfig struct {
|
||||
Enable serpent.Bool `json:"enable" typescript:",notnull"`
|
||||
}
|
||||
|
||||
type PrometheusConfig struct {
|
||||
Enable serpent.Bool `json:"enable" typescript:",notnull"`
|
||||
Address serpent.HostPort `json:"address" typescript:",notnull"`
|
||||
@@ -1080,6 +1085,11 @@ func (c *DeploymentValues) Options() serpent.OptionSet {
|
||||
Name: "pprof",
|
||||
YAML: "pprof",
|
||||
}
|
||||
deploymentGroupIntrospectionTemplateInsights = serpent.Group{
|
||||
Parent: &deploymentGroupIntrospection,
|
||||
Name: "Template Insights",
|
||||
YAML: "templateInsights",
|
||||
}
|
||||
deploymentGroupIntrospectionPrometheus = serpent.Group{
|
||||
Parent: &deploymentGroupIntrospection,
|
||||
Name: "Prometheus",
|
||||
@@ -1701,6 +1711,16 @@ func (c *DeploymentValues) Options() serpent.OptionSet {
|
||||
Group: &deploymentGroupNetworkingDERP,
|
||||
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",
|
||||
Default: "true",
|
||||
Value: &c.TemplateInsights.Enable,
|
||||
Group: &deploymentGroupIntrospectionTemplateInsights,
|
||||
YAML: "enable",
|
||||
},
|
||||
// TODO: support Git Auth settings.
|
||||
// Prometheus settings
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -293,12 +294,14 @@ type UserStatusChangeCount struct {
|
||||
}
|
||||
|
||||
type GetUserStatusCountsRequest struct {
|
||||
Offset time.Time `json:"offset" format:"date-time"`
|
||||
// Timezone offset in hours. Use 0 for UTC, and TimezoneOffsetHour(time.Local)
|
||||
// for the local timezone.
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
func (c *Client) GetUserStatusCounts(ctx context.Context, req GetUserStatusCountsRequest) (GetUserStatusCountsResponse, error) {
|
||||
qp := url.Values{}
|
||||
qp.Add("offset", req.Offset.Format(insightsTimeLayout))
|
||||
qp.Add("tz_offset", strconv.Itoa(req.Offset))
|
||||
|
||||
reqURL := fmt.Sprintf("/api/v2/insights/user-status-counts?%s", qp.Encode())
|
||||
resp, err := c.Request(ctx, http.MethodGet, reqURL, nil)
|
||||
|
||||
Reference in New Issue
Block a user