mirror of https://github.com/docker/compose.git
Move fire and forget code from metrics.Track() (used only by CLI) to metrics.Send (used by both CLI and API)
Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
parent
2570ebec86
commit
e56061d27c
|
@ -64,10 +64,24 @@ func NewClient() Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Send(command Command) {
|
func (c *client) Send(command Command) {
|
||||||
|
wasIn := make(chan bool)
|
||||||
|
|
||||||
|
// Fire and forget, we don't want to slow down the user waiting for DD
|
||||||
|
// metrics endpoint to respond. We could lose some events but that's ok.
|
||||||
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
_ = recover()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wasIn <- true
|
||||||
|
|
||||||
req, err := json.Marshal(command)
|
req, err := json.Marshal(command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = c.httpClient.Post("http://localhost/usage", "application/json", bytes.NewBuffer(req))
|
_, _ = c.httpClient.Post("http://localhost/usage", "application/json", bytes.NewBuffer(req))
|
||||||
|
}()
|
||||||
|
<-wasIn
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,17 +78,6 @@ const (
|
||||||
|
|
||||||
// Track sends the tracking analytics to Docker Desktop
|
// Track sends the tracking analytics to Docker Desktop
|
||||||
func Track(context string, args []string, flags *flag.FlagSet) {
|
func Track(context string, args []string, flags *flag.FlagSet) {
|
||||||
wasIn := make(chan bool)
|
|
||||||
|
|
||||||
// Fire and forget, we don't want to slow down the user waiting for DD
|
|
||||||
// metrics endpoint to respond. We could lose some events but that's ok.
|
|
||||||
go func() {
|
|
||||||
defer func() {
|
|
||||||
_ = recover()
|
|
||||||
}()
|
|
||||||
|
|
||||||
wasIn <- true
|
|
||||||
|
|
||||||
command := getCommand(args, flags)
|
command := getCommand(args, flags)
|
||||||
if command != "" {
|
if command != "" {
|
||||||
c := NewClient()
|
c := NewClient()
|
||||||
|
@ -98,8 +87,6 @@ func Track(context string, args []string, flags *flag.FlagSet) {
|
||||||
Source: CLISource,
|
Source: CLISource,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
<-wasIn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCommand(args []string, flags *flag.FlagSet) string {
|
func getCommand(args []string, flags *flag.FlagSet) string {
|
||||||
|
|
Loading…
Reference in New Issue