Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(coderd/telemetry): Move CLI telemetry to cli/telemetry
This change removes an indirect import of `coderd/database` from the
slim binary.

No size change (yet).

Ref: #9380
  • Loading branch information
mafredri committed Sep 4, 2023
commit 2019a5e96c84c64b0380bed73533e3cea773dd8e
8 changes: 4 additions & 4 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/config"
"github.com/coder/coder/v2/cli/gitauth"
"github.com/coder/coder/v2/coderd/telemetry"
"github.com/coder/coder/v2/cli/telemetry"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
)
Expand Down Expand Up @@ -467,17 +467,17 @@ func addTelemetryHeader(client *codersdk.Client, inv *clibase.Invocation) {
client.HTTPClient.Transport = transport
}

var topts []telemetry.CLIOption
var topts []telemetry.Option
for _, opt := range inv.Command.FullOptions() {
if opt.ValueSource == clibase.ValueSourceNone || opt.ValueSource == clibase.ValueSourceDefault {
continue
}
topts = append(topts, telemetry.CLIOption{
topts = append(topts, telemetry.Option{
Name: opt.Name,
ValueSource: string(opt.ValueSource),
})
}
ti := telemetry.CLIInvocation{
ti := telemetry.Invocation{
Command: inv.Command.FullName(),
Options: topts,
InvokedAt: time.Now(),
Expand Down
15 changes: 15 additions & 0 deletions cli/telemetry/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package telemetry

import "time"

type Option struct {
Name string `json:"name"`
ValueSource string `json:"value_source"`
}

type Invocation struct {
Command string `json:"command"`
Options []Option `json:"options"`
// InvokedAt is provided for deduplication purposes.
InvokedAt time.Time `json:"invoked_at"`
}
5 changes: 3 additions & 2 deletions coderd/httpmw/clitelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"tailscale.com/tstime/rate"

"cdr.dev/slog"
clitelemetry "github.com/coder/coder/v2/cli/telemetry"
"github.com/coder/coder/v2/coderd/telemetry"
"github.com/coder/coder/v2/codersdk"
)
Expand All @@ -30,7 +31,7 @@ func ReportCLITelemetry(log slog.Logger, rep telemetry.Reporter) func(http.Handl
//
// This approach just helps us reduce storage and ingest fees, and doesn't
// change the correctness.
queue = make(map[string]telemetry.CLIInvocation)
queue = make(map[string]clitelemetry.Invocation)
)

log = log.Named("cli-telemetry")
Expand All @@ -55,7 +56,7 @@ func ReportCLITelemetry(log slog.Logger, rep telemetry.Reporter) func(http.Handl
return
}

var inv telemetry.CLIInvocation
var inv clitelemetry.Invocation
err = json.Unmarshal(byt, &inv)
if err != nil {
log.Error(
Expand Down
15 changes: 2 additions & 13 deletions coderd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"cdr.dev/slog"
"github.com/coder/coder/v2/buildinfo"
clitelemetry "github.com/coder/coder/v2/cli/telemetry"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbtime"
)
Expand Down Expand Up @@ -714,7 +715,7 @@ type Snapshot struct {
WorkspaceResources []WorkspaceResource `json:"workspace_resources"`
WorkspaceResourceMetadata []WorkspaceResourceMetadata `json:"workspace_resource_metadata"`
WorkspaceProxies []WorkspaceProxy `json:"workspace_proxies"`
CLIInvocations []CLIInvocation `json:"cli_invocations"`
CLIInvocations []clitelemetry.Invocation `json:"cli_invocations"`
}

// Deployment contains information about the host running Coder.
Expand Down Expand Up @@ -890,18 +891,6 @@ type License struct {
UUID uuid.UUID `json:"uuid"`
}

type CLIOption struct {
Name string `json:"name"`
ValueSource string `json:"value_source"`
}

type CLIInvocation struct {
Command string `json:"command"`
Options []CLIOption `json:"options"`
// InvokedAt is provided for deduplication purposes.
InvokedAt time.Time `json:"invoked_at"`
}

type WorkspaceProxy struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Expand Down