mirror of
https://github.com/coder/coder.git
synced 2026-10-16 14:48:56 +08:00
Track individual applications across deployment statistics, Prometheus, telemetry, and the dashboard instead of exposing only fixed family totals. Preserve existing fields and gauges so current consumers can migrate without breaking. - Add per-app counts with normalized identifiers and registry-backed display names, families, and bundled icons. Unrecognized apps retain their identifiers. - Limit each statistics report to 64 distinct app names, combining excess names into an explicit overflow bucket. - Group dashboard connections by family, including an Other category, with alphabetical per-app tooltips and distinct loading and empty states. - Export app-keyed Prometheus counts separately from current family metadata, allowing queries to enrich historical counts without rewriting stored samples. - Document family queries with unknown fallback, deployment isolation, and replica handling, alongside collection behavior and migration guidance. - Include per-app counts in telemetry, update API schemas and documentation, and add regression coverage across collection, metrics, and dashboard behavior. Closes #27411
82 lines
3.2 KiB
Go
82 lines
3.2 KiB
Go
package coderd_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/coderd/coderdtest"
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/database/dbgen"
|
|
"github.com/coder/coder/v2/coderd/database/dbtestutil"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
"github.com/coder/coder/v2/testutil"
|
|
)
|
|
|
|
func TestDeploymentValues(t *testing.T) {
|
|
t.Parallel()
|
|
hi := "hi"
|
|
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
|
defer cancel()
|
|
cfg := coderdtest.DeploymentValues(t)
|
|
// values should be returned
|
|
cfg.BrowserOnly = true
|
|
// values should not be returned
|
|
cfg.OAuth2.Github.ClientSecret.Set(hi)
|
|
cfg.OIDC.ClientSecret.Set(hi)
|
|
cfg.OIDC.AuthURLParams.Set(`{"foo":"bar"}`)
|
|
cfg.OIDC.EmailField.Set("some_random_field_you_never_expected")
|
|
cfg.PostgresURL.Set(hi)
|
|
cfg.SCIMAPIKey.Set(hi)
|
|
cfg.ExternalTokenEncryptionKeys.Set("the_random_key_we_never_expected,an_other_key_we_never_unexpected")
|
|
cfg.Provisioner.DaemonPSK = "provisionersftw"
|
|
|
|
client := coderdtest.New(t, &coderdtest.Options{
|
|
DeploymentValues: cfg,
|
|
})
|
|
_ = coderdtest.CreateFirstUser(t, client)
|
|
scrubbed, err := client.DeploymentConfig(ctx)
|
|
require.NoError(t, err)
|
|
// ensure normal values pass through
|
|
require.EqualValues(t, true, scrubbed.Values.BrowserOnly.Value())
|
|
require.NotEmpty(t, cfg.OIDC.AuthURLParams)
|
|
require.EqualValues(t, cfg.OIDC.AuthURLParams, scrubbed.Values.OIDC.AuthURLParams)
|
|
require.NotEmpty(t, cfg.OIDC.EmailField)
|
|
require.EqualValues(t, cfg.OIDC.EmailField, scrubbed.Values.OIDC.EmailField)
|
|
// ensure secrets are removed
|
|
require.Empty(t, scrubbed.Values.OAuth2.Github.ClientSecret.Value())
|
|
require.Empty(t, scrubbed.Values.OIDC.ClientSecret.Value())
|
|
require.Empty(t, scrubbed.Values.PostgresURL.Value())
|
|
require.Empty(t, scrubbed.Values.SCIMAPIKey.Value())
|
|
require.Empty(t, scrubbed.Values.ExternalTokenEncryptionKeys.Value())
|
|
require.Empty(t, scrubbed.Values.Provisioner.DaemonPSK.Value())
|
|
}
|
|
|
|
func TestDeploymentStats(t *testing.T) {
|
|
t.Parallel()
|
|
ctx := testutil.Context(t, testutil.WaitLong)
|
|
db, _ := dbtestutil.NewDB(t)
|
|
dbgen.WorkspaceAgentStat(t, db, database.WorkspaceAgentStat{
|
|
ConnectionMedianLatencyMS: 10,
|
|
SessionCounts: dbgen.SessionCounts(t, map[string]int64{"vscode": 1, "cursor": 2, "future_ide": 3}),
|
|
})
|
|
client := coderdtest.New(t, &coderdtest.Options{Database: db})
|
|
_ = coderdtest.CreateFirstUser(t, client)
|
|
var stats codersdk.DeploymentStats
|
|
require.True(t, testutil.Eventually(ctx, t, func(tctx context.Context) bool {
|
|
var err error
|
|
stats, err = client.DeploymentStats(tctx)
|
|
return err == nil
|
|
}, testutil.IntervalMedium), "failed to get deployment stats in time")
|
|
// The legacy total folds both known names into VS Code.
|
|
require.Equal(t, codersdk.SessionCountDeploymentStats{
|
|
Apps: map[string]codersdk.SessionCountApp{
|
|
"vscode": {Count: 1, DisplayName: "VS Code", Icon: "/icon/code.svg", Family: codersdk.AppFamilyVSCode},
|
|
"cursor": {Count: 2, DisplayName: "Cursor", Icon: "/icon/cursor.svg", Family: codersdk.AppFamilyVSCode},
|
|
"future_ide": {Count: 3, DisplayName: "future_ide", Family: codersdk.AppFamilyUnknown},
|
|
},
|
|
VSCode: 3,
|
|
}, stats.SessionCount)
|
|
}
|