Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.

Conversation

robertgzr
Copy link
Contributor

@robertgzr robertgzr commented Jul 26, 2017

This introduces a bpf controller that runs the lookup look for every cgroup we attach a program to and executes handlers that write the tracked data to Prometheus metrics that get exposed on port 9101. The top subcommand uses the same code but implements different handlers. It also improves overall logging and adds a flag to adjust the verbosity.

Closes #4, #5, #6, #9

@robertgzr robertgzr added this to the 0.1.0 milestone Jul 26, 2017
@robertgzr robertgzr requested review from alban, asymmetric and iaguis July 26, 2017 16:28
@robertgzr robertgzr force-pushed the robertgzr/bpf-per-pod branch 2 times, most recently from 98d10c0 to 3be4279 Compare July 26, 2017 16:50
Gopkg.lock Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this pkg mentioned here? it does not seem to be used anywhere (neither in cgnet or in the vendored pkgs), or vendored?

Copy link

@asymmetric asymmetric Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU this file is generated by the package manager.

So to answer your question, one would have to look into the dep's behaviour.

Dockerfile Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the parameters could be on the CMD line

Gopkg.lock Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for using master instead of a released version?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use time.Second

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using a callback in parameter 3 instead of just having the lookup function returning the value?

c.packetsHandle(lookup(c.module, packetsKey))

bpf/src/cgnet.c Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the same name for the section and the variable name?
something like:

struct bpf_map_def SEC("maps/count_map") count_map = {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to document:

  • what is the key: define the keys nearby the map definition, so it's clearer.
  • what is the value: a counter
  • how it is used to communicate: values initialized to zero by userspace and incremented by the ebpf program

Just before the map definition:

#define PACKETS_KEY 0
#define BYTES_KEY 1

In the count_packets function:

     int packets_key = PACKETS_KEY, bytes_key = BYTES_KEY;

cmd/serve.go Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to get this from the Kubernetes API rather than assuming the path is built in a specific way?

/cc @asymmetric @nhlfr

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could follow this and do something like client.Get().Namespace("foo").Resource("bar").URL().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asymmetric But that only gives me the resource URL I need the path to the pods cgroup here

@alban I looked though http://godoc.org/k8s.io/api/core/v1#Pod to find a way to get the cgroup for pods but building it ourselfs seems to be the only way. Maybe @nhlfr knows...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If k8s does not provide it, you might have to ask Docker the leader pid of the container and then check in /proc/$pid/cgroup...

You could file an issue and add a // FIXME: ... if you want to do that later.

cmd/serve.go Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup the bpf module? Or at least. add a // FIXME: ... to remember

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was actually why I filed #7 because I didn't know if you had to do any cleanup work.

Will fix this now...

@robertgzr robertgzr mentioned this pull request Jul 31, 2017
@robertgzr robertgzr force-pushed the robertgzr/bpf-per-pod branch from 3be4279 to e334fb8 Compare August 2, 2017 13:01
This introduces a bpf controller that runs the lookup loop for
every cgroup we attach a program to, reads the map and executes
handlers that write the tracked data to Prometheus metrics.

The top subcommand uses the same code but implements different handlers.

Closes #4, closes #5, closes #6, closes #9
@robertgzr robertgzr force-pushed the robertgzr/bpf-per-pod branch from e334fb8 to e193f74 Compare August 2, 2017 13:04
@robertgzr robertgzr requested review from dongsupark and nhlfr August 2, 2017 13:07
@robertgzr
Copy link
Contributor Author

Any more feedback here?

Copy link

@dongsupark dongsupark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, LGTM.
"top" command works fine.
I didn't try out the prometheus part though.

import (
"bytes"
"fmt"
"log"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"log" doesn't seem to be used anywhere, so we get build error.

func (c *Controller) Stop() {
c.quit <- struct{}{}
if err := c.module.Close(); err != nil {
Log.Error("error closing bpf.Module", "err", err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be log instead of Log?
And log needs to be imported, otherwise we get build errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's left over from the logging I introduced but split out of this PR. thx will use the log pkg here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants