Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flow timestamp update #4955

Merged
merged 1 commit into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di

*Packetbeat*

- Update flow timestamp on each packet being received. {issue}4895[4895]

*Winlogbeat*

==== Added
Expand Down
5 changes: 4 additions & 1 deletion packetbeat/flows/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func (t *flowMetaTable) get(id *FlowID, counter *counterReg) Flow {
}

func (t *flowTable) get(id *FlowID, counter *counterReg) Flow {
ts := time.Now()

t.mutex.Lock()
defer t.mutex.Unlock()

Expand All @@ -66,13 +68,14 @@ func (t *flowTable) get(id *FlowID, counter *counterReg) Flow {
if bf == nil || !bf.isAlive() {
debugf("create new flow")

bf = newBiFlow(id.rawFlowID.clone(), time.Now(), id.dir)
bf = newBiFlow(id.rawFlowID.clone(), ts, id.dir)
t.table[string(bf.id.flowID)] = bf
t.flows.append(bf)
} else if bf.dir != id.dir {
dir = flowDirReversed
}

bf.ts = ts
stats := bf.stats[dir]
if stats == nil {
stats = newFlowStats(counter)
Expand Down
9 changes: 9 additions & 0 deletions packetbeat/tests/system/test_0060_flows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from packetbeat import (BaseTest, FLOWS_REQUIRED_FIELDS)
from pprint import PrettyPrinter
from datetime import datetime
import six


Expand All @@ -11,6 +12,10 @@ def check_fields(flow, fields):
assert flow[k] == v


def parse_timestamp(ts):
return datetime.strptime(ts, "%Y-%m-%dT%H:%M:%S.%fZ")


class Test(BaseTest):

def test_mysql_flow(self):
Expand Down Expand Up @@ -43,6 +48,10 @@ def test_mysql_flow(self):
'dest.stats.net_bytes_total': 181133,
})

start_ts = parse_timestamp(objs[0]['start_time'])
last_ts = parse_timestamp(objs[0]['last_time'])
assert last_ts > start_ts

def test_memcache_udp_flow(self):
self.render_config_template(
flows=True,
Expand Down