Skip to content

Commit

Permalink
Merge pull request #654 from ginglis13/metrics-bug-fixes
Browse files Browse the repository at this point in the history
minor demux snapshotter metrics bug fixes
  • Loading branch information
ginglis13 committed Jun 1, 2022
2 parents 76d673a + f4dcd13 commit 8dc79b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
22 changes: 12 additions & 10 deletions snapshotter/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func Run(config config.Config) error {
if config.Snapshotter.Metrics.Enable {
sdHost := config.Snapshotter.Metrics.Host
sdPort := config.Snapshotter.Metrics.ServiceDiscoveryPort
serviceDiscovery := discovery.NewServiceDiscovery(sdHost, sdPort, cache)
monitor, err := initMetricsProxyMonitor(config.Snapshotter.Metrics.PortRange)
serviceDiscovery = discovery.NewServiceDiscovery(sdHost, sdPort, cache)
var err error
monitor, err = initMetricsProxyMonitor(config.Snapshotter.Metrics.PortRange)
if err != nil {
log.G(ctx).WithError(err).Fatal("failed creating metrics proxy monitor")
return err
Expand Down Expand Up @@ -113,19 +114,20 @@ func Run(config config.Config) error {
if err := snapshotter.Close(); err != nil {
log.G(ctx).WithError(err).Error("failed to close snapshotter")
}
if config.Snapshotter.Metrics.Enable {
if err := serviceDiscovery.Shutdown(ctx); err != nil {
log.G(ctx).WithError(err).Error("failed to shutdown service discovery server")
}
// Senders to this channel would panic if it is closed. However snapshotter.Close() will
// shutdown all metrics proxies and ensure there are no more senders over the channel.
monitor.Stop()
}
}()

for {
select {
case <-stop:
// cancelling context will cause shutdown to fail; shutdown before cancel
if config.Snapshotter.Metrics.Enable {
if err := serviceDiscovery.Shutdown(ctx); err != nil {
log.G(ctx).WithError(err).Error("failed to shutdown service discovery server")
}
// Senders to this channel would panic if it is closed. However snapshotter.Close() will
// shutdown all metrics proxies and ensure there are no more senders over the channel.
monitor.Stop()
}
cancel()
return nil
case <-ctx.Done():
Expand Down
9 changes: 5 additions & 4 deletions snapshotter/demux/metrics/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ func NewProxy(host string, monitor *Monitor, labels map[string]string, dialer fu
DialContext: dialer,
},
},
server: nil,
host: host,
Port: port,
Labels: labels,
server: nil,
host: host,
Port: port,
Labels: labels,
monitor: monitor,
}, nil
}

Expand Down
6 changes: 6 additions & 0 deletions snapshotter/internal/http_address_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
var (
port int
remotePort int
metricsRemotePort int
containerdSockPath string
logger *logrus.Logger
)
Expand All @@ -44,6 +45,7 @@ func init() {
flag.IntVar(&port, "port", 10001, "service port for address resolver")
flag.StringVar(&containerdSockPath, "containerdSocket", "/run/firecracker-containerd/containerd.sock", "filepath to the containerd socket")
flag.IntVar(&remotePort, "remotePort", 10000, "the remote port on which the remote snapshotter is listening")
flag.IntVar(&metricsRemotePort, "metricsRemotePort", 10002, "the remote port on which the remote snapshotter metrics server is listening")
logger = logrus.New()
}

Expand Down Expand Up @@ -135,6 +137,10 @@ func queryAddress(writ http.ResponseWriter, req *http.Request) {
Network: "unix",
Address: vmInfo.VSockPath,
SnapshotterPort: strconv.Itoa(remotePort),
MetricsPort: strconv.Itoa(metricsRemotePort),
Labels: map[string]string{
"VMID": namespace,
},
})
if err != nil {
http.Error(writ, "Internal server error", http.StatusInternalServerError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ SuccessAction=reboot

[Service]
Type=simple
ExecStart=socat VSOCK-LISTEN:10001,reuseaddr,fork TCP:localhost:8234
ExecStart=socat VSOCK-LISTEN:10002,reuseaddr,fork TCP:localhost:8234

0 comments on commit 8dc79b2

Please sign in to comment.