Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 7bc9ea0

Browse files
committed
Add retry mechanism for the unix socket connect phase
Signed-off-by: Guvenc Gulce <[email protected]>
1 parent 748fddc commit 7bc9ea0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
"github.com/prometheus/client_golang/prometheus/promhttp"
1717
)
1818

19+
const (
20+
maxRetries = 5
21+
sleepTime = 10 * time.Second
22+
)
23+
1924
var (
2025
socketPath = "/var/run/dpdk/rte/dpdk_telemetry.v2"
2126

@@ -131,18 +136,26 @@ func updateMetrics(conn net.Conn, hostname string) {
131136
}
132137

133138
func main() {
139+
var conn net.Conn
140+
var err error
141+
134142
r := prometheus.NewRegistry()
135143
r.MustRegister(promMetrics)
136144
r.MustRegister(promMetricsCallCount)
137145

138146
http.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
139147

140-
conn, err := net.Dial("unixpacket", socketPath)
141-
if err != nil {
142-
log.Fatalf("Failed to connect to %s: %v", socketPath, err)
148+
for i := 0; i < maxRetries; i++ {
149+
conn, err = net.Dial("unixpacket", socketPath)
150+
if err == nil {
151+
break
152+
}
153+
log.Printf("Failed to connect to %s: %v. Retry %d of %d", socketPath, err, i+1, maxRetries)
154+
if i < maxRetries-1 {
155+
time.Sleep(sleepTime)
156+
}
143157
}
144158
defer conn.Close()
145-
146159
var host string
147160
hostnameFlag := flag.String("hostname", "", "Hostname to use")
148161
pollIntervalFlag := flag.Int("poll-interval", 20, "Polling interval in seconds")

0 commit comments

Comments
 (0)