Skip to content

Commit ef5d4ae

Browse files
pipiland2612amol-verma-allen
authored andcommitted
Remove package pkg/netutils (jaegertracing#6955)
## Which problem is this PR solving? - part of jaegertracing#6869 ## Description of the changes - Remove package pkg/netutils by - removing unused function `FixLocalhost` - moving function GetPort as private util function `getPortForAddr` within package `cmd/query/app` - the only place where this function is used ## How was this change tested? - running existing tests in the project ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` Signed-off-by: pipiland <[email protected]> Signed-off-by: amol-verma-allen <[email protected]>
1 parent 4f157de commit ef5d4ae

File tree

5 files changed

+69
-111
lines changed

5 files changed

+69
-111
lines changed

cmd/query/app/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/jaegertracing/jaeger/internal/recoveryhandler"
3535
"github.com/jaegertracing/jaeger/internal/telemetry"
3636
"github.com/jaegertracing/jaeger/internal/tenancy"
37-
"github.com/jaegertracing/jaeger/pkg/netutils"
3837
)
3938

4039
// Server runs HTTP, Mux and a grpc server
@@ -270,12 +269,12 @@ func (s *Server) Start(ctx context.Context) error {
270269
}
271270

272271
var httpPort int
273-
if port, err := netutils.GetPort(s.httpConn.Addr()); err == nil {
272+
if port, err := getPortForAddr(s.httpConn.Addr()); err == nil {
274273
httpPort = port
275274
}
276275

277276
var grpcPort int
278-
if port, err := netutils.GetPort(s.grpcConn.Addr()); err == nil {
277+
if port, err := getPortForAddr(s.grpcConn.Addr()); err == nil {
279278
grpcPort = port
280279
}
281280

cmd/query/app/util.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
package app
55

66
import (
7+
"net"
8+
"strconv"
9+
710
"github.com/jaegertracing/jaeger/internal/storage/v1/api/spanstore"
811
)
912

@@ -19,3 +22,18 @@ func getUniqueOperationNames(operations []spanstore.Operation) []string {
1922
}
2023
return operationNames
2124
}
25+
26+
// getPortForAddr returns the port of an endpoint address.
27+
func getPortForAddr(addr net.Addr) (int, error) {
28+
_, port, err := net.SplitHostPort(addr.String())
29+
if err != nil {
30+
return -1, err
31+
}
32+
33+
parsedPort, err := strconv.Atoi(port)
34+
if err != nil {
35+
return -1, err
36+
}
37+
38+
return parsedPort, nil
39+
}

cmd/query/app/util_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011

1112
"github.com/jaegertracing/jaeger/internal/storage/v1/api/spanstore"
1213
)
@@ -25,3 +26,51 @@ func Test_getUniqueOperationNames(t *testing.T) {
2526
assert.Len(t, names, 2)
2627
assert.ElementsMatch(t, expNames, names)
2728
}
29+
30+
func Test_getPort(t *testing.T) {
31+
cases := []struct {
32+
address testAddr
33+
expected int
34+
expectedError string
35+
}{
36+
{
37+
address: testAddr{
38+
Address: "localhost:0",
39+
},
40+
expected: 0,
41+
},
42+
{
43+
address: testAddr{
44+
Address: "localhost",
45+
},
46+
expectedError: "address localhost: missing port in address",
47+
},
48+
{
49+
address: testAddr{
50+
Address: "localhost:port",
51+
},
52+
expectedError: "strconv.Atoi: parsing \"port\": invalid syntax",
53+
},
54+
}
55+
for _, c := range cases {
56+
port, err := getPortForAddr(&c.address)
57+
if c.expectedError != "" {
58+
require.EqualError(t, err, c.expectedError)
59+
} else {
60+
assert.Equal(t, c.expected, port)
61+
}
62+
}
63+
}
64+
65+
type testAddr struct {
66+
Address string
67+
}
68+
69+
// Implement net.Addr methods
70+
func (*testAddr) Network() string {
71+
return "tcp"
72+
}
73+
74+
func (tA *testAddr) String() string {
75+
return tA.Address
76+
}

pkg/netutils/port.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

pkg/netutils/port_test.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)