fix(probe): Update tcptracer-bpf package to cure out-of-order events

Avoid ebpf events out of order by adding offset to time.
This commit is contained in:
Bryan Boreham
2019-07-16 16:23:34 +00:00
parent 5a38963fd0
commit b22bde4a7d
3 changed files with 28 additions and 13 deletions

View File

@@ -1,3 +1,5 @@
// +build linux
package tracer
import (
@@ -37,9 +39,15 @@ func tcpV4ToGo(data *[]byte) (ret TcpV4) {
return
}
// Offset added to all timestamps, to hold back events so they are less
// likely to be reported out of order. Value is in nanoseconds.
var (
TimestampOffset uint64 = 100000
)
func tcpV4Timestamp(data *[]byte) uint64 {
eventC := (*C.struct_tcp_ipv4_event_t)(unsafe.Pointer(&(*data)[0]))
return uint64(eventC.timestamp)
return uint64(eventC.timestamp) + TimestampOffset
}
func tcpV6ToGo(data *[]byte) (ret TcpV6) {
@@ -72,5 +80,5 @@ func tcpV6ToGo(data *[]byte) (ret TcpV6) {
func tcpV6Timestamp(data *[]byte) uint64 {
eventC := (*C.struct_tcp_ipv6_event_t)(unsafe.Pointer(&(*data)[0]))
return uint64(eventC.timestamp)
return uint64(eventC.timestamp) + TimestampOffset
}

View File

@@ -11,6 +11,15 @@ import (
"github.com/weaveworks/tcptracer-bpf/pkg/tracer"
)
const (
OK = iota
BAD_ARGUMENTS
TRACER_INSERT_FAILED
PROCESS_NOT_FOUND
TCP_EVENT_LATE
TCP_EVENTS_LOST
)
var watchFdInstallPids string
type tcpEventTracer struct {
@@ -29,7 +38,7 @@ func (t *tcpEventTracer) TCPEventV4(e tracer.TcpV4) {
if t.lastTimestampV4 > e.Timestamp {
fmt.Printf("ERROR: late event!\n")
os.Exit(1)
os.Exit(TCP_EVENT_LATE)
}
t.lastTimestampV4 = e.Timestamp
@@ -41,7 +50,7 @@ func (t *tcpEventTracer) TCPEventV6(e tracer.TcpV6) {
if t.lastTimestampV6 > e.Timestamp {
fmt.Printf("ERROR: late event!\n")
os.Exit(1)
os.Exit(TCP_EVENT_LATE)
}
t.lastTimestampV6 = e.Timestamp
@@ -49,12 +58,12 @@ func (t *tcpEventTracer) TCPEventV6(e tracer.TcpV6) {
func (t *tcpEventTracer) LostV4(count uint64) {
fmt.Printf("ERROR: lost %d events!\n", count)
os.Exit(1)
os.Exit(TCP_EVENTS_LOST)
}
func (t *tcpEventTracer) LostV6(count uint64) {
fmt.Printf("ERROR: lost %d events!\n", count)
os.Exit(1)
os.Exit(TCP_EVENTS_LOST)
}
func init() {
@@ -66,13 +75,13 @@ func init() {
func main() {
if flag.NArg() > 1 {
flag.Usage()
os.Exit(1)
os.Exit(BAD_ARGUMENTS)
}
t, err := tracer.NewTracer(&tcpEventTracer{})
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
os.Exit(TRACER_INSERT_FAILED)
}
t.Start()
@@ -85,14 +94,12 @@ func main() {
pid, err := strconv.ParseUint(p, 10, 32)
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid pid: %v\n", err)
os.Exit(1)
os.Exit(PROCESS_NOT_FOUND)
}
fmt.Printf("Monitor fdinstall events for pid %d\n", pid)
t.AddFdInstallWatcher(uint32(pid))
}
fmt.Printf("Ready\n")
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, os.Kill)

2
vendor/manifest vendored
View File

@@ -2037,7 +2037,7 @@
"importpath": "github.com/weaveworks/tcptracer-bpf",
"repository": "https://github.com/weaveworks/tcptracer-bpf",
"vcs": "git",
"revision": "6dca783d10f7ba0c8fe707e5e210a8d3114af4c0",
"revision": "cd53e7c84baca8cc63cb689185b93a14b0169848",
"branch": "master",
"notests": true
},