Skip to content

Commit

Permalink
chore: fixes analytics to have better data (#3170)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 authored Jul 31, 2024
1 parent 73fa622 commit 1b9f25e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
23 changes: 15 additions & 8 deletions internal/support/cli/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ func StartEvent(args Args, mode string, client docker.Client, subCommand string)
return
}
event := analytics.BeaconEvent{
Name: "start",
Version: args.Version(),
Mode: mode,
RemoteAgents: len(args.RemoteAgent),
RemoteClients: len(args.RemoteHost),
SubCommand: subCommand,
Name: "start",
Version: args.Version(),
Mode: mode,
RemoteAgents: len(args.RemoteAgent),
RemoteClients: len(args.RemoteHost),
SubCommand: subCommand,
HasActions: args.EnableActions,
HasCustomAddress: args.Addr != ":8080",
HasCustomBase: args.Base != "/",
HasHostname: args.Hostname != "",
FilterLength: len(args.Filter),
}

if client != nil {
event.ServerID = client.SystemInfo().ID
event.ServerVersion = client.SystemInfo().ServerVersion
host := client.Host()
event.ServerID = host.ID
event.ServerVersion = host.DockerVersion
event.IsSwarmMode = client.SystemInfo().Swarm.NodeID != ""
} else {
event.ServerID = "n/a"
}
Expand Down
6 changes: 2 additions & 4 deletions internal/support/cli/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
log "github.com/sirupsen/logrus"
)

func CreateMultiHostService(embeddedCerts embed.FS, args Args) *docker_support.MultiHostService {
func CreateMultiHostService(embeddedCerts embed.FS, args Args) (docker.Client, *docker_support.MultiHostService) {
var clients []docker_support.ClientService
if len(args.RemoteHost) > 0 {
log.Warnf(`Remote host flag is deprecated and will be removed in future versions. Agents will replace remote hosts as a safer and performant option. See https://github.com/amir20/dozzle/issues/3066 for discussion.`)
Expand Down Expand Up @@ -38,10 +38,8 @@ func CreateMultiHostService(embeddedCerts embed.FS, args Args) *docker_support.M
_, err := localClient.ListContainers()
if err != nil {
log.Debugf("could not connect to local Docker Engine: %s", err)
go StartEvent(args, args.Mode, nil, "")
} else {
log.Debugf("connected to local Docker Engine")
go StartEvent(args, args.Mode, localClient, "")
clients = append(clients, docker_support.NewDockerClientService(localClient))
}
}
Expand All @@ -52,5 +50,5 @@ func CreateMultiHostService(embeddedCerts embed.FS, args Args) *docker_support.M
}

clientManager := docker_support.NewRetriableClientManager(args.RemoteAgent, certs, clients...)
return docker_support.NewMultiHostService(clientManager)
return localClient, docker_support.NewMultiHostService(clientManager)
}
3 changes: 1 addition & 2 deletions internal/support/docker/multi_host_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ type ClientManager interface {
}

type MultiHostService struct {
manager ClientManager
SwarmMode bool
manager ClientManager
}

func NewMultiHostService(manager ClientManager) *MultiHostService {
Expand Down
4 changes: 0 additions & 4 deletions internal/web/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ func sendBeaconEvent(h *handler, r *http.Request, runningContainers int) {
b.ServerID = local.ID
}

if h.multiHostService.SwarmMode {
b.Mode = "swarm"
}

if err := analytics.SendBeacon(b); err != nil {
log.Debugf("error sending beacon: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/web/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (h *handler) executeTemplate(w http.ResponseWriter, req *http.Request) {
if h.config.Base != "/" {
base = h.config.Base
}

hosts := h.multiHostService.Hosts()
sort.Slice(hosts, func(i, j int) bool {
return hosts[i].Name < hosts[j].Name
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ func main() {

var multiHostService *docker_support.MultiHostService
if args.Mode == "server" {
multiHostService = cli.CreateMultiHostService(certs, args)
var localClient docker.Client
localClient, multiHostService = cli.CreateMultiHostService(certs, args)
if multiHostService.TotalClients() == 0 {
log.Fatal("Could not connect to any Docker Engines")
} else {
log.Infof("Connected to %d Docker Engine(s)", multiHostService.TotalClients())
}
go cli.StartEvent(args, "server", localClient, "")

} else if args.Mode == "swarm" {
localClient, err := docker.NewLocalClient(args.Filter, args.Hostname)
if err != nil {
Expand Down

0 comments on commit 1b9f25e

Please sign in to comment.