Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Moving UnpackUint32AsIP to internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Keith committed May 17, 2018
1 parent 7df0db7 commit f1e5ce0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 25 deletions.
27 changes: 27 additions & 0 deletions internal/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2018 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"encoding/binary"
"net"
)

// UnpackUint32AsIP does the reverse of utils.PackIPAsUint32
func UnpackUint32AsIP(ip uint32) net.IP {
localIP := make(net.IP, 4)
binary.BigEndian.PutUint32(localIP, ip)
return localIP
}
37 changes: 37 additions & 0 deletions internal/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2018 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package internal

import (
"net"
"testing"

"github.com/crossdock/crossdock-go/assert"
)

func TestUnpackUint32AsIP(t *testing.T) {
tests := []struct {
expected net.IP
in uint32
}{
{net.IPv4(1, 2, 3, 4), 1<<24 | 2<<16 | 3<<8 | 4},
{net.IPv4(127, 0, 0, 1), 127<<24 | 1},
}

for _, test := range tests {
ip := UnpackUint32AsIP(test.in)
assert.Equal(t, test.expected, ip.To16())
}
}
7 changes: 0 additions & 7 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ func PackIPAsUint32(ip net.IP) uint32 {
return 0
}

// UnpackUint32AsIP does the reverse of PackIPAsUint32
func UnpackUint32AsIP(ip uint32) net.IP {
localIP := make(net.IP, 4)
binary.BigEndian.PutUint32(localIP, ip)
return localIP
}

// TimeToMicrosecondsSinceEpochInt64 converts Go time.Time to a long
// representing time since epoch in microseconds, which is used expected
// in the Jaeger spans encoded as Thrift.
Expand Down
15 changes: 0 additions & 15 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,3 @@ func TestPackIPAsUint32(t *testing.T) {
assert.Equal(t, test.out, ip)
}
}

func TestUnpackUint32AsIP(t *testing.T) {
tests := []struct {
expected net.IP
in uint32
}{
{net.IPv4(1, 2, 3, 4), 1<<24 | 2<<16 | 3<<8 | 4},
{net.IPv4(127, 0, 0, 1), 127<<24 | 1},
}

for _, test := range tests {
ip := UnpackUint32AsIP(test.in)
assert.Equal(t, test.expected, ip.To16())
}
}
7 changes: 4 additions & 3 deletions zipkin_v2_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/opentracing/opentracing-go/ext"

zipkinModel "github.com/openzipkin/zipkin-go/model"
"github.com/uber/jaeger-client-go/internal"
"github.com/uber/jaeger-client-go/internal/spanlog"
"github.com/uber/jaeger-client-go/utils"
)
Expand All @@ -34,7 +35,7 @@ func BuildZipkinV2Span(span *Span) *zipkinModel.SpanModel {

localEndpoint := &zipkinModel.Endpoint{
ServiceName: span.tracer.serviceName,
IPv4: utils.UnpackUint32AsIP(span.tracer.hostIPv4),
IPv4: internal.UnpackUint32AsIP(span.tracer.hostIPv4),
}

kind, remoteEndpoint, tags := processTags(span)
Expand Down Expand Up @@ -126,9 +127,9 @@ func convertPeerIPv4(value interface{}) net.IP {
return ip.To4()
}
} else if val, ok := value.(uint32); ok {
return utils.UnpackUint32AsIP(val)
return internal.UnpackUint32AsIP(val)
} else if val, ok := value.(int32); ok {
return utils.UnpackUint32AsIP(uint32(val))
return internal.UnpackUint32AsIP(uint32(val))
}
return nil
}
Expand Down

0 comments on commit f1e5ce0

Please sign in to comment.