Skip to content

Commit

Permalink
feat: Log and add agent, kernel and btfEnabled to events (#52)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

Adds agent, kernel and btf enabled fields to events.

- Closes #47 

## Short description of the changes
- Add BtfEnabled func to utils
- Log agent version, kernel version and if btf is enabled at startup
- Add agent version, kernel version and btfEnabled fields to all events

## How to verify that this has the expected result
- Agent logs agent version, kernel version and if btf is enabled at
start up
- Events sent to Honeycomb include fields for agent version, kernel
version and if btf is enabled

```sh
# Local Docker Desktop:
2023-08-03 10:15:00 2023/08/03 14:15:00 Starting Honeycomb eBPF agent v0.0.2
2023-08-03 10:15:00 2023/08/03 14:15:00 Host kernel version: 5.15.49
2023-08-03 10:15:00 2023/08/03 14:15:00 BTF enabled: false

# EKS on ARM
2023/08/03 14:19:26 Starting Honeycomb eBPF agent v0.0.2
2023/08/03 14:19:26 Host kernel version: 5.10.184
2023/08/03 14:19:26 BTF enabled: true
```


![event-with-metadata-eks-docker](https://github.com/honeycombio/honeycomb-ebpf-agent/assets/29520003/c2083f6c-411e-4a79-98b4-2bfc419af610)

---------

Co-authored-by: Mike Goldsmth <goldsmith.mike@gmail.com>
  • Loading branch information
JamieDanielson and MikeGoldsmith committed Aug 3, 2023
1 parent 489e179 commit b0bb6c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"

Expand All @@ -9,20 +10,22 @@ import (
"github.com/honeycombio/libhoney-go"
)

const Version string = "0.0.1"
const Version string = "0.0.2"
const defaultDataset = "hny-ebpf-agent"
const defaultEndpoint = "https://api.honeycomb.io"

func main() {
log.Printf("Starting Honeycomb eBPF agent v%s\n", Version)

// Try to detect host kernel kernelVersion
kernelVersion, err := utils.HostKernelVersion()
if err != nil {
log.Fatalf("Failed to get host kernel version: %v", err)
}
log.Printf("Host kernel version: %s\n", kernelVersion)

btfEnabled := utils.HostBtfEnabled()
log.Printf("BTF enabled: %v\n", btfEnabled)

apikey := os.Getenv("HONEYCOMB_API_KEY")
if apikey == "" {
log.Fatalf("Honeycomb API key not set, unable to send events\n")
Expand All @@ -40,6 +43,15 @@ func main() {
Dataset: dataset,
APIHost: endpoint,
})

// appends libhoney's user-agent (TODO: doesn't work, no useragent right now)
libhoney.UserAgentAddition = fmt.Sprintf("hny/ebpf-agent/%s", Version)

// configure global fields that are set on all events
libhoney.AddField("honeycomb.agent_version", Version)
libhoney.AddField("meta.kernel_version", kernelVersion.String())
libhoney.AddField("meta.btf_enabled", btfEnabled)

defer libhoney.Close()

// setup probes
Expand Down
6 changes: 6 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"os"

"github.com/cilium/ebpf/features"
)
Expand Down Expand Up @@ -31,3 +32,8 @@ func HostKernelVersion() (KernelVersion, error) {
}
return KernelVersion(code), nil
}

func HostBtfEnabled() bool {
_, err := os.Stat("/sys/kernel/btf/vmlinux")
return err == nil
}

0 comments on commit b0bb6c8

Please sign in to comment.