1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 21:33:18 +01:00

chore: fixes analytics to have better data (#3170)

This commit is contained in:
Amir Raminfar
2024-07-31 10:39:24 -07:00
committed by GitHub
parent 73fa622721
commit 1b9f25e64f
6 changed files with 23 additions and 19 deletions

View File

@@ -17,11 +17,18 @@ func StartEvent(args Args, mode string, client docker.Client, subCommand string)
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"
}

View File

@@ -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.`)
@@ -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))
}
}
@@ -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)
}

View File

@@ -29,7 +29,6 @@ type ClientManager interface {
type MultiHostService struct {
manager ClientManager
SwarmMode bool
}
func NewMultiHostService(manager ClientManager) *MultiHostService {

View File

@@ -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)
}

View File

@@ -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

View File

@@ -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 {