telemetry

package
v2.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VersionHeader is sent in every telemetry request to
	// report the semantic version of Coder.
	VersionHeader = "X-Coder-Version"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID        string             `json:"id"`
	UserID    uuid.UUID          `json:"user_id"`
	CreatedAt time.Time          `json:"created_at"`
	LastUsed  time.Time          `json:"last_used"`
	LoginType database.LoginType `json:"login_type"`
	IPAddress net.IP             `json:"ip_address"`
}

func ConvertAPIKey

func ConvertAPIKey(apiKey database.APIKey) APIKey

ConvertAPIKey anonymizes an API key.

type DERPMap added in v2.14.0

type DERPMap struct {
	HomeParams DERPMapHomeParams `json:"home_params"`
	Regions    map[int64]DERPRegion
}

type DERPMapHomeParams added in v2.14.0

type DERPMapHomeParams struct {
	RegionScore map[int64]float64 `json:"region_score"`
}

type DERPNode added in v2.14.0

type DERPNode struct {
	Name             string `json:"name"`
	RegionID         int64  `json:"region_id"`
	HostName         string `json:"host_name"`
	CertName         string `json:"cert_name"`
	IPv4             string `json:"ipv4"`
	IPv6             string `json:"ipv6"`
	STUNPort         int32  `json:"stun_port"`
	STUNOnly         bool   `json:"stun_only"`
	DERPPort         int32  `json:"derp_port"`
	InsecureForTests bool   `json:"insecure_for_tests"`
	ForceHTTP        bool   `json:"force_http"`
	STUNTestIP       string `json:"stun_test_ip"`
	CanPort80        bool   `json:"can_port_80"`
}

type DERPRegion added in v2.14.0

type DERPRegion struct {
	RegionID      int64 `json:"region_id"`
	EmbeddedRelay bool  `json:"embedded_relay"`
	RegionCode    string
	RegionName    string
	Avoid         bool
	Nodes         []DERPNode `json:"nodes"`
}

type Deployment

type Deployment struct {
	ID              string                     `json:"id"`
	Architecture    string                     `json:"architecture"`
	BuiltinPostgres bool                       `json:"builtin_postgres"`
	Containerized   bool                       `json:"containerized"`
	Kubernetes      bool                       `json:"kubernetes"`
	Config          *codersdk.DeploymentValues `json:"config"`
	Tunnel          bool                       `json:"tunnel"`
	InstallSource   string                     `json:"install_source"`
	OSType          string                     `json:"os_type"`
	OSFamily        string                     `json:"os_family"`
	OSPlatform      string                     `json:"os_platform"`
	OSName          string                     `json:"os_name"`
	OSVersion       string                     `json:"os_version"`
	CPUCores        int                        `json:"cpu_cores"`
	MemoryTotal     uint64                     `json:"memory_total"`
	MachineID       string                     `json:"machine_id"`
	StartedAt       time.Time                  `json:"started_at"`
	ShutdownAt      *time.Time                 `json:"shutdown_at"`
}

Deployment contains information about the host running Coder.

type ExternalProvisioner added in v2.3.2

type ExternalProvisioner struct {
	ID           string            `json:"id"`
	Tags         map[string]string `json:"tags"`
	Provisioners []string          `json:"provisioners"`
	StartedAt    time.Time         `json:"started_at"`
	ShutdownAt   *time.Time        `json:"shutdown_at"`
}

func ConvertExternalProvisioner added in v2.3.2

func ConvertExternalProvisioner(id uuid.UUID, tags map[string]string, provisioners []database.ProvisionerType) ExternalProvisioner

type Group added in v2.13.0

type Group struct {
	ID             uuid.UUID            `json:"id"`
	Name           string               `json:"name"`
	OrganizationID uuid.UUID            `json:"organization_id"`
	AvatarURL      string               `json:"avatar_url"`
	QuotaAllowance int32                `json:"quota_allowance"`
	DisplayName    string               `json:"display_name"`
	Source         database.GroupSource `json:"source"`
}

func ConvertGroup added in v2.13.0

func ConvertGroup(group database.Group) Group

type GroupMember added in v2.13.0

type GroupMember struct {
	UserID  uuid.UUID `json:"user_id"`
	GroupID uuid.UUID `json:"group_id"`
}

func ConvertGroupMember added in v2.13.0

func ConvertGroupMember(member database.GroupMember) GroupMember

type License

type License struct {
	JWT        string    `json:"jwt"`
	UploadedAt time.Time `json:"uploaded_at"`
	Exp        time.Time `json:"exp"`
	UUID       uuid.UUID `json:"uuid"`
	// These two fields are set by decoding the JWT. If the signing keys aren't
	// passed in, these will always be nil.
	Email *string `json:"email"`
	Trial *bool   `json:"trial"`
}

func ConvertLicense

func ConvertLicense(license database.License) License

type ModuleSourceType added in v2.18.0

type ModuleSourceType string

ModuleSourceType is the type of source for a module. For reference, see https://developer.hashicorp.com/terraform/language/modules/sources

const (
	ModuleSourceTypeLocal           ModuleSourceType = "local"
	ModuleSourceTypeLocalAbs        ModuleSourceType = "local_absolute"
	ModuleSourceTypePublicRegistry  ModuleSourceType = "public_registry"
	ModuleSourceTypePrivateRegistry ModuleSourceType = "private_registry"
	ModuleSourceTypeCoderRegistry   ModuleSourceType = "coder_registry"
	ModuleSourceTypeGitHub          ModuleSourceType = "github"
	ModuleSourceTypeBitbucket       ModuleSourceType = "bitbucket"
	ModuleSourceTypeGit             ModuleSourceType = "git"
	ModuleSourceTypeMercurial       ModuleSourceType = "mercurial"
	ModuleSourceTypeHTTP            ModuleSourceType = "http"
	ModuleSourceTypeS3              ModuleSourceType = "s3"
	ModuleSourceTypeGCS             ModuleSourceType = "gcs"
	ModuleSourceTypeUnknown         ModuleSourceType = "unknown"
)

func GetModuleSourceType added in v2.18.0

func GetModuleSourceType(source string) ModuleSourceType

Terraform supports a variety of module source types, like:

  • local paths (./ or ../)
  • absolute local paths (/)
  • git URLs (git:: or git@)
  • http URLs
  • s3 URLs

and more!

See https://developer.hashicorp.com/terraform/language/modules/sources for an overview.

This function attempts to classify the source type of a module. It's imperfect, as checks that terraform actually does are pretty complicated. See e.g. https://github.com/hashicorp/go-getter/blob/842d6c379e5e70d23905b8f6b5a25a80290acb66/detect.go#L47 if you're interested in the complexity.

type Netcheck added in v2.14.0

type Netcheck struct {
	UDP         bool `json:"udp"`
	IPv6        bool `json:"ipv6"`
	IPv4        bool `json:"ipv4"`
	IPv6CanSend bool `json:"ipv6_can_send"`
	IPv4CanSend bool `json:"ipv4_can_send"`
	ICMPv4      bool `json:"icmpv4"`

	OSHasIPv6             *bool `json:"os_has_ipv6"`
	MappingVariesByDestIP *bool `json:"mapping_varies_by_dest_ip"`
	HairPinning           *bool `json:"hair_pinning"`
	UPnP                  *bool `json:"upnp"`
	PMP                   *bool `json:"pmp"`
	PCP                   *bool `json:"pcp"`

	PreferredDERP int64 `json:"preferred_derp"`

	RegionV4Latency map[int64]time.Duration `json:"region_v4_latency"`
	RegionV6Latency map[int64]time.Duration `json:"region_v6_latency"`

	GlobalV4 NetcheckIP `json:"global_v4"`
	GlobalV6 NetcheckIP `json:"global_v6"`
}

type NetcheckIP added in v2.14.0

type NetcheckIP struct {
	Hash   string               `json:"hash"`
	Fields NetworkEventIPFields `json:"fields"`
}

type NetworkEvent added in v2.14.0

type NetworkEvent struct {
	ID             uuid.UUID               `json:"id"`
	Time           time.Time               `json:"time"`
	Application    string                  `json:"application"`
	Status         string                  `json:"status"`      // connected, disconnected
	ClientType     string                  `json:"client_type"` // cli, agent, coderd, wsproxy
	ClientVersion  string                  `json:"client_version"`
	NodeIDSelf     uint64                  `json:"node_id_self"`
	NodeIDRemote   uint64                  `json:"node_id_remote"`
	P2PEndpoint    NetworkEventP2PEndpoint `json:"p2p_endpoint"`
	HomeDERP       int                     `json:"home_derp"`
	DERPMap        DERPMap                 `json:"derp_map"`
	LatestNetcheck Netcheck                `json:"latest_netcheck"`

	ConnectionAge   *time.Duration `json:"connection_age"`
	ConnectionSetup *time.Duration `json:"connection_setup"`
	P2PSetup        *time.Duration `json:"p2p_setup"`
	DERPLatency     *time.Duration `json:"derp_latency"`
	P2PLatency      *time.Duration `json:"p2p_latency"`
	ThroughputMbits *float32       `json:"throughput_mbits"`
}

NetworkEvent and all related structs come from tailnet.proto.

func NetworkEventFromProto added in v2.14.0

func NetworkEventFromProto(proto *tailnetproto.TelemetryEvent) (NetworkEvent, error)

type NetworkEventIPFields added in v2.14.0

type NetworkEventIPFields struct {
	Version int32  `json:"version"` // 4 or 6
	Class   string `json:"class"`   // public, private, link_local, unique_local, loopback
}

type NetworkEventP2PEndpoint added in v2.14.0

type NetworkEventP2PEndpoint struct {
	Hash   string               `json:"hash"`
	Port   int                  `json:"port"`
	Fields NetworkEventIPFields `json:"fields"`
}

type Options

type Options struct {
	Database database.Store
	Logger   slog.Logger
	// URL is an endpoint to direct telemetry towards!
	URL *url.URL

	DeploymentID     string
	DeploymentConfig *codersdk.DeploymentValues
	BuiltinPostgres  bool
	Tunnel           bool

	SnapshotFrequency time.Duration
	ParseLicenseJWT   func(lic *License) error
}

type ProvisionerJob

type ProvisionerJob struct {
	ID             uuid.UUID                   `json:"id"`
	OrganizationID uuid.UUID                   `json:"organization_id"`
	InitiatorID    uuid.UUID                   `json:"initiator_id"`
	CreatedAt      time.Time                   `json:"created_at"`
	UpdatedAt      time.Time                   `json:"updated_at"`
	StartedAt      *time.Time                  `json:"started_at,omitempty"`
	CanceledAt     *time.Time                  `json:"canceled_at,omitempty"`
	CompletedAt    *time.Time                  `json:"completed_at,omitempty"`
	Error          string                      `json:"error"`
	Type           database.ProvisionerJobType `json:"type"`
}

func ConvertProvisionerJob

func ConvertProvisionerJob(job database.ProvisionerJob) ProvisionerJob

ConvertProvisionerJob anonymizes a provisioner job.

type Reporter

type Reporter interface {
	// Report sends a snapshot to the telemetry server.
	// The contents of the snapshot can be a partial representation of the
	// database. For example, if a new user is added, a snapshot can
	// contain just that user entry.
	Report(snapshot *Snapshot)
	Enabled() bool
	Close()
}

Reporter sends data to the telemetry server.

func New

func New(options Options) (Reporter, error)

New constructs a reporter for telemetry data. Duplicate data will be sent, it's on the server-side to index by UUID. Data is anonymized prior to being sent!

func NewNoop

func NewNoop() Reporter

NewNoop creates a new telemetry reporter that entirely discards all requests.

type Snapshot

type Snapshot struct {
	DeploymentID string `json:"deployment_id"`

	APIKeys                   []APIKey                    `json:"api_keys"`
	CLIInvocations            []clitelemetry.Invocation   `json:"cli_invocations"`
	ExternalProvisioners      []ExternalProvisioner       `json:"external_provisioners"`
	Licenses                  []License                   `json:"licenses"`
	ProvisionerJobs           []ProvisionerJob            `json:"provisioner_jobs"`
	TemplateVersions          []TemplateVersion           `json:"template_versions"`
	Templates                 []Template                  `json:"templates"`
	Users                     []User                      `json:"users"`
	Groups                    []Group                     `json:"groups"`
	GroupMembers              []GroupMember               `json:"group_members"`
	WorkspaceAgentStats       []WorkspaceAgentStat        `json:"workspace_agent_stats"`
	WorkspaceAgents           []WorkspaceAgent            `json:"workspace_agents"`
	WorkspaceApps             []WorkspaceApp              `json:"workspace_apps"`
	WorkspaceBuilds           []WorkspaceBuild            `json:"workspace_build"`
	WorkspaceProxies          []WorkspaceProxy            `json:"workspace_proxies"`
	WorkspaceResourceMetadata []WorkspaceResourceMetadata `json:"workspace_resource_metadata"`
	WorkspaceResources        []WorkspaceResource         `json:"workspace_resources"`
	WorkspaceModules          []WorkspaceModule           `json:"workspace_modules"`
	Workspaces                []Workspace                 `json:"workspaces"`
	NetworkEvents             []NetworkEvent              `json:"network_events"`
}

Snapshot represents a point-in-time anonymized database dump. Data is aggregated by latest on the server-side, so partial data can be sent without issue.

type Template

type Template struct {
	ID              uuid.UUID `json:"id"`
	CreatedBy       uuid.UUID `json:"created_by"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
	OrganizationID  uuid.UUID `json:"organization_id"`
	Deleted         bool      `json:"deleted"`
	ActiveVersionID uuid.UUID `json:"active_version_id"`
	Name            string    `json:"name"`
	Description     bool      `json:"description"`

	DefaultTTLMillis               int64    `json:"default_ttl_ms"`
	AllowUserCancelWorkspaceJobs   bool     `json:"allow_user_cancel_workspace_jobs"`
	AllowUserAutostart             bool     `json:"allow_user_autostart"`
	AllowUserAutostop              bool     `json:"allow_user_autostop"`
	FailureTTLMillis               int64    `json:"failure_ttl_ms"`
	TimeTilDormantMillis           int64    `json:"time_til_dormant_ms"`
	TimeTilDormantAutoDeleteMillis int64    `json:"time_til_dormant_auto_delete_ms"`
	AutostopRequirementDaysOfWeek  []string `json:"autostop_requirement_days_of_week"`
	AutostopRequirementWeeks       int64    `json:"autostop_requirement_weeks"`
	AutostartAllowedDays           []string `json:"autostart_allowed_days"`
	RequireActiveVersion           bool     `json:"require_active_version"`
	Deprecated                     bool     `json:"deprecated"`
}

func ConvertTemplate

func ConvertTemplate(dbTemplate database.Template) Template

ConvertTemplate anonymizes a template.

type TemplateVersion

type TemplateVersion struct {
	ID              uuid.UUID  `json:"id"`
	CreatedAt       time.Time  `json:"created_at"`
	TemplateID      *uuid.UUID `json:"template_id,omitempty"`
	OrganizationID  uuid.UUID  `json:"organization_id"`
	JobID           uuid.UUID  `json:"job_id"`
	SourceExampleID *string    `json:"source_example_id,omitempty"`
}

func ConvertTemplateVersion

func ConvertTemplateVersion(version database.TemplateVersion) TemplateVersion

ConvertTemplateVersion anonymizes a template version.

type User

type User struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	// Email is only filled in for the first/admin user!
	Email           *string             `json:"email"`
	EmailHashed     string              `json:"email_hashed"`
	RBACRoles       []string            `json:"rbac_roles"`
	Status          database.UserStatus `json:"status"`
	GithubComUserID int64               `json:"github_com_user_id"`
}

func ConvertUser

func ConvertUser(dbUser database.User) User

ConvertUser anonymizes a user.

type Workspace

type Workspace struct {
	ID                uuid.UUID `json:"id"`
	OrganizationID    uuid.UUID `json:"organization_id"`
	OwnerID           uuid.UUID `json:"owner_id"`
	TemplateID        uuid.UUID `json:"template_id"`
	CreatedAt         time.Time `json:"created_at"`
	Deleted           bool      `json:"deleted"`
	Name              string    `json:"name"`
	AutostartSchedule string    `json:"autostart_schedule"`
	AutomaticUpdates  string    `json:"automatic_updates"`
}

func ConvertWorkspace

func ConvertWorkspace(workspace database.Workspace) Workspace

ConvertWorkspace anonymizes a workspace.

type WorkspaceAgent

type WorkspaceAgent struct {
	ID                       uuid.UUID  `json:"id"`
	CreatedAt                time.Time  `json:"created_at"`
	ResourceID               uuid.UUID  `json:"resource_id"`
	InstanceAuth             bool       `json:"instance_auth"`
	Architecture             string     `json:"architecture"`
	OperatingSystem          string     `json:"operating_system"`
	EnvironmentVariables     bool       `json:"environment_variables"`
	Directory                bool       `json:"directory"`
	FirstConnectedAt         *time.Time `json:"first_connected_at"`
	LastConnectedAt          *time.Time `json:"last_connected_at"`
	DisconnectedAt           *time.Time `json:"disconnected_at"`
	ConnectionTimeoutSeconds int32      `json:"connection_timeout_seconds"`
	Subsystems               []string   `json:"subsystems"`
}

func ConvertWorkspaceAgent

func ConvertWorkspaceAgent(agent database.WorkspaceAgent) WorkspaceAgent

ConvertWorkspaceAgent anonymizes a workspace agent.

type WorkspaceAgentStat

type WorkspaceAgentStat struct {
	UserID                      uuid.UUID `json:"user_id"`
	TemplateID                  uuid.UUID `json:"template_id"`
	WorkspaceID                 uuid.UUID `json:"workspace_id"`
	AggregatedFrom              time.Time `json:"aggregated_from"`
	AgentID                     uuid.UUID `json:"agent_id"`
	RxBytes                     int64     `json:"rx_bytes"`
	TxBytes                     int64     `json:"tx_bytes"`
	ConnectionLatency50         float64   `json:"connection_latency_50"`
	ConnectionLatency95         float64   `json:"connection_latency_95"`
	SessionCountVSCode          int64     `json:"session_count_vscode"`
	SessionCountJetBrains       int64     `json:"session_count_jetbrains"`
	SessionCountReconnectingPTY int64     `json:"session_count_reconnecting_pty"`
	SessionCountSSH             int64     `json:"session_count_ssh"`
}

func ConvertWorkspaceAgentStat

func ConvertWorkspaceAgentStat(stat database.GetWorkspaceAgentStatsRow) WorkspaceAgentStat

ConvertWorkspaceAgentStat anonymizes a workspace agent stat.

type WorkspaceApp

type WorkspaceApp struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	AgentID   uuid.UUID `json:"agent_id"`
	Icon      string    `json:"icon"`
	Subdomain bool      `json:"subdomain"`
}

func ConvertWorkspaceApp

func ConvertWorkspaceApp(app database.WorkspaceApp) WorkspaceApp

ConvertWorkspaceApp anonymizes a workspace app.

type WorkspaceBuild

type WorkspaceBuild struct {
	ID                uuid.UUID `json:"id"`
	CreatedAt         time.Time `json:"created_at"`
	WorkspaceID       uuid.UUID `json:"workspace_id"`
	TemplateVersionID uuid.UUID `json:"template_version_id"`
	JobID             uuid.UUID `json:"job_id"`
	BuildNumber       uint32    `json:"build_number"`
}

func ConvertWorkspaceBuild

func ConvertWorkspaceBuild(build database.WorkspaceBuild) WorkspaceBuild

ConvertWorkspaceBuild anonymizes a workspace build.

type WorkspaceModule added in v2.18.0

type WorkspaceModule struct {
	ID         uuid.UUID                    `json:"id"`
	CreatedAt  time.Time                    `json:"created_at"`
	JobID      uuid.UUID                    `json:"job_id"`
	Transition database.WorkspaceTransition `json:"transition"`
	Key        string                       `json:"key"`
	Version    string                       `json:"version"`
	Source     string                       `json:"source"`
	SourceType ModuleSourceType             `json:"source_type"`
}

func ConvertWorkspaceModule added in v2.18.0

func ConvertWorkspaceModule(module database.WorkspaceModule) WorkspaceModule

type WorkspaceProxy

type WorkspaceProxy struct {
	ID          uuid.UUID `json:"id"`
	Name        string    `json:"name"`
	DisplayName string    `json:"display_name"`
	// No URLs since we don't send deployment URL.
	DerpEnabled bool `json:"derp_enabled"`
	DerpOnly    bool `json:"derp_only"`
	// No Status since it may contain sensitive information.
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func ConvertWorkspaceProxy

func ConvertWorkspaceProxy(proxy database.WorkspaceProxy) WorkspaceProxy

ConvertWorkspaceProxy anonymizes a workspace proxy.

type WorkspaceResource

type WorkspaceResource struct {
	ID           uuid.UUID                    `json:"id"`
	CreatedAt    time.Time                    `json:"created_at"`
	JobID        uuid.UUID                    `json:"job_id"`
	Transition   database.WorkspaceTransition `json:"transition"`
	Type         string                       `json:"type"`
	InstanceType string                       `json:"instance_type"`
	// ModulePath is nullable because it was added a long time after the
	// original workspace resource telemetry was added. All new resources
	// will have a module path, but deployments with older resources still
	// in the database will not.
	ModulePath *string `json:"module_path"`
}

func ConvertWorkspaceResource

func ConvertWorkspaceResource(resource database.WorkspaceResource) WorkspaceResource

ConvertWorkspaceResource anonymizes a workspace resource.

type WorkspaceResourceMetadata

type WorkspaceResourceMetadata struct {
	ResourceID uuid.UUID `json:"resource_id"`
	Key        string    `json:"key"`
	Sensitive  bool      `json:"sensitive"`
}

func ConvertWorkspaceResourceMetadata

func ConvertWorkspaceResourceMetadata(metadata database.WorkspaceResourceMetadatum) WorkspaceResourceMetadata

ConvertWorkspaceResourceMetadata anonymizes workspace metadata.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL