Commit Graph

608 Commits

Author SHA1 Message Date
Michael Schubert
cd25b8b935 endpoint/ebpf: implement stop
Since d60874aca8 `connectionTracker` can
fallback when the `EbpfTracker` died. Hence we only have to stop the
`tracer` in `stop()`.

This commit is also a fixup for d60874aca8
where we do a gentle fallback but never actually stop the tracer to stop
polling.
2017-03-21 14:42:34 +01:00
Michael Schubert
5572895a2b ebpf_test: tracker set to dead after out of order events 2017-03-17 16:50:25 +01:00
Michael Schubert
5262e0765d reader_linux: only access latestBuf when set
.. and avoid nil pointer dereference. It can happen that
`getWalkedProcPid` is called before the first `performWalk` finished.
2017-03-17 14:43:31 +01:00
Michael Schubert
d60874aca8 Fallback to proc when ebpf timestamps are wrong 2017-03-17 14:43:31 +01:00
Michael Schubert
22ae6c45a0 Implement ebpf proc fallback 2017-03-14 13:59:09 +01:00
Michael Schubert
5f2ba891a4 endpoint/reporter: only stop scanner if not nil 2017-03-14 11:56:04 +01:00
Michael Schubert
ce904fc56c Remove redundant arg from newEbpfTracker 2017-03-14 11:56:04 +01:00
Matthias Radestock
245c2e9149 fall back to /proc/<pid>/comm for process name
when proc/<pid>/cmdline is empty, which is the case for some system
and defunct processes.

Fixes #2315
2017-03-09 14:02:32 +00:00
Iago López Galeiras
9920c4ea48 Add eBPF connection tracking without dependencies on kernel headers
Based on work from Lorenzo, updated by Iago, Alban, Alessandro and
Michael.

This PR adds connection tracking using eBPF. This feature is not enabled by default.
For now, you can enable it by launching scope with the following command:

```
sudo ./scope launch --probe.ebpf.connections=true
```

This patch allows scope to get notified of every connection event,
without relying on the parsing of /proc/$pid/net/tcp{,6} and
/proc/$pid/fd/*, and therefore improve performance.

We vendor https://github.com/iovisor/gobpf in Scope to load the
pre-compiled ebpf program and https://github.com/weaveworks/tcptracer-bpf
to guess the offsets of the structures we need in the kernel. In this
way we don't need a different pre-compiled ebpf object file per kernel.
The pre-compiled ebpf program is included in the vendoring of
tcptracer-bpf.

The ebpf program uses kprobes/kretprobes on the following kernel functions:
- tcp_v4_connect
- tcp_v6_connect
- tcp_set_state
- inet_csk_accept
- tcp_close

It generates "connect", "accept" and "close" events containing the
connection tuple but also pid and netns.
Note: the IPv6 events are not supported in Scope and thus not passed on.

probe/endpoint/ebpf.go maintains the list of connections. Similarly to
conntrack, it also keeps the dead connections for one iteration in order
to report short-lived connections.

The code for parsing /proc/$pid/net/tcp{,6} and /proc/$pid/fd/* is still
there and still used at start-up because eBPF only brings us the events
and not the initial state. However, the /proc parsing for the initial
state is now done in foreground instead of background, via
newForegroundReader().

NAT resolution on connections from eBPF works in the same way as it did
on connections from /proc: by using conntrack. One of the two conntrack
instances is only started to get the initial state and then it is
stopped since eBPF detects short-lived connections.

The Scope Docker image size comparison:
- weaveworks/scope in current master:  22 MB (compressed),  68 MB
  (uncompressed)
- weaveworks/scope with this patchset: 23 MB (compressed), 69 MB
  (uncompressed)

Fixes #1168 (walking /proc to obtain connections is very expensive)

Fixes #1260 (Short-lived connections not tracked for containers in
shared networking namespaces)

Fixes #1962 (Port ebpf tracker to Go)

Fixes #1961 (Remove runtime kernel header dependency from ebpf tracker)
2017-03-08 22:11:12 +01:00
Alfonso Acosta
052ff39bf1 Merge pull request #2309 from weaveworks/2258-fix-kubelet-access
Fix kubelet failure fallback and make port configurable
2017-03-08 10:15:21 -08:00
Alfonso Acosta
8bf753a51b Revert "Revert "Add options to hide args and env vars (#2306)"" (#2311)
* Revert "Revert "Add options to hide args and env vars (#2306)""

* Make linter happy
2017-03-08 02:16:42 -08:00
Alfonso Acosta
dcc7389127 Revert "Add options to hide args and env vars (#2306)"
This reverts commit 764afb6301.
2017-03-07 17:51:27 +01:00
Mike Bryant
764afb6301 Add options to hide args and env vars (#2306)
* Add options to hide args and env vars

To allow for use of weave-scope in an unauthenticated environment,
add options to the probe to hide comand line arguments and
environment variables, which might contain secret data.

Fixes #2222

* Change docker.NewRegistry arguments to be a struct

* Remove redundant declarations of default values

* Move registry options outside to improve readability
2017-03-07 08:51:18 -08:00
Alfonso Acosta
fb64f1102f Fix tests 2017-03-07 13:53:17 +00:00
Alfonso Acosta
c1fa5bb665 Fix kubelet failure fallback and make port configurable 2017-03-07 13:29:02 +00:00
Mike Lang
a49f1c9559 ECS service controls: Don't allow scale down below 1
as currently this would make it disappear (#2085).
See also https://github.com/weaveworks/scope/pull/2197#discussion_r100424800
2017-02-17 13:31:54 -08:00
Mike Lang
5a477171d3 awsecs: Implement scale up/down control 2017-02-07 14:57:32 -08:00
Mike Lang
7d58e6a9c3 awsecs: Add dummy scale up and scale down controls for services
These controls do nothing for now, this was just to get the control buttons working
2017-02-07 14:57:31 -08:00
Mike Lang
fad3e88269 Rename ECS Service node ids to be cluster;serviceName
This is important for two reasons:
* It prevents nasty false-equality bugs when two different services from different ECS clusters
  are present in the same report
* It allows us to retrieve the cluster and service name - all the info we need to look up the service -
  using only the node ID. This matters, for example, when trying to handle a control request.
2017-02-03 13:45:18 -08:00
Alfonso Acosta
6347238f10 Review feedback 2017-01-27 13:05:50 +00:00
Alfonso Acosta
7ae94a8c8a DNSSnooper: Support Dot1Q and limit decoding errors 2017-01-27 10:59:33 +00:00
Mike Lang
dee274e438 Merge pull request #2065 from weaveworks/mike/ecs/caching
ECS reporter: Minimize API calls by caching task and service data
2017-01-24 11:03:51 -08:00
Mike Lang
c4eb0960f9 awsecs client: simplify list/describe services
by removing ability to stream results between them, since this is such a minor optimization
and greatly complicates the code.
2017-01-23 12:48:50 -08:00
Mike Lang
baffe94538 awsecs caching: Minor review changes 2017-01-20 14:31:41 -08:00
Alfonso Acosta
7aff988929 Simplify kubelet test 2017-01-20 18:23:11 +00:00
Alfonso Acosta
87f1c0f0f5 Merge pull request #2132 from weaveworks/2049-get-local-pods-from-kubelet
Obtain local pods from kubelet
2017-01-19 12:57:54 +01:00
Mike Lang
79a83e3656 awsecs: Appease linter 2017-01-17 12:17:34 -08:00
Alban Crequy
f1e2b5d93a probe: conntrack: fix output parsing
With net.netfilter.nf_conntrack_acct = 1, conntrack adds the following
fields in the output: packets=3 bytes=164

And with SELinux (e.g. Fedora), conntrack adds: secctx=...

The parsing with fmt.Sscanf introduced in #2095 was unfortunately
rejecting lines with those fields. This patch fixes that by adding more
complicated parsing in decodeFlowKeyValues() with FieldsFunc and SplitN.

Fixes #2117
Regression from #2095
2017-01-17 19:30:56 +01:00
Mike Lang
2b7662a3c6 Make reporter tests a seperate package to appease linter
This requires making All The Things public. Yuck.
2017-01-17 03:02:47 -08:00
Alfonso Acosta
496e3f2072 Merge pull request #2114 from weaveworks/1972-non-established-proc-conns
Report persistent connections in states other than ESTABLISHED
2017-01-17 10:45:53 +01:00
Alfonso Acosta
c6f7bdc78e Obtain local pods from kubelet 2017-01-16 18:50:03 +00:00
Filip Barl
d3466b5454 Refactored the table component/model and wrote the tests
Backward-compatibility fix
2017-01-16 17:05:36 +01:00
Filip Barl
6888108b83 Made the searching of generic tables work on the UI
Extracted table headers common code on the frontend

Fixed the search matching and extracted further common code in the UI
2017-01-16 12:22:10 +01:00
Filip Barl
e475a09ee6 Rendering sortable generic tables in the UI
Rendering generic table columns

Made Type a required attribute for TableTemplate

Made generic table sortable on the UI
2017-01-16 12:22:10 +01:00
Filip Barl
31be525bd2 Created generic table model on backend
Replaced MetadataRow with generic Row in Table model

Sending through multicolumn tables from the backend
2017-01-16 12:22:10 +01:00
Mike Lang
5c19dc792e ecs probe: add tests for reporter 2017-01-13 17:31:29 -08:00
Mike Lang
685af493bf ecs probe: Allow cache settings to be tweaked 2017-01-12 11:37:23 -08:00
Mike Lang
513977081d aws ecs probe: Use a size and time bound LRU gcache for caching
instead of our own hand-rolled size-unbound cache
2017-01-12 10:34:41 -08:00
Mike Lang
e220ae822f wip: 2017-01-12 07:11:12 -08:00
Alfonso Acosta
2be26e2be4 Limit connections to established and half-closed 2017-01-10 15:35:32 +00:00
Alfonso Acosta
89a0ab6799 Fix test data and improve /proc/net/tcp header parsing
The header checking code was unsafe because:

1. It was accessing the byteslice at [2] without ensuring a length >= 3
2. It was assuming that the indentation of the 'sl' header is always 2 (which seems to be the case in recent kernels 8f18e4d03e/net/ipv4/tcp_ipv4.c (L2304) and 8f18e4d03e/net/ipv6/tcp_ipv6.c (L1831) ) but it's more robust to simply trim the byteslice.
2017-01-04 00:27:16 +00:00
Alfonso Acosta
99a7dc3b9a Fix tests 2017-01-03 23:34:32 +00:00
Alfonso Acosta
a8b4e65b5c Make linter happy 2017-01-03 22:55:28 +00:00
Alfonso Acosta
7716d96810 Report persistent connections in states other than ESTABLISHED
This aligns the `/proc` connection tracking (persistent connections) with
conntrack (short-lived connections).
2017-01-03 18:38:02 +00:00
Alfonso Acosta
b4e1fc7074 Merge pull request #2112 from weaveworks/2032-ensure-conntrack-events
Check that conntrack events are enabled in the kernel
2017-01-02 23:11:52 +01:00
Alfonso Acosta
5c3ea83846 Fix minor typo 2017-01-02 14:28:22 +00:00
Alfonso Acosta
dfb52f0d93 Clarify even further that proc/PID/net/tcp varies by namespace 2017-01-02 14:27:37 +00:00
Alfonso Acosta
64f1a5d0f5 Check that conntrack events are enabled in the kernel 2017-01-02 09:22:26 +00:00
Alfonso Acosta
2cd76130a1 Merge pull request #2095 from weaveworks/1991-conntrack-parsing
Disable XML in conntrack parsing
2016-12-22 11:00:51 +01:00
Alfonso Acosta
9d352e96f5 Review feedback 2016-12-22 09:33:52 +00:00