telemetry

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package telemetry provides types and helpers for CLI telemetry.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRecord = NewRecord()

DefaultRecord is the global default record.

Functions

func Endpoint

func Endpoint() url.URL

Endpoint returns the real telemetry endpoint.

func GenerateOrReadSignature

func GenerateOrReadSignature(cpsigfile, anasigfile string) (string, bool)

GenerateOrReadSignature attempts to read the analytics signature. If not present, it will create a new one.

func GenerateSignature

func GenerateSignature() string

GenerateSignature generates a new random signature.

func ReadSignature

func ReadSignature(p string) string

ReadSignature parses a signature file. It works for checkpoint and analytics signatures as both use the same format.

func SendMessage

func SendMessage(msg *Message, p SendMessageParams) <-chan error

SendMessage sends an analytics message to the backend endpoint asynchronously. It returns a channel that will receive the result of the operation when it's done.

Types

type AuthType

type AuthType int

AuthType is the authentication method that was used.

const (
	// AuthNone represents no authentication.
	AuthNone AuthType = iota
	// AuthIDPGoogle represents Google IDP authentication.
	AuthIDPGoogle
	// AuthIDPGithub represents GitHub IDP authentication.
	AuthIDPGithub
	// AuthOIDCGithub represents GitHub OIDC authentication.
	AuthOIDCGithub
	// AuthOIDCGitlab represents GitLab OIDC authentication.
	AuthOIDCGitlab
	// AuthAPIKey represents API key authentication.
	AuthAPIKey
)

func DetectAuthTypeFromEnv

func DetectAuthTypeFromEnv(credpath string) AuthType

DetectAuthTypeFromEnv detects AuthType based on environment variables and credentials.

type Message

type Message struct {
	Platform ci.PlatformType `json:"platform,omitempty"`
	// PlatformUser is a platform-specific identifier.
	PlatformUser string `json:"platform_user,omitempty"`

	Auth AuthType `json:"auth,omitempty"`
	// AuthUser is the TMC user UUID.
	AuthUser string `json:"auth_user,omitempty"`

	Signature string `json:"signature,omitempty"`
	OrgName   string `json:"org_name,omitempty"`
	OrgUUID   string `json:"org_uuid,omitempty"`

	Arch string `json:"arch,omitempty"`
	OS   string `json:"os,omitempty"`

	// Command stores the invoked command.
	Command string `json:"command,omitempty"`

	// Details stores features or flags used by the command.
	Details []string `json:"details,omitempty"`
}

Message is the analytics data that will be collected.

type MessageOpt

type MessageOpt func(msg *Message)

MessageOpt is the option type for Set.

func AuthUser added in v0.11.5

func AuthUser(authUser cloud.UUID) MessageOpt

AuthUser sets the auth user.

func BoolFlag

func BoolFlag(name string, flag bool, ifCmds ...string) MessageOpt

BoolFlag sets the given detail name if flag is true. If ifCmds is not empty, the current command of the record must also match any of the given values.

func Command

func Command(cmd string) MessageOpt

Command sets the command name.

func DetectFromEnv

func DetectFromEnv(credfile, cpsigfile, anasigfile string, plat ci.PlatformType, repo *git.Repository) MessageOpt

DetectFromEnv detects platform, platform_user, auth type, signature, architecture and OS from the environment.

func OrgName

func OrgName(orgName string) MessageOpt

OrgName sets the organization name.

func OrgUUID added in v0.11.5

func OrgUUID(orgUUID cloud.UUID) MessageOpt

OrgUUID sets the organization uuid.

func StringFlag

func StringFlag(name string, flag string, ifCmds ...string) MessageOpt

StringFlag calls BoolFlag with flag = (stringFlag != "").

type Record

type Record struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Record is used to aggregate telemetry data over the runtime of the application.

func NewRecord

func NewRecord() *Record

NewRecord creates an empty record.

func (*Record) Send

func (r *Record) Send(params SendMessageParams)

Send sends a message for the current record state asynchronously. A record can only be sent once, subsequent calls will be ignored. The function is non-blocking, the result can be checked with WaitForSend().

func (*Record) Set

func (r *Record) Set(opts ...MessageOpt)

Set updates the telemetry data in the record. It is safe to be called concurrently.

func (*Record) WaitForSend

func (r *Record) WaitForSend() error

WaitForSend waits until Send is done, either successfully, or with error/timeout.

type SendMessageParams

type SendMessageParams struct {
	Endpoint *url.URL
	Client   *http.Client
	Version  string
	Timeout  time.Duration
}

SendMessageParams contains parameters for SendMessage.

Jump to

Keyboard shortcuts

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