Skip to content

Commit 8dc79b2

Browse files
authored
Merge pull request #654 from ginglis13/metrics-bug-fixes
minor demux snapshotter metrics bug fixes
2 parents 76d673a + f4dcd13 commit 8dc79b2

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

snapshotter/app/service.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ func Run(config config.Config) error {
6363
if config.Snapshotter.Metrics.Enable {
6464
sdHost := config.Snapshotter.Metrics.Host
6565
sdPort := config.Snapshotter.Metrics.ServiceDiscoveryPort
66-
serviceDiscovery := discovery.NewServiceDiscovery(sdHost, sdPort, cache)
67-
monitor, err := initMetricsProxyMonitor(config.Snapshotter.Metrics.PortRange)
66+
serviceDiscovery = discovery.NewServiceDiscovery(sdHost, sdPort, cache)
67+
var err error
68+
monitor, err = initMetricsProxyMonitor(config.Snapshotter.Metrics.PortRange)
6869
if err != nil {
6970
log.G(ctx).WithError(err).Fatal("failed creating metrics proxy monitor")
7071
return err
@@ -113,19 +114,20 @@ func Run(config config.Config) error {
113114
if err := snapshotter.Close(); err != nil {
114115
log.G(ctx).WithError(err).Error("failed to close snapshotter")
115116
}
116-
if config.Snapshotter.Metrics.Enable {
117-
if err := serviceDiscovery.Shutdown(ctx); err != nil {
118-
log.G(ctx).WithError(err).Error("failed to shutdown service discovery server")
119-
}
120-
// Senders to this channel would panic if it is closed. However snapshotter.Close() will
121-
// shutdown all metrics proxies and ensure there are no more senders over the channel.
122-
monitor.Stop()
123-
}
124117
}()
125118

126119
for {
127120
select {
128121
case <-stop:
122+
// cancelling context will cause shutdown to fail; shutdown before cancel
123+
if config.Snapshotter.Metrics.Enable {
124+
if err := serviceDiscovery.Shutdown(ctx); err != nil {
125+
log.G(ctx).WithError(err).Error("failed to shutdown service discovery server")
126+
}
127+
// Senders to this channel would panic if it is closed. However snapshotter.Close() will
128+
// shutdown all metrics proxies and ensure there are no more senders over the channel.
129+
monitor.Stop()
130+
}
129131
cancel()
130132
return nil
131133
case <-ctx.Done():

snapshotter/demux/metrics/proxy.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ func NewProxy(host string, monitor *Monitor, labels map[string]string, dialer fu
129129
DialContext: dialer,
130130
},
131131
},
132-
server: nil,
133-
host: host,
134-
Port: port,
135-
Labels: labels,
132+
server: nil,
133+
host: host,
134+
Port: port,
135+
Labels: labels,
136+
monitor: monitor,
136137
}, nil
137138
}
138139

snapshotter/internal/http_address_resolver.go

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
var (
3737
port int
3838
remotePort int
39+
metricsRemotePort int
3940
containerdSockPath string
4041
logger *logrus.Logger
4142
)
@@ -44,6 +45,7 @@ func init() {
4445
flag.IntVar(&port, "port", 10001, "service port for address resolver")
4546
flag.StringVar(&containerdSockPath, "containerdSocket", "/run/firecracker-containerd/containerd.sock", "filepath to the containerd socket")
4647
flag.IntVar(&remotePort, "remotePort", 10000, "the remote port on which the remote snapshotter is listening")
48+
flag.IntVar(&metricsRemotePort, "metricsRemotePort", 10002, "the remote port on which the remote snapshotter metrics server is listening")
4749
logger = logrus.New()
4850
}
4951

@@ -135,6 +137,10 @@ func queryAddress(writ http.ResponseWriter, req *http.Request) {
135137
Network: "unix",
136138
Address: vmInfo.VSockPath,
137139
SnapshotterPort: strconv.Itoa(remotePort),
140+
MetricsPort: strconv.Itoa(metricsRemotePort),
141+
Labels: map[string]string{
142+
"VMID": namespace,
143+
},
138144
})
139145
if err != nil {
140146
http.Error(writ, "Internal server error", http.StatusInternalServerError)

tools/image-builder/files_stargz/etc/systemd/system/metrics-socat.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ SuccessAction=reboot
1919

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

0 commit comments

Comments
 (0)