Skip to content

Commit f4dcd13

Browse files
committed
minor metrics bug fixes
fix a scoping issues in demux snapshotter issuer. initialize monitor properly in metrics proxy server. add metrics info to example HTTP address resolver. Change VSOCK port for metrics in both HTTP address resovler and socat service. Signed-off-by: Gavin Inglis <[email protected]>
1 parent 2086286 commit f4dcd13

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

snapshotter/app/service.go

Lines changed: 12 additions & 10 deletions
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

Lines changed: 5 additions & 4 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)