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

Add Inspektor Gadget TCP and DNS traces #230

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1ba403e
add gadget top block-io
bravebeaver Sep 22, 2022
ddf3e76
create trace using client-go and stream result
bravebeaver Sep 26, 2022
5f53de6
check existence of trace crd rather than pod. more reliable way to se…
bravebeaver Sep 27, 2022
b03c937
allow periscope to run exec on pods
bravebeaver Sep 28, 2022
7f0c785
collect stream and delete pod
bravebeaver Sep 28, 2022
b8c0bef
wait and wait
bravebeaver Sep 28, 2022
1aa75b2
dns needs a bit more time to collect
bravebeaver Sep 29, 2022
96c9bf6
add tcp tracer
bravebeaver Oct 5, 2022
60ea45d
implement data exporter
bravebeaver Oct 5, 2022
d4ee312
tidy up logging
bravebeaver Oct 5, 2022
018a605
add readme
bravebeaver Oct 6, 2022
534b14d
try using IG packages directly
peterbom Dec 2, 2022
53862ab
try to add e2e tests
peterbom Jan 13, 2023
8d01839
make tests work
peterbom Jan 17, 2023
eef7ec4
fix and test TCP trace collector
peterbom Jan 20, 2023
efbbf5f
tidy go.mod
peterbom Jan 20, 2023
2a44057
fix some build errors
peterbom Jan 20, 2023
e0431c3
allow building in a container (without .git folder)
peterbom Jan 22, 2023
bd44c1e
reduce collection time for traces to avoid huge log outputs
peterbom Jan 22, 2023
c94cf06
ensure container collection can map between containers and PIDs
peterbom Jan 22, 2023
d5005e8
fix Windows compilation errors
peterbom Jan 23, 2023
1471203
fixup! try to add e2e tests
peterbom Jan 23, 2023
e5cd7b8
revert changes for running IG as daemonset
peterbom Jan 23, 2023
0acc84b
try to fix linting error and test failure
peterbom May 12, 2023
1475a27
fix systemlogs test
peterbom May 12, 2023
ed625da
fix go linting issues
bravebeaver May 16, 2023
9760839
Merge pull request #11 from bravebeaver/feature/ig-inprocess
peterbom May 16, 2023
f7e18fe
fix windows build errors
peterbom May 16, 2023
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: 1 addition & 1 deletion .github/workflows/ci-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- name: Go tests
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
run: sudo go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
Copy link
Member

Choose a reason for hiding this comment

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

💡Thank you for this. Archiving only: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#administrative-privileges - if anyone ponders sudo use.

minor small question is: Why is sudo needed?

- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash) -C $(Build.SourceVersion)
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,6 @@ deployment/overlays/temp
# Local deployment configuration files
**/.env
**/.env.*

# Test binaries
__debug_bin
21 changes: 7 additions & 14 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
"name": "Launch Tests",
"type": "go",
"request": "launch",
"program": "${fileDirname}",
"mode": "test",
"program": "${fileDirname}/__debug_bin",
"mode": "exec",
"env": {},
"args": ["-test.v"],
"showLog": true
},
{
"name": "Launch Tests with race check",
"type": "go",
"request": "launch",
"program": "${fileDirname}",
"mode": "test",
"env": {},
"buildFlags": "-race",
"args": ["-test.v"],
"showLog": true
"showLog": true,
// https://github.com/golang/vscode-go/blob/master/docs/debugging.md#debug-a-package-test-as-root
Copy link
Member

Choose a reason for hiding this comment

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

Question please: 💡 What is the relevance of this .vscode/launch file with this PR? aka if end-users editor is something else - say - vim or anything else do we need some kind of small doc for fyi?

"console": "integratedTerminal",
"asRoot": true,
"preLaunchTask": "go test (debug)",
},
]
}
21 changes: 21 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "go test (debug)",
"type": "shell",
"command": "go",
"args": [
"test",
"-race",
"-c",
"-gcflags=all=-N -l",
"-o",
"${fileDirname}/__debug_bin"
],
"options": {
"cwd": "${fileDirname}"
}
}
]
}
2 changes: 1 addition & 1 deletion builder/Dockerfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN go mod download

COPY . .

RUN go build ./cmd/aks-periscope
RUN go build -buildvcs=false ./cmd/aks-periscope

# Add dependencies for building nsenter
RUN apt-get update && \
Expand Down
2 changes: 1 addition & 1 deletion builder/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN go mod download

COPY . .

RUN go build ./cmd/aks-periscope
RUN go build -buildvcs=false ./cmd/aks-periscope

# Runner
FROM $BASE_IMAGE
Expand Down
2 changes: 2 additions & 0 deletions cmd/aks-periscope/aks-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Azure/aks-periscope/pkg/exporter"
"github.com/Azure/aks-periscope/pkg/interfaces"
"github.com/Azure/aks-periscope/pkg/utils"

restclient "k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -99,6 +100,7 @@ func run(osIdentifier utils.OSIdentifier, knownFilePaths *utils.KnownFilePaths,
collector.NewSystemPerfCollector(config, runtimeInfo),
collector.NewWindowsLogsCollector(osIdentifier, runtimeInfo, knownFilePaths, fileSystem, 10*time.Second, 20*time.Minute),
}
collectors = addOSSpecificCollectors(collectors, config, runtimeInfo)

collectorGrp := new(sync.WaitGroup)

Expand Down
52 changes: 52 additions & 0 deletions cmd/aks-periscope/collectorsfactory_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"log"
"time"

"github.com/Azure/aks-periscope/pkg/collector"
"github.com/Azure/aks-periscope/pkg/interfaces"
"github.com/Azure/aks-periscope/pkg/utils"

containercollection "github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection"
"github.com/inspektor-gadget/inspektor-gadget/pkg/runcfanotify"

restclient "k8s.io/client-go/rest"
)

func addOSSpecificCollectors(collectors []interfaces.Collector, config *restclient.Config, runtimeInfo *utils.RuntimeInfo) []interfaces.Collector {
// Use the default InspektorGadget behaviour for determining containers:
// https://github.com/inspektor-gadget/inspektor-gadget/blob/6b00fea3f925c9da478126931e774e340ca9bfdf/pkg/gadgettracermanager/gadgettracermanager.go#L275-L283
var containerCollectionOptions []containercollection.ContainerCollectionOption
if runcfanotify.Supported() {
containerCollectionOptions = []containercollection.ContainerCollectionOption{
containercollection.WithRuncFanotify(),
containercollection.WithInitialKubernetesContainers(runtimeInfo.HostNodeName),
}
} else {
containerCollectionOptions = []containercollection.ContainerCollectionOption{
containercollection.WithPodInformer(runtimeInfo.HostNodeName),
}
}

containerCollectionOptions = append(
containerCollectionOptions,
containercollection.WithNodeName(runtimeInfo.HostNodeName),
containercollection.WithCgroupEnrichment(),
containercollection.WithLinuxNamespaceEnrichment(),
containercollection.WithKubernetesEnrichment(runtimeInfo.HostNodeName, config),
)

// Traces can produce a lot of data.
// TODO: Consider whether this should be lower or configurable.
traceCollectionPeriod := 30 * time.Second
traceWaiter := func() {
log.Printf("\twait for %v to stop collection", traceCollectionPeriod)
time.Sleep(traceCollectionPeriod)
}

return append(collectors,
collector.NewInspektorGadgetDNSTraceCollector(runtimeInfo, traceWaiter, containerCollectionOptions),
collector.NewInspektorGadgetTCPTraceCollector(runtimeInfo, traceWaiter, containerCollectionOptions),
)
}
11 changes: 11 additions & 0 deletions cmd/aks-periscope/collectorsfactory_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"github.com/Azure/aks-periscope/pkg/interfaces"
"github.com/Azure/aks-periscope/pkg/utils"
restclient "k8s.io/client-go/rest"
)

func addOSSpecificCollectors(collectors []interfaces.Collector, config *restclient.Config, runtimeInfo *utils.RuntimeInfo) []interfaces.Collector {
return collectors
}
10 changes: 6 additions & 4 deletions deployment/base/daemon-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ spec:
mountPath: /secret
- name: varlog
mountPath: /var/log
- name: resolvlog
mountPath: /run/systemd/resolve
- name: run
mountPath: /run
- name: etcvmlog
mountPath: /etchostlogs
resources:
Expand All @@ -56,9 +56,11 @@ spec:
- name: varlog
hostPath:
path: /var/log
- name: resolvlog
# Need /run from the host to access the container runtime (e.g. containerd) client socket,
# which is used by InspektorGadget to determine the PID for a container ID.
- name: run
hostPath:
path: /run/systemd/resolve
path: /run
- name: etcvmlog
hostPath:
path: /etc
Expand Down
30 changes: 22 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ go 1.19

require (
github.com/Azure/azure-storage-blob-go v0.14.0
github.com/cilium/ebpf v0.9.3
github.com/docker/docker v20.10.17+incompatible
github.com/google/uuid v1.2.0
github.com/hashicorp/go-multierror v1.1.1
github.com/inspektor-gadget/inspektor-gadget v0.12.1
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
helm.sh/helm/v3 v3.10.3
k8s.io/api v0.25.2
k8s.io/apimachinery v0.25.2
k8s.io/cli-runtime v0.25.2
k8s.io/client-go v0.25.2
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/cli-runtime v0.25.4
k8s.io/client-go v0.25.4
k8s.io/kubectl v0.25.2
k8s.io/metrics v0.25.2
)

require (
cloud.google.com/go v0.99.0 // indirect
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/BurntSushi/toml v1.1.0 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
Expand Down Expand Up @@ -56,6 +66,7 @@ require (
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
Expand Down Expand Up @@ -98,31 +109,34 @@ require (
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rubenv/sql-migrate v1.1.2 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/s3rj1k/go-fanotify/fanotify v0.0.0-20210917134616-9c00a300bb7a // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.47.0 // indirect
Expand All @@ -133,6 +147,7 @@ require (
k8s.io/apiextensions-apiserver v0.25.2 // indirect
k8s.io/apiserver v0.25.2 // indirect
k8s.io/component-base v0.25.2 // indirect
k8s.io/cri-api v0.23.1 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
Expand All @@ -143,4 +158,3 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

Loading