Skip to content

Commit 0ceedee

Browse files
committed
chore: address review comments
* chore: rm named returns * chore: mark no route to host error as error * chore: rename hop method to doHop Signed-off-by: lvlcn-t <[email protected]>
1 parent 085fbc1 commit 0ceedee

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/checks/traceroute/traceroute.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func randomPort() int {
4343

4444
// tcpHop attempts to connect to the target host using TCP with the specified TTL and timeout.
4545
// It returns a [net.Conn], the port used for the connection, and an error if the connection failed.
46-
func tcpHop(ctx context.Context, addr net.Addr, ttl int, timeout time.Duration) (conn net.Conn, port int, err error) {
46+
func tcpHop(ctx context.Context, addr net.Addr, ttl int, timeout time.Duration) (net.Conn, int, error) {
4747
span := trace.SpanFromContext(ctx)
4848

4949
for {
@@ -86,10 +86,10 @@ func tcpHop(ctx context.Context, addr net.Addr, ttl int, timeout time.Duration)
8686
case errors.Is(err, unix.EADDRINUSE):
8787
// Address in use, retry by continuing the loop
8888
continue
89-
case errors.Is(err, syscall.EHOSTUNREACH):
90-
// No route to host is no error because of how tcp traceroute works
89+
case errors.Is(err, unix.EHOSTUNREACH):
90+
// No route to host is a special error because of how tcp traceroute works
9191
// we are expecting the connection to fail because of TTL expiry
92-
span.SetStatus(codes.Unset, "No route to host")
92+
span.SetStatus(codes.Error, "No route to host")
9393
span.AddEvent("No route to host", trace.WithAttributes(
9494
attribute.String("error", err.Error()),
9595
))
@@ -198,7 +198,7 @@ func TraceRoute(ctx context.Context, cfg tracerouteConfig) (map[int][]Hop, error
198198
attribute.Int("retry", retry),
199199
))
200200

201-
hop, hErr := hop(ctx, addr, ttl, cfg.Timeout)
201+
hop, hErr := doHop(ctx, addr, ttl, cfg.Timeout)
202202
if hop != nil {
203203
results <- *hop
204204
}
@@ -243,9 +243,9 @@ func TraceRoute(ctx context.Context, cfg tracerouteConfig) (map[int][]Hop, error
243243
return hops, nil
244244
}
245245

246-
// hop performs a hop to the given address with the specified TTL and timeout.
246+
// doHop performs a hop to the given address with the specified TTL and timeout.
247247
// It returns a Hop struct containing the latency, TTL, address, and other details of the hop.
248-
func hop(ctx context.Context, addr net.Addr, ttl int, timeout time.Duration) (*Hop, error) {
248+
func doHop(ctx context.Context, addr net.Addr, ttl int, timeout time.Duration) (*Hop, error) {
249249
span := trace.SpanFromContext(ctx)
250250
log := logger.FromContext(ctx)
251251
canIcmp, icmpListener, err := newIcmpListener()

0 commit comments

Comments
 (0)