{"modulePath":"github.com/docker/compose-cli","version":"v1.0.35","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package metrics\n\n## Constants\n\n```go\nconst (\n\t// APISource is sent for API metrics\n\tAPISource = \"api\"\n\t// SuccessStatus command success\n\tSuccessStatus = \"success\"\n\t// FailureStatus command failure\n\tFailureStatus = \"failure\"\n\t// ComposeParseFailureStatus failure while parsing compose file\n\tComposeParseFailureStatus = \"failure-compose-parse\"\n\t// FileNotFoundFailureStatus failure getting compose file\n\tFileNotFoundFailureStatus = \"failure-file-not-found\"\n\t// CommandSyntaxFailureStatus failure reading command\n\tCommandSyntaxFailureStatus = \"failure-cmd-syntax\"\n\t// BuildFailureStatus failure building imge\n\tBuildFailureStatus = \"failure-build\"\n\t// PullFailureStatus failure pulling imge\n\tPullFailureStatus = \"failure-pull\"\n\t// CanceledStatus command canceled\n\tCanceledStatus = \"canceled\"\n)\n```\n\n```go\nconst EnvVarDebugMetricsPath = \"DOCKER_METRICS_DEBUG_LOG\"\n```\nEnvVarDebugMetricsPath is an optional environment variable used to debug metrics by triggering all events to also be written as JSON lines to the specified file path.\n\n```go\nconst Timeout = 50 * time.Millisecond\n```\nTimeout is the maximum amount of time we'll wait for metrics sending to be acknowledged before giving up.\n\n## Variables\n\n```go\nvar (\n\t// FileNotFoundFailure failure for compose file not found\n\tFileNotFoundFailure = FailureCategory{MetricsStatus: FileNotFoundFailureStatus, ExitCode: 14}\n\t// ComposeParseFailure failure for composefile parse error\n\tComposeParseFailure = FailureCategory{MetricsStatus: ComposeParseFailureStatus, ExitCode: 15}\n\t// CommandSyntaxFailure failure for command line syntax\n\tCommandSyntaxFailure = FailureCategory{MetricsStatus: CommandSyntaxFailureStatus, ExitCode: 16}\n\t// BuildFailure failure while building images.\n\tBuildFailure = FailureCategory{MetricsStatus: BuildFailureStatus, ExitCode: 17}\n\t// PullFailure failure while pulling image\n\tPullFailure = FailureCategory{MetricsStatus: PullFailureStatus, ExitCode: 18}\n)\n```\n\n```go\nvar CLISource = \"cli\"\n```\nCLISource is sent for cli metrics\n\n## Functions\n\n```go\nfunc GetCommand(args []string) string\n```\nGetCommand get the invoked command\n\n```go\nfunc HasQuietFlag(args []string) bool\n```\nHasQuietFlag returns true if one of the arguments is \\`--quiet\\` or \\`-q\\`\n\n## Types\n\n```go\ntype AnalyticsRequest struct {\n\tEvent string      `json:\"event\"`\n\tBody  interface{} `json:\"body\"`\n}\n```\n\n```go\ntype Client interface {\n\t// WithCliVersionFunc sets the docker cli version func\n\t// that returns the docker cli version (com.docker.cli)\n\tWithCliVersionFunc(f func() string)\n\t// SendUsage sends the command to Docker Desktop.\n\t//\n\t// Note that metric collection is best-effort, so any errors are ignored.\n\tSendUsage(CommandUsage)\n\t// Track creates an event for a command execution and reports it.\n\tTrack(CmdResult)\n}\n```\nClient sends metrics to Docker Desktop\n\n```go\nfunc NewClient(reporter Reporter) Client\n```\nNewClient returns a new metrics client that will send metrics using the provided Reporter instance.\n\n```go\nfunc NewDefaultClient() Client\n```\nNewDefaultClient returns a new metrics client that will send metrics using the default Reporter configuration, which reports via HTTP, and, optionally, to a local file for debugging. (No format guarantees are made!)\n\n```go\ntype CmdResult struct {\n\t// ContextType is `moby` for Docker or the name of a cloud provider.\n\tContextType string\n\t// Args minus the process name (argv[0] aka `docker`).\n\tArgs []string\n\t// Status based on exit code as a descriptive value.\n\t//\n\t// Deprecated: used for usage, events rely exclusively on exit code.\n\tStatus string\n\t// ExitCode is 0 on success; otherwise, failure.\n\tExitCode int\n\t// Start time of the process (UTC).\n\tStart time.Time\n\t// Duration of process execution.\n\tDuration time.Duration\n}\n```\nCmdResult provides details about process execution.\n\n```go\ntype CommandUsage struct {\n\tCommand string `json:\"command\"`\n\tContext string `json:\"context\"`\n\tSource  string `json:\"source\"`\n\tStatus  string `json:\"status\"`\n}\n```\nCommandUsage reports a CLI invocation for aggregation.\n\n```go\nfunc NewCommandUsage(cmd CmdResult) *CommandUsage\n```\n\n```go\ntype DockerCLIEvent struct {\n\tCommand      string    `json:\"command,omitempty\"`\n\tSubcommand   string    `json:\"subcommand,omitempty\"`\n\tUsage        bool      `json:\"usage,omitempty\"`\n\tExitCode     int32     `json:\"exit_code\"`\n\tStartTime    time.Time `json:\"start_time\"`\n\tDurationSecs float64   `json:\"duration_secs,omitempty\"`\n}\n```\nDockerCLIEvent represents an invocation of \\`docker\\` from the the CLI.\n\n```go\nfunc NewDockerCLIEvent(cmd CmdResult) *DockerCLIEvent\n```\nNewDockerCLIEvent inspects the command line string and returns a stripped down version suitable for reporting.\n\nThe parser will only use known values for command/subcommand from a hardcoded built-in set for safety. It also does not attempt to perfectly accurately reflect how arg parsing works in a real program, instead favoring a fairly simple approach that's still reasonably robust.\n\nIf the command does not map to a known Docker (or first-party plugin) command, \\`nil\\` will be returned. Similarly, if no subcommand for the built-in/plugin can be determined, it will be empty.\n\n```go\ntype FailureCategory struct {\n\tMetricsStatus string\n\tExitCode      int\n}\n```\nFailureCategory struct regrouping metrics failure status and specific exit code\n\n```go\nfunc FailureCategoryFromExitCode(exitCode int) FailureCategory\n```\nFailureCategoryFromExitCode retrieve FailureCategory based on command exit code\n\n```go\ntype HTTPReporter struct {\n\t// contains filtered or unexported fields\n}\n```\nHTTPReporter reports metric events to an HTTP endpoint.\n\n```go\nfunc NewHTTPReporter(client *http.Client) HTTPReporter\n```\nNewHTTPReporter creates a new reporter that will report metric events using the provided HTTP client.\n\n```go\nfunc (l HTTPReporter) Event(cmd DockerCLIEvent)\n```\nEvent reports an analytics action.\n\n```go\nfunc (l HTTPReporter) Heartbeat(cmd CommandUsage)\n```\nHeartbeat reports a metric for aggregation.\n\n```go\ntype MuxReporter struct {\n\t// contains filtered or unexported fields\n}\n```\nMuxReporter wraps multiple reporter instances and reports metrics to each instance on invocation.\n\n```go\nfunc NewMuxReporter(reporters ...Reporter) MuxReporter\n```\nNewMuxReporter creates a reporter that will report metrics to each of the provided reporter instances.\n\n```go\nfunc (m MuxReporter) Event(cmd DockerCLIEvent)\n```\nEvent reports an analytics action.\n\n```go\nfunc (m MuxReporter) Heartbeat(cmd CommandUsage)\n```\nHeartbeat reports a metric for aggregation.\n\n```go\ntype Reporter interface {\n\t// Heartbeat reports a metric for aggregation.\n\tHeartbeat(cmd CommandUsage)\n\n\t// Event reports an analytics action.\n\tEvent(cmd DockerCLIEvent)\n}\n```\nReporter reports metric events generated by the client.\n\n```go\ntype WriterReporter struct {\n\t// contains filtered or unexported fields\n}\n```\nWriterReporter reports metrics as JSON lines to the provided writer.\n\n```go\nfunc NewWriterReporter(w io.Writer) WriterReporter\n```\nNewWriterReporter creates a new reporter that will write metrics to the provided writer as JSON lines.\n\n```go\nfunc (w WriterReporter) Event(cmd DockerCLIEvent)\n```\nEvent reports an analytics action.\n\n```go\nfunc (w WriterReporter) Heartbeat(cmd CommandUsage)\n```\nHeartbeat reports a metric for aggregation.\n\n","path":"github.com/docker/compose-cli/cli/metrics","name":"metrics","synopsis":"","isRedistributable":true}
