Skip to content

Commit 337adf1

Browse files
committed
draft
0 parents  commit 337adf1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+24951
-0
lines changed

CONTRIBUTING.md

Whitespace-only changes.

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Todo delete before merge to elastic/beats
2+
FROM debian
3+
RUN apt-get update
4+
RUN apt-get install -y ca-certificates
5+
COPY ./cloudbeat /cloudbeat
6+
COPY ./cloudbeat.yml /cloudbeat.yml
7+
ENTRYPOINT ["/cloudbeat"]
8+
CMD ["-e", "-d", "'*'"]

Dockerfile.debug

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Todo delete before merge to elastic/beats
2+
FROM golang
3+
RUN go install github.com/go-delve/delve/cmd/dlv@latest
4+
RUN apt-get update
5+
RUN apt-get install -y ca-certificates
6+
EXPOSE 40000
7+
EXPOSE 8080
8+
COPY ./cloudbeat /cloudbeat
9+
COPY ./cloudbeat.yml /cloudbeat.yml
10+
ENTRYPOINT ["/go/bin/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "--wd=/", "exec", "/cloudbeat"]
11+
CMD ["--", "-e", "-d", "'*'"]

JUSTFILE

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Todo delete before merge to elastic/beats
2+
create-kind-cluster:
3+
kind create cluster --config deploy/k8s/kind/kind-config.yaml
4+
5+
install-kind:
6+
brew install kind
7+
8+
setup-env: install-kind create-kind-cluster
9+
10+
load-cloudbeat-image:
11+
kind load docker-image cloudbeat:latest --name kind-mono
12+
13+
load-agent-image:
14+
kind load docker-image docker.elastic.co/beats/elastic-agent:8.1.0-SNAPSHOT --name kind-mono
15+
16+
build-cloudbeat:
17+
GOOS=linux go build -v && docker build -t cloudbeat .
18+
19+
deploy-cloudbeat:
20+
kubectl delete -f deploy/k8s/cloudbeat-ds.yaml -n kube-system & kubectl apply -f deploy/k8s/cloudbeat-ds.yaml -n kube-system
21+
22+
build-deploy-cloudbeat: build-cloudbeat load-cloudbeat-image deploy-cloudbeat
23+
24+
build-cloudbeat-debug:
25+
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags "all=-N -l" && docker build -f Dockerfile.debug -t cloudbeat .
26+
27+
deploy-cloudbeat-debug:
28+
kubectl delete -f deploy/k8s/cloudbeat-ds-debug.yaml -n kube-system & kubectl apply -f deploy/k8s/cloudbeat-ds-debug.yaml -n kube-system
29+
30+
build-deploy-cloudbeat-debug: build-cloudbeat-debug load-cloudbeat-image deploy-cloudbeat-debug
31+
32+
logs-cloudbeat:
33+
kubectl logs -f --selector="k8s-app=cloudbeat" -n kube-system
34+
35+
package-agent:
36+
cd ../x-pack/elastic-agent & DEV=true SNAPSHOT=true PLATFORMS=linux/amd64 TYPES=docker mage -v package
37+
38+
deploy-agent:
39+
kubectl delete -f deploy/k8s/fleet-managed-agent.yaml -n kube-system & kubectl apply -f deploy/k8s//fleet-managed-agent.yaml -n kube-system
40+
41+
build-deploy-agent: package-agent load-agent-image deploy-agent
42+
43+
build-kibana-docker:
44+
node scripts/build --docker-images --skip-docker-ubi --skip-docker-centos -v
45+
46+
elastic-stack-up:
47+
elastic-package stack up --version=8.1.0-SNAPSHOT
48+
49+
elastic-stack-down:
50+
elastic-package stack down
51+

LICENSE.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) {year} Eyal Kraft
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Makefile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
BEAT_NAME=cloudbeat
2+
BEAT_PATH=github.com/elastic/beats/v7/cloudbeat
3+
BEAT_GOPATH=$(firstword $(subst :, ,${GOPATH}))
4+
SYSTEM_TESTS=false
5+
TEST_ENVIRONMENT=false
6+
ES_BEATS_IMPORT_PATH=github.com/elastic/beats/v7
7+
ES_BEATS?=$(shell go list -m -f '{{.Dir}}' ${ES_BEATS_IMPORT_PATH})
8+
LIBBEAT_MAKEFILE=$(ES_BEATS)/libbeat/scripts/Makefile
9+
GOPACKAGES=$(shell go list ${BEAT_PATH}/... | grep -v /tools)
10+
GOBUILD_FLAGS=-i -ldflags "-X ${ES_BEATS_IMPORT_PATH}/libbeat/version.buildTime=$(NOW) -X ${ES_BEATS_IMPORT_PATH}/libbeat/version.commit=$(COMMIT_ID)"
11+
MAGE_IMPORT_PATH=github.com/magefile/mage
12+
NO_COLLECT=true
13+
CHECK_HEADERS_DISABLED=true
14+
15+
# Path to the libbeat Makefile
16+
-include $(LIBBEAT_MAKEFILE)
17+
18+
.PHONY: copy-vendor
19+
copy-vendor:
20+
mage vendorUpdate
21+
22+
delete-pod:
23+
kubectl delete pod cloudbeat-demo
24+
25+
build-docker:
26+
GOOS=linux go build && docker build -t cloudbeat .
27+
28+
docker-image-load-minikube: build-docker
29+
minikube image load cloudbeat:latest
30+
31+
docker-image-load-kind: build-docker
32+
kind load docker-image docker.elastic.co/beats/elastic-agent:8.1.0-SNAPSHOT --name single-host
33+
34+
deploy-cloudbeat:
35+
kubectl apply -f deploy/k8s/cloudbeat-ds.yaml -n kube-system
36+
37+
deploy-pod: delete-pod build-docker docker-image-load-minikube
38+
kubectl apply -f pod.yml
39+
40+
build-deploy-docker: build-docker docker-image-load-kind deploy-cloudbeat
41+

NOTICE.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cloudbeat
2+
Copyright {year} Eyal Kraft
3+
4+
This product includes software developed by The Apache Software
5+
Foundation (http://www.apache.org/).

README.md

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
# POC Documentation
2+
3+
I generated this repo using the [beats development guide](https://www.elastic.co/guide/en/beats/devguide/current/newbeat-generate.html).
4+
The kube-api call is based on the [k8s go-client example](https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration).
5+
6+
The interesting files are:
7+
* `beater/cloudbeat.go` - the beats logic
8+
* `cloudbeat.yml` - the beats config
9+
* `Dockerfile` - runs the beat dockerized with debug flags
10+
* `JUSTFILE` - just commander file
11+
12+
13+
## Table of contents
14+
- [POC Documentation](#poc-documentation)
15+
- [Table of contents](#table-of-contents)
16+
- [Prerequisites](#prerequisites)
17+
- [Running Cloudbeat (without the agent)](#running-cloudbeat-without-the-agent)
18+
- [Clean up](#clean-up)
19+
- [Remote Debugging](#remote-debugging)
20+
- [{Beat}](#beat)
21+
- [Getting Started with {Beat}](#getting-started-with-beat)
22+
- [Requirements](#requirements)
23+
- [Init Project](#init-project)
24+
- [Build](#build)
25+
- [Run](#run)
26+
- [Test](#test)
27+
- [Update](#update)
28+
- [Cleanup](#cleanup)
29+
- [Clone](#clone)
30+
- [Packaging](#packaging)
31+
- [Build Elastic-Agent Docker with pre-packaged cloudbeat](#build-elastic-agent-docker-with-pre-packaged-cloudbeat)
32+
33+
34+
## Prerequisites
35+
**Please make sure that you run the following instructions within the `cloudbeat` directory.**
36+
1. [Just command runner](https://github.com/casey/just)
37+
2. Elasticsearch with the default username & password (`elastic` & `changeme`) running on the default port (`http://localhost:9200`)
38+
3. Kibana with running on the default port (`http://localhost:5601`)
39+
4. Setup the local env:
40+
41+
```zsh
42+
cd cloudbeat & just setup-env
43+
```
44+
45+
## Running Cloudbeat (without the agent)
46+
47+
Build & deploy cloudbeat:
48+
49+
```zsh
50+
just build-deploy-cloudbeat
51+
```
52+
53+
To validate check the logs:
54+
55+
```zsh
56+
kubectl logs -f --selector="k8s-app=cloudbeat" -n kube-system
57+
```
58+
59+
Now go and check out the data on your Kibana! Make sure to add a kibana dataview `logs-k8s_cis.result-*`
60+
61+
note: when changing the fields kibana will reject events dent from the cloudbeat for not matching the existing scheme. make sure to delete the index when changing the event fields in your code.
62+
63+
### Clean up
64+
65+
To stop this example and clean up the pod, run:
66+
```zsh
67+
kubectl delete -f deploy/k8s/cloudbeat-ds.yaml -n kube-system
68+
```
69+
### Remote Debugging
70+
71+
Build & Deploy remote debug docker:
72+
73+
```zsh
74+
just build-deploy-cloudbeat-debug
75+
```
76+
77+
After running the pod, expose the relevant ports:
78+
```zsh
79+
kubectl port-forward ${pod-name} -n kube-system 40000:40000 8080:8080
80+
```
81+
82+
The app will wait for the debugger to connect before starting
83+
84+
```zsh
85+
just logs-cloudbeat
86+
```
87+
88+
Use your favorite IDE to connect to the debugger on `localhost:40000` (for example [Goland](https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-create-the-remote-run-debug-configuration-on-the-client-computer))
89+
90+
# {Beat}
91+
92+
Welcome to {Beat}.
93+
94+
Ensure that this folder is at the following location:
95+
`${GOPATH}/src/github.com/elastic/beats/v7/cloudbeat`
96+
97+
## Getting Started with {Beat}
98+
99+
### Requirements
100+
101+
* [Golang](https://golang.org/dl/) 1.7
102+
103+
### Init Project
104+
To get running with {Beat} and also install the
105+
dependencies, run the following command:
106+
107+
```
108+
make update
109+
```
110+
111+
It will create a clean git history for each major step. Note that you can always rewrite the history if you wish before pushing your changes.
112+
113+
To push {Beat} in the git repository, run the following commands:
114+
115+
```
116+
git remote set-url origin https://github.com/elastic/beats/v7/cloudbeat
117+
git push origin master
118+
```
119+
120+
For further development, check out the [beat developer guide](https://www.elastic.co/guide/en/beats/libbeat/current/new-beat.html).
121+
122+
### Build
123+
124+
To build the binary for {Beat} run the command below. This will generate a binary
125+
in the same directory with the name cloudbeat.
126+
127+
```
128+
make
129+
```
130+
131+
132+
### Run
133+
134+
To run {Beat} with debugging output enabled, run:
135+
136+
```
137+
./cloudbeat -c cloudbeat.yml -e -d "*"
138+
```
139+
140+
### Test
141+
142+
To test {Beat}, run the following command:
143+
144+
```
145+
make testsuite
146+
```
147+
148+
alternatively:
149+
```
150+
make unit-tests
151+
make system-tests
152+
make integration-tests
153+
make coverage-report
154+
```
155+
156+
The test coverage is reported in the folder `./build/coverage/`
157+
158+
### Update
159+
160+
Each beat has a template for the mapping in elasticsearch and a documentation for the fields
161+
which is automatically generated based on `fields.yml` by running the following command.
162+
163+
```
164+
make update
165+
```
166+
167+
168+
### Cleanup
169+
170+
To clean {Beat} source code, run the following command:
171+
172+
```
173+
make fmt
174+
```
175+
176+
To clean up the build directory and generated artifacts, run:
177+
178+
```
179+
make clean
180+
```
181+
182+
183+
### Clone
184+
185+
To clone {Beat} from the git repository, run the following commands:
186+
187+
```
188+
mkdir -p ${GOPATH}/src/github.com/elastic/beats/v7/cloudbeat
189+
git clone https://github.com/elastic/beats/v7/cloudbeat ${GOPATH}/src/github.com/elastic/beats/v7/cloudbeat
190+
```
191+
192+
193+
For further development, check out the [beat developer guide](https://www.elastic.co/guide/en/beats/libbeat/current/new-beat.html).
194+
195+
196+
## Packaging
197+
198+
The beat frameworks provides tools to crosscompile and package your beat for different platforms. This requires [docker](https://www.docker.com/) and vendoring as described above. To build packages of your beat, run the following command:
199+
200+
```
201+
make release
202+
```
203+
204+
This will fetch and create all images required for the build process. The whole process to finish can take several minutes.
205+
206+
## Build Elastic-Agent Docker with pre-packaged cloudbeat
207+
208+
209+
**1.Build Elastic-Agent Docker**
210+
211+
1. Access the Elastic-Agent dir
212+
```
213+
$ cd x-pack/elastic-agent
214+
```
215+
2. Build & deploy the elastic-agent docker( You might need to increase docker engine resources on your docker-engine)
216+
```
217+
$ just build-deploy-agent # It takes a while on the first execution.
218+
```
219+
3. Once command is finished, Verify the agent is running on your machine
220+
221+
```zsh
222+
$ kubectl get po --selector="app=elastic-agent" --all-namespaces -o wide
223+
224+
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
225+
kube-system elastic-agent-9fpdz 1/1 Running 0 5h8m 172.20.0.2 kind-mono-control-plane <none> <none>
226+
227+
228+
```
229+
230+
Note: Check the jusfile for all available commands for build or deploy `$ just --summary`
231+
</br>
232+

_meta/config/beat.docker.yml.tmpl

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
################### {Beat} Configuration Example #########################
2+
3+
############################# {Beat} ######################################
4+
5+
cloudbeat:
6+
# Defines how often an event is sent to the output
7+
period: 30s
8+
files: [
9+
"/hostfs/etc/kubernetes/scheduler.conf",
10+
"/hostfs/etc/kubernetes/controller-manager.conf",
11+
"/hostfs/etc/kubernetes/admin.conf",
12+
"/hostfs/etc/kubernetes/kubelet.conf",
13+
"/hostfs/etc/kubernetes/manifests/etcd.yaml",
14+
"/hostfs/etc/kubernetes/manifests/kube-apiserver.yaml",
15+
"/hostfs/etc/kubernetes/manifests/kube-controller-manager.yaml",
16+
"/hostfs/etc/kubernetes/manifests/kube-scheduler.yaml",
17+
"/hostfs/etc/systemd/system/kubelet.service.d/10-kubeadm.conf",
18+
"/hostfs/var/lib/kubelet/config.yaml",
19+
"/hostfs/var/lib/etcd",
20+
"/hostfs/etc/kubernetes/pki"
21+
]

0 commit comments

Comments
 (0)