Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7a35e0

Browse files
authored
chore: add workspace proxies to telemetry (#8963)
1 parent 3c52b01 commit f7a35e0

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

coderd/telemetry/telemetry.go

+37-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"golang.org/x/xerrors"
2323

2424
"cdr.dev/slog"
25-
2625
"github.com/coder/coder/buildinfo"
2726
"github.com/coder/coder/coderd/database"
2827
)
@@ -460,6 +459,17 @@ func (r *remoteReporter) createSnapshot() (*Snapshot, error) {
460459
}
461460
return nil
462461
})
462+
eg.Go(func() error {
463+
proxies, err := r.options.Database.GetWorkspaceProxies(ctx)
464+
if err != nil {
465+
return xerrors.Errorf("get workspace proxies: %w", err)
466+
}
467+
snapshot.WorkspaceProxies = make([]WorkspaceProxy, 0, len(proxies))
468+
for _, proxy := range proxies {
469+
snapshot.WorkspaceProxies = append(snapshot.WorkspaceProxies, ConvertWorkspaceProxy(proxy))
470+
}
471+
return nil
472+
})
463473

464474
err := eg.Wait()
465475
if err != nil {
@@ -665,6 +675,19 @@ func ConvertLicense(license database.License) License {
665675
}
666676
}
667677

678+
// ConvertWorkspaceProxy anonymizes a workspace proxy.
679+
func ConvertWorkspaceProxy(proxy database.WorkspaceProxy) WorkspaceProxy {
680+
return WorkspaceProxy{
681+
ID: proxy.ID,
682+
Name: proxy.Name,
683+
DisplayName: proxy.DisplayName,
684+
DerpEnabled: proxy.DerpEnabled,
685+
DerpOnly: proxy.DerpOnly,
686+
CreatedAt: proxy.CreatedAt,
687+
UpdatedAt: proxy.UpdatedAt,
688+
}
689+
}
690+
668691
// Snapshot represents a point-in-time anonymized database dump.
669692
// Data is aggregated by latest on the server-side, so partial data
670693
// can be sent without issue.
@@ -684,6 +707,7 @@ type Snapshot struct {
684707
WorkspaceBuilds []WorkspaceBuild `json:"workspace_build"`
685708
WorkspaceResources []WorkspaceResource `json:"workspace_resources"`
686709
WorkspaceResourceMetadata []WorkspaceResourceMetadata `json:"workspace_resource_metadata"`
710+
WorkspaceProxies []WorkspaceProxy `json:"workspace_proxies"`
687711
CLIInvocations []CLIInvocation `json:"cli_invocations"`
688712
}
689713

@@ -872,6 +896,18 @@ type CLIInvocation struct {
872896
InvokedAt time.Time `json:"invoked_at"`
873897
}
874898

899+
type WorkspaceProxy struct {
900+
ID uuid.UUID `json:"id"`
901+
Name string `json:"name"`
902+
DisplayName string `json:"display_name"`
903+
// No URLs since we don't send deployment URL.
904+
DerpEnabled bool `json:"derp_enabled"`
905+
DerpOnly bool `json:"derp_only"`
906+
// No Status since it may contain sensitive information.
907+
CreatedAt time.Time `json:"created_at"`
908+
UpdatedAt time.Time `json:"updated_at"`
909+
}
910+
875911
type noopReporter struct{}
876912

877913
func (*noopReporter) Report(_ *Snapshot) {}

coderd/telemetry/telemetry_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func TestTelemetry(t *testing.T) {
8181
UUID: uuid.New(),
8282
})
8383
assert.NoError(t, err)
84+
_, _ = dbgen.WorkspaceProxy(t, db, database.WorkspaceProxy{})
85+
8486
_, snapshot := collectSnapshot(t, db)
8587
require.Len(t, snapshot.ProvisionerJobs, 1)
8688
require.Len(t, snapshot.Licenses, 1)
@@ -93,6 +95,7 @@ func TestTelemetry(t *testing.T) {
9395
require.Len(t, snapshot.WorkspaceBuilds, 1)
9496
require.Len(t, snapshot.WorkspaceResources, 1)
9597
require.Len(t, snapshot.WorkspaceAgentStats, 1)
98+
require.Len(t, snapshot.WorkspaceProxies, 1)
9699

97100
wsa := snapshot.WorkspaceAgents[0]
98101
require.Equal(t, string(database.WorkspaceAgentSubsystemEnvbox), wsa.Subsystem)

enterprise/coderd/workspaceproxy.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/coder/coder/coderd/httpapi"
2424
"github.com/coder/coder/coderd/httpmw"
2525
"github.com/coder/coder/coderd/rbac"
26+
"github.com/coder/coder/coderd/telemetry"
2627
"github.com/coder/coder/coderd/workspaceapps"
2728
"github.com/coder/coder/codersdk"
2829
"github.com/coder/coder/cryptorand"
@@ -369,6 +370,10 @@ func (api *API) postWorkspaceProxy(rw http.ResponseWriter, r *http.Request) {
369370
return
370371
}
371372

373+
api.Telemetry.Report(&telemetry.Snapshot{
374+
WorkspaceProxies: []telemetry.WorkspaceProxy{telemetry.ConvertWorkspaceProxy(proxy)},
375+
})
376+
372377
aReq.New = proxy
373378
httpapi.Write(ctx, rw, http.StatusCreated, codersdk.UpdateWorkspaceProxyResponse{
374379
Proxy: convertProxy(proxy, proxyhealth.ProxyStatus{

0 commit comments

Comments
 (0)