fluent-plugin-k8s-metrics-agg 1.1.5 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci_build_test.yaml +192 -0
- data/Gemfile.lock +22 -20
- data/Makefile +3 -6
- data/README.md +0 -1
- data/VERSION +1 -1
- data/ci_scripts/deploy_connector.sh +29 -0
- data/{.circleci → ci_scripts}/install_dep.sh +0 -0
- data/ci_scripts/k8s-splunk.yml +31 -0
- data/docker/Dockerfile +19 -8
- data/docker/Gemfile +4 -4
- data/docker/Gemfile.lock +41 -40
- data/docker/build.sh +1 -2
- data/lib/fluent/plugin/in_kubernetes_metrics_aggregator.rb +130 -81
- metadata +10 -9
- data/.circleci/config.yml +0 -88
- data/.circleci/trigger_func_test.sh +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276b6cf483191eac629b4d605d22296689f26e03d7fd02bf0ba3366b91804242
|
4
|
+
data.tar.gz: e36406b6036c87edac3fa5cf12884a7837e68bf1e04043d42689e18c8e347880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2144bb3bcc031291595986318217b8c52567106290893f7b47bef16df9e10a8a9bd09242791092cfbc3313f610f406de3c65af38b0e7ac295fc3db52d6c077bd
|
7
|
+
data.tar.gz: bde4c5f3b7a86257460773d6dc61b7013c8cdadf7626f9e8269c109d62dbb3f4f52050dec3af61bb04f54923938847bf402cfa93fb8844e80016755bd8bc2ef8
|
@@ -0,0 +1,192 @@
|
|
1
|
+
name: CI Build Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches-ignore:
|
6
|
+
- /^release\/.*/
|
7
|
+
- main
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-20.04
|
12
|
+
steps:
|
13
|
+
- name: Checkout code
|
14
|
+
uses: actions/checkout@v2
|
15
|
+
|
16
|
+
- name: Setup Ruby and install gems
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
bundler-cache: true
|
20
|
+
ruby-version: 2.6.1
|
21
|
+
|
22
|
+
- name: Install dependencies
|
23
|
+
run: |
|
24
|
+
sudo ci_scripts/install_dep.sh
|
25
|
+
|
26
|
+
- name: Builder
|
27
|
+
run: |
|
28
|
+
rake build -t -v
|
29
|
+
cp -R pkg /tmp
|
30
|
+
|
31
|
+
- name: Cache pkg
|
32
|
+
uses: actions/cache@v1
|
33
|
+
with:
|
34
|
+
path: /tmp
|
35
|
+
key: ${{ runner.os }}-build
|
36
|
+
|
37
|
+
unit-test:
|
38
|
+
runs-on: ubuntu-20.04
|
39
|
+
needs:
|
40
|
+
- build
|
41
|
+
steps:
|
42
|
+
- name: Checkout
|
43
|
+
uses: actions/checkout@v2
|
44
|
+
|
45
|
+
- name: Install dependencies
|
46
|
+
run: |
|
47
|
+
sudo ci_scripts/install_dep.sh
|
48
|
+
|
49
|
+
- uses: actions/cache@v2
|
50
|
+
with:
|
51
|
+
path: /tmp
|
52
|
+
key: ${{ runner.os }}-build
|
53
|
+
|
54
|
+
- name: Run unit tests
|
55
|
+
run: |
|
56
|
+
bundle exec rake test -t -v
|
57
|
+
|
58
|
+
func-test:
|
59
|
+
needs:
|
60
|
+
- unit-test
|
61
|
+
runs-on: ubuntu-20.04
|
62
|
+
env:
|
63
|
+
CI_SPLUNK_PORT: 8089
|
64
|
+
CI_SPLUNK_USERNAME: admin
|
65
|
+
CI_SPLUNK_HEC_TOKEN: a6b5e77f-d5f6-415a-bd43-930cecb12959
|
66
|
+
CI_SPLUNK_PASSWORD: helloworld
|
67
|
+
CI_INDEX_EVENTS: ci_events
|
68
|
+
CI_INDEX_OBJECTS: ci_objects
|
69
|
+
CI_INDEX_METRICS: ci_metrics
|
70
|
+
KUBERNETES_VERSION: v1.15.2
|
71
|
+
MINIKUBE_VERSION: v1.21.0
|
72
|
+
GITHUB_ACTIONS: true
|
73
|
+
|
74
|
+
steps:
|
75
|
+
- name: Checkout
|
76
|
+
uses: actions/checkout@v2
|
77
|
+
|
78
|
+
- name: Prepare container build
|
79
|
+
id: prep
|
80
|
+
run: |
|
81
|
+
VERSION=`cat VERSION`
|
82
|
+
TAGS=splunk/k8s-metrics-aggr:recent
|
83
|
+
echo ::set-output name=tags::${TAGS}
|
84
|
+
echo ::set-output name=version::${VERSION}
|
85
|
+
|
86
|
+
- name: Set up QEMU
|
87
|
+
uses: docker/setup-qemu-action@master
|
88
|
+
with:
|
89
|
+
platforms: all
|
90
|
+
|
91
|
+
- name: Set up Docker Buildx
|
92
|
+
id: buildx
|
93
|
+
uses: docker/setup-buildx-action@master
|
94
|
+
|
95
|
+
- name: Build multi-arch kubernetes-metrics image
|
96
|
+
uses: docker/build-push-action@v2
|
97
|
+
with:
|
98
|
+
builder: ${{ steps.buildx.outputs.name }}
|
99
|
+
context: .
|
100
|
+
file: ./docker/Dockerfile
|
101
|
+
platforms: linux/amd64
|
102
|
+
push: false
|
103
|
+
load: true
|
104
|
+
tags: ${{ steps.prep.outputs.tags }}
|
105
|
+
build-args: VERSION=${{ steps.prep.outputs.version }}
|
106
|
+
|
107
|
+
- name: Build k8s-metrics-aggr image
|
108
|
+
run: |
|
109
|
+
docker image ls
|
110
|
+
|
111
|
+
- name: Setup Minikube
|
112
|
+
run: |
|
113
|
+
# Install Kubectl
|
114
|
+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/linux/amd64/kubectl
|
115
|
+
chmod +x kubectl
|
116
|
+
sudo mv kubectl /usr/local/bin/
|
117
|
+
mkdir -p ${HOME}/.kube
|
118
|
+
touch ${HOME}/.kube/config
|
119
|
+
# Install Minikube
|
120
|
+
curl -Lo minikube https://storage.googleapis.com/minikube/releases/${MINIKUBE_VERSION}/minikube-linux-amd64
|
121
|
+
chmod +x minikube
|
122
|
+
sudo mv minikube /usr/local/bin/
|
123
|
+
# Start Minikube and Wait
|
124
|
+
minikube start --driver=docker --container-runtime=docker --cpus 2 --memory 4096 --kubernetes-version=${KUBERNETES_VERSION} --no-vtx-check
|
125
|
+
export JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
|
126
|
+
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
|
127
|
+
sleep 1;
|
128
|
+
done
|
129
|
+
|
130
|
+
- name: Install Splunk
|
131
|
+
run: |
|
132
|
+
# Wait until minikube is ready
|
133
|
+
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
|
134
|
+
export JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'
|
135
|
+
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do
|
136
|
+
echo "wait for minikube ready ..."
|
137
|
+
sleep 1;
|
138
|
+
done
|
139
|
+
kubectl get nodes
|
140
|
+
# Install Splunk on minikube
|
141
|
+
kubectl apply -f ci_scripts/k8s-splunk.yml
|
142
|
+
# Wait until splunk is ready
|
143
|
+
until kubectl logs splunk --tail=2 | grep -q 'Ansible playbook complete'; do
|
144
|
+
sleep 1;
|
145
|
+
done
|
146
|
+
export CI_SPLUNK_HOST=$(kubectl get pod splunk --template={{.status.podIP}})
|
147
|
+
# Setup Indexes
|
148
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/data/indexes -d name=$CI_INDEX_EVENTS -d datatype=event
|
149
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/data/indexes -d name=$CI_INDEX_OBJECTS -d datatype=event
|
150
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/data/indexes -d name=$CI_INDEX_METRICS -d datatype=metric
|
151
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/data/indexes -d name=default-events -d datatype=event
|
152
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/data/indexes -d name=ns-anno -d datatype=event
|
153
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/data/indexes -d name=pod-anno -d datatype=event
|
154
|
+
# Enable HEC services
|
155
|
+
curl -X POST -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD -k https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/servicesNS/nobody/splunk_httpinput/data/inputs/http/http/enable
|
156
|
+
# Create new HEC token
|
157
|
+
curl -X POST -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD -k -d "name=splunk_hec_token&token=a6b5e77f-d5f6-415a-bd43-930cecb12959&disabled=0&index=default-events&indexes=default-events,$CI_INDEX_METRICS,$CI_INDEX_OBJECTS,$CI_INDEX_EVENTS,ns-anno,pod-anno" https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/servicesNS/nobody/splunk_httpinput/data/inputs/http
|
158
|
+
# Restart Splunk
|
159
|
+
curl -k -u $CI_SPLUNK_USERNAME:$CI_SPLUNK_PASSWORD https://$CI_SPLUNK_HOST:$CI_SPLUNK_PORT/services/server/control/restart -X POST
|
160
|
+
|
161
|
+
- name: Deploy k8s connector
|
162
|
+
run: |
|
163
|
+
export CI_SPLUNK_HOST=$(kubectl get pod splunk --template={{.status.podIP}})
|
164
|
+
ci_scripts/deploy_connector.sh
|
165
|
+
|
166
|
+
- name: Deploy log generator
|
167
|
+
run: |
|
168
|
+
cd /opt/splunk-connect-for-kubernetes
|
169
|
+
kubectl apply -f test/test_setup.yaml
|
170
|
+
sleep 65
|
171
|
+
|
172
|
+
- uses: actions/setup-python@v2
|
173
|
+
with:
|
174
|
+
python-version: 3.7
|
175
|
+
|
176
|
+
- name: Run functional tests
|
177
|
+
run: |
|
178
|
+
echo "check the pods"
|
179
|
+
kubectl get pods -A
|
180
|
+
cd /opt/splunk-connect-for-kubernetes
|
181
|
+
kubectl get nodes
|
182
|
+
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
|
183
|
+
export CI_SPLUNK_HOST=$(kubectl get pod splunk --template={{.status.podIP}})
|
184
|
+
cd test
|
185
|
+
pip install --upgrade pip
|
186
|
+
pip install -r requirements.txt
|
187
|
+
echo "Running functional tests....."
|
188
|
+
python -m pytest \
|
189
|
+
--splunkd-url https://$CI_SPLUNK_HOST:8089 \
|
190
|
+
--splunk-user admin \
|
191
|
+
--splunk-password $CI_SPLUNK_PASSWORD \
|
192
|
+
-p no:warnings -s
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-k8s-metrics-agg (1.1.
|
4
|
+
fluent-plugin-k8s-metrics-agg (1.1.9)
|
5
5
|
fluentd (>= 1.9.1)
|
6
6
|
kubeclient (~> 4.6.0)
|
7
7
|
multi_json (~> 1.14.1)
|
@@ -10,29 +10,30 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
addressable (2.
|
13
|
+
addressable (2.8.0)
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
15
|
-
concurrent-ruby (1.1.
|
15
|
+
concurrent-ruby (1.1.9)
|
16
16
|
cool.io (1.7.1)
|
17
17
|
crack (0.4.5)
|
18
18
|
rexml
|
19
|
-
docile (1.
|
19
|
+
docile (1.4.0)
|
20
20
|
domain_name (0.5.20190701)
|
21
21
|
unf (>= 0.0.5, < 1.0.0)
|
22
|
-
ffi (1.
|
22
|
+
ffi (1.15.4)
|
23
23
|
ffi-compiler (1.0.1)
|
24
24
|
ffi (>= 1.0.0)
|
25
25
|
rake
|
26
|
-
fluentd (1.
|
26
|
+
fluentd (1.14.4)
|
27
27
|
bundler
|
28
28
|
cool.io (>= 1.4.5, < 2.0.0)
|
29
|
-
http_parser.rb (>= 0.5.1, < 0.
|
29
|
+
http_parser.rb (>= 0.5.1, < 0.9.0)
|
30
30
|
msgpack (>= 1.3.1, < 2.0.0)
|
31
31
|
serverengine (>= 2.2.2, < 3.0.0)
|
32
32
|
sigdump (~> 0.2.2)
|
33
|
-
strptime (>= 0.2.
|
33
|
+
strptime (>= 0.2.4, < 1.0.0)
|
34
34
|
tzinfo (>= 1.0, < 3.0)
|
35
35
|
tzinfo-data (~> 1.0)
|
36
|
+
webrick (>= 1.4.2, < 1.8.0)
|
36
37
|
yajl-ruby (~> 1.0)
|
37
38
|
hashdiff (1.0.1)
|
38
39
|
http (4.4.1)
|
@@ -41,35 +42,35 @@ GEM
|
|
41
42
|
http-form_data (~> 2.2)
|
42
43
|
http-parser (~> 1.2.0)
|
43
44
|
http-accept (1.7.0)
|
44
|
-
http-cookie (1.0.
|
45
|
+
http-cookie (1.0.4)
|
45
46
|
domain_name (~> 0.5)
|
46
47
|
http-form_data (2.3.0)
|
47
48
|
http-parser (1.2.3)
|
48
49
|
ffi-compiler (>= 1.0, < 2.0)
|
49
|
-
http_parser.rb (0.
|
50
|
-
json (2.
|
50
|
+
http_parser.rb (0.8.0)
|
51
|
+
json (2.6.1)
|
51
52
|
kubeclient (4.6.0)
|
52
53
|
http (>= 3.0, < 5.0)
|
53
54
|
recursive-open-struct (~> 1.0, >= 1.0.4)
|
54
55
|
rest-client (~> 2.0)
|
55
|
-
mime-types (3.
|
56
|
+
mime-types (3.4.1)
|
56
57
|
mime-types-data (~> 3.2015)
|
57
|
-
mime-types-data (3.
|
58
|
+
mime-types-data (3.2022.0105)
|
58
59
|
msgpack (1.4.2)
|
59
60
|
multi_json (1.14.1)
|
60
61
|
netrc (0.11.0)
|
61
62
|
oj (3.10.18)
|
62
|
-
power_assert (2.0.
|
63
|
+
power_assert (2.0.1)
|
63
64
|
public_suffix (4.0.6)
|
64
|
-
rake (13.0.
|
65
|
+
rake (13.0.6)
|
65
66
|
recursive-open-struct (1.1.3)
|
66
67
|
rest-client (2.1.0)
|
67
68
|
http-accept (>= 1.7.0, < 2.0)
|
68
69
|
http-cookie (>= 1.0.2, < 2.0)
|
69
70
|
mime-types (>= 1.16, < 4.0)
|
70
71
|
netrc (~> 0.8)
|
71
|
-
rexml (3.2.
|
72
|
-
serverengine (2.2.
|
72
|
+
rexml (3.2.5)
|
73
|
+
serverengine (2.2.4)
|
73
74
|
sigdump (~> 0.2.2)
|
74
75
|
sigdump (0.2.4)
|
75
76
|
simplecov (0.16.1)
|
@@ -82,15 +83,16 @@ GEM
|
|
82
83
|
power_assert
|
83
84
|
tzinfo (2.0.4)
|
84
85
|
concurrent-ruby (~> 1.0)
|
85
|
-
tzinfo-data (1.2021.
|
86
|
+
tzinfo-data (1.2021.5)
|
86
87
|
tzinfo (>= 1.0.0)
|
87
88
|
unf (0.1.4)
|
88
89
|
unf_ext
|
89
|
-
unf_ext (0.0.
|
90
|
+
unf_ext (0.0.8)
|
90
91
|
webmock (3.5.1)
|
91
92
|
addressable (>= 2.3.6)
|
92
93
|
crack (>= 0.3.2)
|
93
94
|
hashdiff
|
95
|
+
webrick (1.7.0)
|
94
96
|
yajl-ruby (1.4.1)
|
95
97
|
|
96
98
|
PLATFORMS
|
@@ -105,4 +107,4 @@ DEPENDENCIES
|
|
105
107
|
webmock (~> 3.5.1)
|
106
108
|
|
107
109
|
BUNDLED WITH
|
108
|
-
2.
|
110
|
+
2.3.5
|
data/Makefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
VERSION := $(shell sh -c 'cat VERSION')
|
2
|
-
NODEJS_VERSION := 14.15.1
|
3
2
|
|
4
3
|
clean_pkg:
|
5
4
|
@rm -rf pkg/* docker/*.gem
|
@@ -13,11 +12,9 @@ clean: clean_pkg clean_gems
|
|
13
12
|
build: clean_pkg
|
14
13
|
@bundle exec rake build
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
@
|
19
|
-
@cp -rp LICENSE docker/licenses/
|
20
|
-
@docker build --no-cache --pull --build-arg VERSION=$(VERSION) --build-arg NODEJS_VERSION=$(NODEJS_VERSION) -t splunk/k8s-metrics-aggr:$(VERSION) ./docker
|
15
|
+
.PHONY: docker
|
16
|
+
docker:
|
17
|
+
@docker build --no-cache --pull --build-arg VERSION=$(VERSION) -t splunk/k8s-metrics-aggr:$(VERSION) . -f docker/Dockerfile
|
21
18
|
|
22
19
|
unit-test:
|
23
20
|
@bundle exec rake test
|
data/README.md
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
[![CircleCI](https://circleci.com/gh/git-lfs/git-lfs.svg?style=shield&circle-token=856152c2b02bfd236f54d21e1f581f3e4ebf47ad)](https://circleci.com/gh/splunk/fluent-plugin-k8s-metrics-agg)
|
2
1
|
# Fluentd Plugin for Kubernetes Metrics - Aggregator
|
3
2
|
|
4
3
|
[Fluentd](https://fluentd.org/) input plugin collects kubernetes cluster metrics from the kubeapiserver API. The API is exposed by [KubeApiServer](https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/) on a kubernetes cluster.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.9
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -e
|
3
|
+
|
4
|
+
#Make sure to check and clean previously failed deployment
|
5
|
+
echo "Checking if previous deployment exist..."
|
6
|
+
if [ "`helm ls --short`" == "" ]; then
|
7
|
+
echo "Nothing to clean, ready for deployment"
|
8
|
+
else
|
9
|
+
helm delete $(helm ls --short)
|
10
|
+
fi
|
11
|
+
|
12
|
+
# Clone splunk-connect-for-kubernetes repo
|
13
|
+
cd /opt
|
14
|
+
git clone https://github.com/splunk/splunk-connect-for-kubernetes.git
|
15
|
+
cd splunk-connect-for-kubernetes
|
16
|
+
|
17
|
+
minikube image load splunk/k8s-metrics-aggr:recent
|
18
|
+
|
19
|
+
echo "Deploying k8s-connect with latest changes"
|
20
|
+
helm install ci-sck --set global.splunk.hec.token=$CI_SPLUNK_HEC_TOKEN \
|
21
|
+
--set global.splunk.hec.host=$CI_SPLUNK_HOST \
|
22
|
+
--set kubelet.serviceMonitor.https=true \
|
23
|
+
--set splunk-kubernetes-metrics.imageAgg.tag=recent \
|
24
|
+
--set splunk-kubernetes-metrics.imageAgg.pullPolicy=IfNotPresent \
|
25
|
+
-f ci_scripts/sck_values.yml helm-chart/splunk-connect-for-kubernetes
|
26
|
+
#wait for deployment to finish
|
27
|
+
until kubectl get pod | grep Running | [[ $(wc -l) == 4 ]]; do
|
28
|
+
sleep 1;
|
29
|
+
done
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
apiVersion: v1
|
2
|
+
kind: Pod
|
3
|
+
metadata:
|
4
|
+
name: splunk
|
5
|
+
spec:
|
6
|
+
hostNetwork: true
|
7
|
+
securityContext:
|
8
|
+
runAsUser: 0
|
9
|
+
runAsGroup: 0
|
10
|
+
containers:
|
11
|
+
- name: splunk
|
12
|
+
image: splunk/splunk:latest
|
13
|
+
ports:
|
14
|
+
- containerPort: 8000
|
15
|
+
hostPort: 8000
|
16
|
+
protocol: TCP
|
17
|
+
- containerPort: 8088
|
18
|
+
hostPort: 8088
|
19
|
+
protocol: TCP
|
20
|
+
- containerPort: 8089
|
21
|
+
hostPort: 8089
|
22
|
+
protocol: TCP
|
23
|
+
env:
|
24
|
+
- name: SPLUNK_START_ARGS
|
25
|
+
value: --accept-license
|
26
|
+
- name: SPLUNK_USER
|
27
|
+
value: root
|
28
|
+
- name: SPLUNK_PASSWORD
|
29
|
+
value: helloworld
|
30
|
+
- name: SPLUNK_LAUNCH_CONF
|
31
|
+
value: OPTIMISTIC_ABOUT_FILE_LOCKING=1
|
data/docker/Dockerfile
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
FROM ruby:2.7.4-buster as builder
|
2
|
+
|
3
|
+
ADD ./ /app/
|
4
|
+
WORKDIR /app
|
5
|
+
RUN gem install bundler
|
6
|
+
RUN bundle update --bundler
|
7
|
+
RUN bundle install
|
8
|
+
|
9
|
+
RUN bundle exec rake build -t -v
|
10
|
+
|
1
11
|
FROM registry.access.redhat.com/ubi8/ruby-27
|
2
12
|
|
3
13
|
ARG VERSION
|
4
|
-
ARG NODEJS_VERSION
|
5
14
|
|
6
15
|
LABEL name="Splunk Connect for Kubernetes Metrics Aggregator container" \
|
7
16
|
maintainer="DataEdge@splunk.com" \
|
@@ -15,18 +24,20 @@ ENV VERSION=${VERSION}
|
|
15
24
|
ENV FLUENT_USER fluent
|
16
25
|
|
17
26
|
USER root
|
18
|
-
COPY licenses /licenses
|
19
27
|
|
20
|
-
COPY
|
28
|
+
COPY --from=builder /app/pkg/fluent-plugin-*.gem /tmp/
|
29
|
+
|
30
|
+
RUN mkdir /licenses
|
31
|
+
COPY --from=builder /app/LICENSE /licenses/LICENSE
|
32
|
+
|
33
|
+
COPY --from=builder /app/docker/Gemfile* ./
|
21
34
|
|
22
|
-
COPY Gemfile* ./
|
23
35
|
RUN yum update -y \
|
24
|
-
&&
|
25
|
-
&& yum remove -y nodejs \
|
26
|
-
&& n ${NODEJS_VERSION} \
|
36
|
+
&& yum remove -y nodejs npm \
|
27
37
|
&& gem install bundler \
|
28
38
|
&& gem unpack /tmp/*.gem --target gem \
|
29
|
-
&& bundle install
|
39
|
+
&& bundle install \
|
40
|
+
&& rpm -e --nodeps python3-pip-wheel python3-urllib3-* python3-requests-* python3-libxml2-* python3-dmidecode-* subscription-manager-* libwebp-* libwebp-devel-* glib2-* libjpeg-turbo-devel-* libjpeg-turbo-* mariadb-connector-c-config-* mariadb-connector-c-* mariadb-connector-c-devel-* rsync-* sqlite-libs-* sqlite-devel-* sqlite-* libxml2-* libxml2-devel-* libX11-* libX11-common-* libX11-devel-* libX11-xcb-* nettle-* libsolv-* file-libs-* dbus-daemon-* tar-* qt5-srpm-macros-* perl-parent-* git-* bsdtar-* openssh-clients-* json-c-* binutils-* libtiff-devel-* libtiff-* || true
|
30
41
|
|
31
42
|
RUN groupadd -r $FLUENT_USER && \
|
32
43
|
useradd -r -g $FLUENT_USER $FLUENT_USER && \
|
data/docker/Gemfile
CHANGED
@@ -3,16 +3,16 @@ source 'https://rubygems.org'
|
|
3
3
|
# This is separate gemfile for building docker image that has all plugins
|
4
4
|
# for kubernetes log collection agent
|
5
5
|
# List all required gems here and install via bundler to resolve dependencies
|
6
|
-
gem "fluentd", "
|
7
|
-
gem "fluent-plugin-prometheus", "
|
6
|
+
gem "fluentd", ">=1.14.2"
|
7
|
+
gem "fluent-plugin-prometheus", ">=2.0"
|
8
8
|
gem "fluent-plugin-record-modifier", "=2.1.0"
|
9
|
-
gem "fluent-plugin-kubernetes_metadata_filter", "
|
9
|
+
gem "fluent-plugin-kubernetes_metadata_filter", ">=2.9.2"
|
10
10
|
gem "kubeclient", "=4.6.0"
|
11
11
|
gem "oj", "=3.10.2"
|
12
12
|
gem 'multi_json', '=1.14.1'
|
13
13
|
gem 'http_parser.rb', '=0.5.3'
|
14
14
|
gem 'bigdecimal', '=3.0.0'
|
15
15
|
|
16
|
-
gem "fluent-plugin-splunk-hec", ">= 1.2.
|
16
|
+
gem "fluent-plugin-splunk-hec", ">= 1.2.7"
|
17
17
|
|
18
18
|
gem 'fluent-plugin-k8s-metrics-agg', path: 'gem/'
|
data/docker/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: gem
|
3
3
|
specs:
|
4
|
-
fluent-plugin-k8s-metrics-agg (1.1.
|
4
|
+
fluent-plugin-k8s-metrics-agg (1.1.9)
|
5
5
|
fluentd (>= 1.9.1)
|
6
6
|
kubeclient (~> 4.6.0)
|
7
7
|
multi_json (~> 1.14.1)
|
@@ -10,53 +10,55 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (6.1.3
|
14
|
-
activesupport (= 6.1.3
|
15
|
-
activesupport (6.1.3
|
13
|
+
activemodel (6.1.4.3)
|
14
|
+
activesupport (= 6.1.4.3)
|
15
|
+
activesupport (6.1.4.3)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 1.6, < 2)
|
18
18
|
minitest (>= 5.1)
|
19
19
|
tzinfo (~> 2.0)
|
20
20
|
zeitwerk (~> 2.3)
|
21
|
-
addressable (2.
|
21
|
+
addressable (2.8.0)
|
22
22
|
public_suffix (>= 2.0.2, < 5.0)
|
23
23
|
aes_key_wrap (1.1.0)
|
24
24
|
attr_required (1.0.1)
|
25
25
|
bigdecimal (3.0.0)
|
26
|
-
bindata (2.4.
|
27
|
-
concurrent-ruby (1.1.
|
28
|
-
connection_pool (2.2.
|
26
|
+
bindata (2.4.10)
|
27
|
+
concurrent-ruby (1.1.9)
|
28
|
+
connection_pool (2.2.5)
|
29
29
|
cool.io (1.7.1)
|
30
30
|
domain_name (0.5.20190701)
|
31
31
|
unf (>= 0.0.5, < 1.0.0)
|
32
|
-
ffi (1.15.
|
32
|
+
ffi (1.15.4)
|
33
33
|
ffi-compiler (1.0.1)
|
34
34
|
ffi (>= 1.0.0)
|
35
35
|
rake
|
36
|
-
fluent-plugin-kubernetes_metadata_filter (2.
|
37
|
-
fluentd (>= 0.14.0, < 1.
|
38
|
-
kubeclient (< 5)
|
36
|
+
fluent-plugin-kubernetes_metadata_filter (2.9.3)
|
37
|
+
fluentd (>= 0.14.0, < 1.15)
|
38
|
+
kubeclient (>= 4.0.0, < 5.0.0)
|
39
39
|
lru_redux
|
40
|
-
fluent-plugin-prometheus (
|
40
|
+
fluent-plugin-prometheus (2.0.2)
|
41
41
|
fluentd (>= 1.9.1, < 2)
|
42
|
-
prometheus-client (
|
42
|
+
prometheus-client (>= 2.1.0)
|
43
43
|
fluent-plugin-record-modifier (2.1.0)
|
44
44
|
fluentd (>= 1.0, < 2)
|
45
|
-
fluent-plugin-splunk-hec (1.2.
|
45
|
+
fluent-plugin-splunk-hec (1.2.9)
|
46
46
|
fluentd (>= 1.4)
|
47
47
|
multi_json (~> 1.13)
|
48
48
|
net-http-persistent (~> 3.1)
|
49
49
|
openid_connect (~> 1.1.8)
|
50
|
-
prometheus-client (
|
51
|
-
fluentd (1.
|
50
|
+
prometheus-client (>= 2.1.0)
|
51
|
+
fluentd (1.14.3)
|
52
|
+
bundler
|
52
53
|
cool.io (>= 1.4.5, < 2.0.0)
|
53
|
-
http_parser.rb (>= 0.5.1, < 0.
|
54
|
+
http_parser.rb (>= 0.5.1, < 0.9.0)
|
54
55
|
msgpack (>= 1.3.1, < 2.0.0)
|
55
56
|
serverengine (>= 2.2.2, < 3.0.0)
|
56
57
|
sigdump (~> 0.2.2)
|
57
|
-
strptime (>= 0.2.
|
58
|
+
strptime (>= 0.2.4, < 1.0.0)
|
58
59
|
tzinfo (>= 1.0, < 3.0)
|
59
60
|
tzinfo-data (~> 1.0)
|
61
|
+
webrick (>= 1.4.2, < 1.8.0)
|
60
62
|
yajl-ruby (~> 1.0)
|
61
63
|
http (4.4.1)
|
62
64
|
addressable (~> 2.3)
|
@@ -64,14 +66,14 @@ GEM
|
|
64
66
|
http-form_data (~> 2.2)
|
65
67
|
http-parser (~> 1.2.0)
|
66
68
|
http-accept (1.7.0)
|
67
|
-
http-cookie (1.0.
|
69
|
+
http-cookie (1.0.4)
|
68
70
|
domain_name (~> 0.5)
|
69
71
|
http-form_data (2.3.0)
|
70
72
|
http-parser (1.2.3)
|
71
73
|
ffi-compiler (>= 1.0, < 2.0)
|
72
74
|
http_parser.rb (0.5.3)
|
73
75
|
httpclient (2.8.3)
|
74
|
-
i18n (1.8.
|
76
|
+
i18n (1.8.11)
|
75
77
|
concurrent-ruby (~> 1.0)
|
76
78
|
json-jwt (1.13.0)
|
77
79
|
activesupport (>= 4.2)
|
@@ -84,11 +86,11 @@ GEM
|
|
84
86
|
lru_redux (1.1.0)
|
85
87
|
mail (2.7.1)
|
86
88
|
mini_mime (>= 0.1.1)
|
87
|
-
mime-types (3.
|
89
|
+
mime-types (3.4.1)
|
88
90
|
mime-types-data (~> 3.2015)
|
89
|
-
mime-types-data (3.2021.
|
90
|
-
mini_mime (1.
|
91
|
-
minitest (5.
|
91
|
+
mime-types-data (3.2021.1115)
|
92
|
+
mini_mime (1.1.2)
|
93
|
+
minitest (5.15.0)
|
92
94
|
msgpack (1.4.2)
|
93
95
|
multi_json (1.14.1)
|
94
96
|
net-http-persistent (3.1.0)
|
@@ -105,50 +107,49 @@ GEM
|
|
105
107
|
validate_email
|
106
108
|
validate_url
|
107
109
|
webfinger (>= 1.0.1)
|
108
|
-
prometheus-client (
|
109
|
-
quantile (~> 0.2.1)
|
110
|
+
prometheus-client (2.1.0)
|
110
111
|
public_suffix (4.0.6)
|
111
|
-
quantile (0.2.1)
|
112
112
|
rack (2.2.3)
|
113
|
-
rack-oauth2 (1.
|
113
|
+
rack-oauth2 (1.19.0)
|
114
114
|
activesupport
|
115
115
|
attr_required
|
116
116
|
httpclient
|
117
117
|
json-jwt (>= 1.11.0)
|
118
118
|
rack (>= 2.1.0)
|
119
|
-
rake (13.0.
|
119
|
+
rake (13.0.6)
|
120
120
|
recursive-open-struct (1.1.3)
|
121
121
|
rest-client (2.1.0)
|
122
122
|
http-accept (>= 1.7.0, < 2.0)
|
123
123
|
http-cookie (>= 1.0.2, < 2.0)
|
124
124
|
mime-types (>= 1.16, < 4.0)
|
125
125
|
netrc (~> 0.8)
|
126
|
-
serverengine (2.2.
|
126
|
+
serverengine (2.2.4)
|
127
127
|
sigdump (~> 0.2.2)
|
128
128
|
sigdump (0.2.4)
|
129
129
|
strptime (0.2.5)
|
130
|
-
swd (1.
|
130
|
+
swd (1.3.0)
|
131
131
|
activesupport (>= 3)
|
132
132
|
attr_required (>= 0.0.5)
|
133
133
|
httpclient (>= 2.4)
|
134
134
|
tzinfo (2.0.4)
|
135
135
|
concurrent-ruby (~> 1.0)
|
136
|
-
tzinfo-data (1.2021.
|
136
|
+
tzinfo-data (1.2021.5)
|
137
137
|
tzinfo (>= 1.0.0)
|
138
138
|
unf (0.1.4)
|
139
139
|
unf_ext
|
140
|
-
unf_ext (0.0.
|
140
|
+
unf_ext (0.0.8)
|
141
141
|
validate_email (0.1.6)
|
142
142
|
activemodel (>= 3.0)
|
143
143
|
mail (>= 2.2.5)
|
144
144
|
validate_url (1.0.13)
|
145
145
|
activemodel (>= 3.0.0)
|
146
146
|
public_suffix
|
147
|
-
webfinger (1.
|
147
|
+
webfinger (1.2.0)
|
148
148
|
activesupport
|
149
149
|
httpclient (>= 2.4)
|
150
|
+
webrick (1.7.0)
|
150
151
|
yajl-ruby (1.4.1)
|
151
|
-
zeitwerk (2.
|
152
|
+
zeitwerk (2.5.1)
|
152
153
|
|
153
154
|
PLATFORMS
|
154
155
|
ruby
|
@@ -156,11 +157,11 @@ PLATFORMS
|
|
156
157
|
DEPENDENCIES
|
157
158
|
bigdecimal (= 3.0.0)
|
158
159
|
fluent-plugin-k8s-metrics-agg!
|
159
|
-
fluent-plugin-kubernetes_metadata_filter (
|
160
|
-
fluent-plugin-prometheus (
|
160
|
+
fluent-plugin-kubernetes_metadata_filter (>= 2.9.2)
|
161
|
+
fluent-plugin-prometheus (>= 2.0)
|
161
162
|
fluent-plugin-record-modifier (= 2.1.0)
|
162
|
-
fluent-plugin-splunk-hec (>= 1.2.
|
163
|
-
fluentd (
|
163
|
+
fluent-plugin-splunk-hec (>= 1.2.7)
|
164
|
+
fluentd (>= 1.14.2)
|
164
165
|
http_parser.rb (= 0.5.3)
|
165
166
|
kubeclient (= 4.6.0)
|
166
167
|
multi_json (= 1.14.1)
|
data/docker/build.sh
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
set -e
|
3
3
|
TAG=$1
|
4
|
-
NODEJS_VERSION=14.15.1
|
5
4
|
|
6
5
|
# Install dependecies
|
7
6
|
gem install bundler
|
@@ -17,4 +16,4 @@ VERSION=`cat VERSION`
|
|
17
16
|
echo "Copying licenses to be included in the docker image..."
|
18
17
|
mkdir -p docker/licenses
|
19
18
|
cp -rp LICENSE docker/licenses/
|
20
|
-
docker build --no-cache --pull --build-arg VERSION=$VERSION --
|
19
|
+
docker build --no-cache --pull --build-arg VERSION=$VERSION --no-cache -t splunk/k8s-metrics-aggr:$TAG ./docker
|
@@ -51,11 +51,11 @@ module Fluent
|
|
51
51
|
# m cpu is assumed standard
|
52
52
|
@cpu_mult = 1
|
53
53
|
@cpu_mult = 1000 if cpu[-1] != 'm'
|
54
|
-
cpu.delete('^0-9').to_i
|
54
|
+
cpu.delete('^0-9.').to_i
|
55
55
|
end
|
56
56
|
|
57
57
|
def get_cpu_or_memory_value(resource)
|
58
|
-
resource = resource.tr('^0-9', '').to_i
|
58
|
+
resource = resource.tr('^0-9.', '').to_i
|
59
59
|
resource
|
60
60
|
end
|
61
61
|
|
@@ -66,29 +66,35 @@ module Fluent
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#meaning-of-memory
|
69
|
+
# 1 Ki = 1024 bytes
|
70
|
+
# 1 K = 1000 bytes = 1000/1024 Ki = 1000/1024*1024 Mi
|
69
71
|
def get_memory_mult(memory)
|
70
|
-
memory_mult = if memory[-2] == 'Ki'
|
71
|
-
0.001
|
72
|
-
elsif memory[-2] == 'K'
|
72
|
+
memory_mult = if memory[-2..] == 'Ki'
|
73
73
|
1.0 / 1024
|
74
|
-
elsif memory[-
|
74
|
+
elsif memory[-1] == 'K'
|
75
|
+
1e3 / 1024 ** 2
|
76
|
+
elsif memory[-2..] == 'Mi'
|
75
77
|
1
|
76
|
-
elsif memory[-
|
77
|
-
|
78
|
-
elsif memory[-2] == 'Gi'
|
79
|
-
1000
|
80
|
-
elsif memory[-2] == 'G'
|
78
|
+
elsif memory[-1] == 'M'
|
79
|
+
1e6 / 1024 ** 2
|
80
|
+
elsif memory[-2..] == 'Gi'
|
81
81
|
1024
|
82
|
-
elsif memory[-
|
83
|
-
|
84
|
-
elsif memory[-2] == '
|
85
|
-
|
86
|
-
elsif memory[-
|
87
|
-
|
82
|
+
elsif memory[-1] == 'G'
|
83
|
+
1e9 / 1024 ** 2
|
84
|
+
elsif memory[-2..] == 'Ti'
|
85
|
+
1024 ** 2
|
86
|
+
elsif memory[-1] == 'T'
|
87
|
+
1e12 / 1024 ** 2
|
88
|
+
elsif memory[-2..] == 'Pi'
|
89
|
+
1024**3
|
90
|
+
elsif memory[-2] == 'P'
|
91
|
+
1e15 / 1024 ** 2
|
92
|
+
elsif memory[-2..] == 'Ei'
|
93
|
+
1024**4
|
88
94
|
elsif memory[-2] == 'E'
|
89
|
-
|
95
|
+
1e18 / 1024 ** 2
|
90
96
|
else
|
91
|
-
0
|
97
|
+
1.0 / 1024 ** 2
|
92
98
|
end
|
93
99
|
memory_mult
|
94
100
|
end
|
@@ -278,43 +284,47 @@ module Fluent
|
|
278
284
|
end
|
279
285
|
|
280
286
|
def get_cpu_value(resource)
|
281
|
-
cpu_val = resource.tr('^0-9', '').to_i
|
287
|
+
cpu_val = resource.tr('^0-9.', '').to_i
|
282
288
|
mult = get_cpu_mult(resource)
|
283
|
-
cpu_val
|
289
|
+
cpu_val = cpu_val * mult
|
284
290
|
cpu_val
|
285
291
|
end
|
286
292
|
|
287
293
|
def get_memory_mult(memory)
|
288
|
-
memory_mult = if memory[-2] == 'Ki'
|
289
|
-
0.001
|
290
|
-
elsif memory[-2] == 'K'
|
294
|
+
memory_mult = if memory[-2..] == 'Ki'
|
291
295
|
1.0 / 1024
|
292
|
-
elsif memory[-
|
293
|
-
|
294
|
-
elsif memory[-2] == '
|
296
|
+
elsif memory[-1] == 'K'
|
297
|
+
1e3 / 1024 ** 2
|
298
|
+
elsif memory[-2..] == 'Mi'
|
295
299
|
1
|
296
|
-
elsif memory[-
|
297
|
-
|
298
|
-
elsif memory[-2] == '
|
300
|
+
elsif memory[-1] == 'M'
|
301
|
+
1e6 / 1024 ** 2
|
302
|
+
elsif memory[-2..] == 'Gi'
|
299
303
|
1024
|
300
|
-
elsif memory[-
|
301
|
-
|
302
|
-
elsif memory[-2] == '
|
303
|
-
|
304
|
-
elsif memory[-
|
305
|
-
|
304
|
+
elsif memory[-1] == 'G'
|
305
|
+
1e9 / 1024 ** 2
|
306
|
+
elsif memory[-2..] == 'Ti'
|
307
|
+
1024 ** 2
|
308
|
+
elsif memory[-1] == 'T'
|
309
|
+
1e12 / 1024 ** 2
|
310
|
+
elsif memory[-2..] == 'Pi'
|
311
|
+
1024**3
|
312
|
+
elsif memory[-2] == 'P'
|
313
|
+
1e15 / 1024 ** 2
|
314
|
+
elsif memory[-2..] == 'Ei'
|
315
|
+
1024**4
|
306
316
|
elsif memory[-2] == 'E'
|
307
|
-
|
317
|
+
1e18 / 1024 ** 2
|
308
318
|
else
|
309
|
-
0
|
319
|
+
1.0 / 1024 ** 2
|
310
320
|
end
|
311
321
|
memory_mult
|
312
322
|
end
|
313
323
|
|
314
324
|
def get_memory_value(resource)
|
315
|
-
mem_val = resource.tr('^0-9', '').to_i
|
325
|
+
mem_val = resource.tr('^0-9.', '').to_i
|
316
326
|
mult = get_memory_mult(resource)
|
317
|
-
mem_val
|
327
|
+
mem_val = mem_val * mult
|
318
328
|
mem_val
|
319
329
|
end
|
320
330
|
|
@@ -418,7 +428,7 @@ module Fluent
|
|
418
428
|
end
|
419
429
|
end
|
420
430
|
container_usage_metrics.add_usage_metrics(cpu_limit, cpu_request, memory_limit, memory_request)
|
421
|
-
container_labels = { 'name' => container_json['name'], 'image' => container_json['image'], 'node' => pod_json['spec']['nodeName'] }
|
431
|
+
container_labels = { 'pod-name' => pod_json['metadata']['name'], 'namespace' => pod_json['metadata']['namespace'], 'name' => container_json['name'], 'image' => container_json['image'], 'node' => pod_json['spec']['nodeName'] }
|
422
432
|
emit_limits_requests_metrics(generate_tag('container'), @scraped_at, container_labels, container_usage_metrics)
|
423
433
|
pod_usage_metrics.add_usage_metrics(cpu_limit, cpu_request, memory_limit, memory_request)
|
424
434
|
end
|
@@ -485,46 +495,53 @@ module Fluent
|
|
485
495
|
end
|
486
496
|
|
487
497
|
def process_node_response(response)
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
498
|
+
@mutex_node_req_lim.synchronize do
|
499
|
+
Array(response['items']).each do |node_json|
|
500
|
+
node_name = node_json['metadata']['name']
|
501
|
+
node_cpu_capacity = get_cpu_value(node_json['status']['capacity']['cpu'])
|
502
|
+
router.emit generate_tag('node') << ('.cpu.capacity'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_cpu_capacity
|
503
|
+
node_cpu_allocatable = get_cpu_value(node_json['status']['allocatable']['cpu'])
|
504
|
+
router.emit generate_tag('node') << ('.cpu.allocatable'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_cpu_allocatable
|
505
|
+
node_memory_capacity = get_memory_value(node_json['status']['capacity']['memory'])
|
506
|
+
router.emit generate_tag('node') << ('.memory.capacity'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_memory_capacity
|
507
|
+
node_memory_allocatable = get_memory_value(node_json['status']['allocatable']['memory'])
|
508
|
+
router.emit generate_tag('node') << ('.memory.allocatable'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_memory_allocatable
|
509
|
+
|
510
|
+
node_req_lim = UsageMetricsUnit.new
|
511
|
+
if @@node_requests_limits_metrics_map[node_name].nil?
|
512
|
+
next
|
513
|
+
end
|
504
514
|
node_req_lim = @@node_requests_limits_metrics_map[node_name]
|
515
|
+
|
516
|
+
node_cpu_reservation = node_req_lim.instance_variable_get(:@cpu_request).to_f / node_cpu_allocatable
|
517
|
+
router.emit generate_tag('node') << ('.cpu.reservation'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_cpu_reservation
|
518
|
+
node_memory_reservation = node_req_lim.instance_variable_get(:@memory_request).to_f / node_memory_allocatable
|
519
|
+
router.emit generate_tag('node') << ('.memory.reservation'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_memory_reservation
|
505
520
|
end
|
506
|
-
|
507
|
-
|
521
|
+
@@node_requests_limits_metrics_map = nil
|
522
|
+
@@node_requests_limits_metrics_map = {}
|
523
|
+
end
|
524
|
+
|
525
|
+
@mutex_node_res_usage.synchronize do
|
526
|
+
Array(response['items']).each do |node_json|
|
527
|
+
node_name = node_json['metadata']['name']
|
528
|
+
node_cpu_allocatable = get_cpu_value(node_json['status']['allocatable']['cpu'])
|
529
|
+
node_memory_allocatable = get_memory_value(node_json['status']['allocatable']['memory'])
|
508
530
|
|
531
|
+
node_res_usage = ResourceUsageMetricsUnit.new
|
532
|
+
if @@node_resource_usage_metrics_map[node_name].nil?
|
533
|
+
next
|
534
|
+
end
|
509
535
|
node_res_usage = @@node_resource_usage_metrics_map[node_name]
|
536
|
+
|
537
|
+
# https://github.com/kubernetes/heapster/blob/c78cc312ab3901acfe5c2f95f7a621909c8455ad/metrics/processors/node_autoscaling_enricher.go#L62
|
538
|
+
node_cpu_utilization = node_res_usage.instance_variable_get(:@cpu_usage).to_f / 1_000_000 * node_cpu_allocatable # converting from nano cores to milli core
|
539
|
+
router.emit generate_tag('node') << ('.cpu.utilization'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_cpu_utilization
|
540
|
+
node_memory_utilization = node_res_usage.instance_variable_get(:@memory_usage).to_f / node_memory_allocatable # converting from bytes to megabytes
|
541
|
+
router.emit generate_tag('node') << ('.memory.utilization'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_memory_utilization
|
510
542
|
end
|
511
|
-
|
512
|
-
|
513
|
-
router.emit generate_tag('node') << ('.cpu.utilization'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_cpu_utilization
|
514
|
-
node_cpu_reservation = node_req_lim.instance_variable_get(:@cpu_request).to_f / node_cpu_allocatable
|
515
|
-
router.emit generate_tag('node') << ('.cpu.reservation'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_cpu_reservation
|
516
|
-
node_memory_utilization = node_res_usage.instance_variable_get(:@memory_usage).to_f / 1_000_000 * node_memory_allocatable # converting from bytes to megabytes
|
517
|
-
router.emit generate_tag('node') << ('.memory.utilization'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_memory_utilization
|
518
|
-
node_memory_reservation = node_req_lim.instance_variable_get(:@memory_request).to_f / node_memory_allocatable
|
519
|
-
router.emit generate_tag('node') << ('.memory.reservation'), Fluent::EventTime.from_time(@scraped_node_at), 'node' => node_name, 'value' => node_memory_reservation
|
520
|
-
@mutex_node_req_lim.synchronize do
|
521
|
-
@@node_requests_limits_metrics_map = nil
|
522
|
-
@@node_requests_limits_metrics_map = {}
|
523
|
-
end
|
524
|
-
@mutex_node_res_usage.synchronize do
|
525
|
-
@@node_resource_usage_metrics_map = nil
|
526
|
-
@@node_resource_usage_metrics_map = {}
|
527
|
-
end
|
543
|
+
@@node_resource_usage_metrics_map = nil
|
544
|
+
@@node_resource_usage_metrics_map = {}
|
528
545
|
end
|
529
546
|
end
|
530
547
|
|
@@ -541,7 +558,7 @@ module Fluent
|
|
541
558
|
def scrape_resource_usage_metrics
|
542
559
|
response = resource_usage_api.get(@client.headers)
|
543
560
|
handle_resource_usage_response(response)
|
544
|
-
|
561
|
+
rescue StandardError => e
|
545
562
|
log.error "Failed to get resource usage metrics, error=#{$ERROR_INFO}, #{e.inspect}"
|
546
563
|
log.error_backtrace
|
547
564
|
end
|
@@ -573,16 +590,21 @@ module Fluent
|
|
573
590
|
end
|
574
591
|
end
|
575
592
|
|
576
|
-
|
593
|
+
begin
|
594
|
+
node_response = JSON.parse(node_rest_client.get(@client.headers))
|
595
|
+
rescue RestClient::ServiceUnavailable
|
596
|
+
log.warn("Couldn't scrap metric for node '#{node_name} as it is unavailable. Ignoring it.'")
|
597
|
+
next
|
598
|
+
end
|
599
|
+
|
577
600
|
Array(node_response['pods']).each do |pod_json|
|
578
601
|
unless pod_json['cpu'].nil? || pod_json['memory'].nil?
|
579
|
-
pod_cpu_usage = pod_json['cpu'].fetch('usageNanoCores', 0)/ 1_000_000
|
580
|
-
pod_memory_usage = pod_json['memory'].fetch('usageBytes', 0)
|
602
|
+
pod_cpu_usage = pod_json['cpu'].fetch('usageNanoCores', 0)/ 1_000_000.to_f
|
603
|
+
pod_memory_usage = pod_json['memory'].fetch('usageBytes', 0) / 1024 ** 2.to_f # Converting to Mi
|
581
604
|
pod_namespace = pod_json['podRef']['namespace']
|
582
605
|
pod_usage = ResourceUsageMetricsUnit.new
|
583
606
|
pod_usage.add_resource_usage_metrics(pod_cpu_usage, pod_memory_usage)
|
584
607
|
if @@namespace_resource_usage_metrics_map[pod_namespace].nil?
|
585
|
-
namespace_usage_metrics = ResourceUsageMetricsUnit.new
|
586
608
|
@@namespace_resource_usage_metrics_map[pod_namespace] = pod_usage
|
587
609
|
else
|
588
610
|
@@namespace_resource_usage_metrics_map[pod_namespace].add_resource_usage_metrics(pod_cpu_usage, pod_memory_usage)
|
@@ -594,6 +616,33 @@ module Fluent
|
|
594
616
|
@@node_resource_usage_metrics_map[node_name].add_resource_usage_metrics(pod_cpu_usage, pod_memory_usage)
|
595
617
|
pod_usage = nil
|
596
618
|
end
|
619
|
+
|
620
|
+
if pod_json['cpu'].nil? || pod_json['memory'].nil?
|
621
|
+
unless pod_json['containers'].nil?
|
622
|
+
pod_namespace = pod_json['podRef']['namespace']
|
623
|
+
Array(pod_json['containers']).each do |container_json|
|
624
|
+
unless container_json['cpu'].nil? || container_json['memory'].nil?
|
625
|
+
container_cpu_usage = container_json['cpu'].fetch('usageNanoCores', 0)/ 1_000_000.to_f
|
626
|
+
container_memory_usage = container_json['memory'].fetch('usageBytes', 0) / 1024 ** 2.to_f # Converting to Mi
|
627
|
+
container_usage = ResourceUsageMetricsUnit.new
|
628
|
+
container_usage.add_resource_usage_metrics(container_cpu_usage, container_memory_usage)
|
629
|
+
if @@namespace_resource_usage_metrics_map[pod_namespace].nil?
|
630
|
+
namespace_usage_metrics = ResourceUsageMetricsUnit.new
|
631
|
+
@@namespace_resource_usage_metrics_map[pod_namespace] = container_usage
|
632
|
+
else
|
633
|
+
@@namespace_resource_usage_metrics_map[pod_namespace].add_resource_usage_metrics(container_cpu_usage, container_memory_usage)
|
634
|
+
end
|
635
|
+
if @@node_resource_usage_metrics_map[node_name].nil?
|
636
|
+
node_name_usage_metrics = ResourceUsageMetricsUnit.new
|
637
|
+
@@node_resource_usage_metrics_map[node_name] = node_name_usage_metrics
|
638
|
+
else
|
639
|
+
@@node_resource_usage_metrics_map[node_name].add_resource_usage_metrics(container_cpu_usage, container_memory_usage)
|
640
|
+
end
|
641
|
+
container_usage = nil
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
end
|
597
646
|
end
|
598
647
|
end
|
599
648
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-k8s-metrics-agg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Splunk Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,13 +144,11 @@ executables: []
|
|
144
144
|
extensions: []
|
145
145
|
extra_rdoc_files: []
|
146
146
|
files:
|
147
|
-
- ".circleci/config.yml"
|
148
|
-
- ".circleci/install_dep.sh"
|
149
|
-
- ".circleci/trigger_func_test.sh"
|
150
147
|
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
151
148
|
- ".github/ISSUE_TEMPLATE/enhancement_request.md"
|
152
149
|
- ".github/ISSUE_TEMPLATE/failing_test.md"
|
153
150
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
151
|
+
- ".github/workflows/ci_build_test.yaml"
|
154
152
|
- ".gitignore"
|
155
153
|
- CLA.md
|
156
154
|
- CONTRIBUTING.md
|
@@ -162,6 +160,9 @@ files:
|
|
162
160
|
- README.md
|
163
161
|
- Rakefile
|
164
162
|
- VERSION
|
163
|
+
- ci_scripts/deploy_connector.sh
|
164
|
+
- ci_scripts/install_dep.sh
|
165
|
+
- ci_scripts/k8s-splunk.yml
|
165
166
|
- docker/CONTRIBUTING.md
|
166
167
|
- docker/Dockerfile
|
167
168
|
- docker/Gemfile
|
@@ -185,7 +186,7 @@ homepage: https://github.com/splunk/fluent-plugin-k8s-metrics-agg
|
|
185
186
|
licenses:
|
186
187
|
- Apache-2.0
|
187
188
|
metadata: {}
|
188
|
-
post_install_message:
|
189
|
+
post_install_message:
|
189
190
|
rdoc_options: []
|
190
191
|
require_paths:
|
191
192
|
- lib
|
@@ -200,8 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
201
|
- !ruby/object:Gem::Version
|
201
202
|
version: '0'
|
202
203
|
requirements: []
|
203
|
-
rubygems_version: 3.1.
|
204
|
-
signing_key:
|
204
|
+
rubygems_version: 3.1.4
|
205
|
+
signing_key:
|
205
206
|
specification_version: 4
|
206
207
|
summary: A fluentd input plugin that collects kubernetes cluster metrics.
|
207
208
|
test_files:
|
data/.circleci/config.yml
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
version: 2
|
2
|
-
jobs:
|
3
|
-
build:
|
4
|
-
docker:
|
5
|
-
- image: circleci/ruby:2.6.1-node-browsers
|
6
|
-
working_directory: ~/repo
|
7
|
-
steps:
|
8
|
-
- checkout
|
9
|
-
- setup_remote_docker:
|
10
|
-
reusable: true
|
11
|
-
- run:
|
12
|
-
name: Install dependencies
|
13
|
-
command: |
|
14
|
-
.circleci/install_dep.sh
|
15
|
-
- run:
|
16
|
-
name: Builder
|
17
|
-
command: |
|
18
|
-
rake build -t -v
|
19
|
-
cp -R pkg /tmp
|
20
|
-
- persist_to_workspace:
|
21
|
-
root: /tmp
|
22
|
-
paths:
|
23
|
-
- pkg
|
24
|
-
|
25
|
-
unit_test:
|
26
|
-
docker:
|
27
|
-
- image: circleci/ruby:2.6.1-node-browsers
|
28
|
-
working_directory: ~/repo
|
29
|
-
steps:
|
30
|
-
- attach_workspace:
|
31
|
-
at: /tmp
|
32
|
-
- checkout
|
33
|
-
- setup_remote_docker:
|
34
|
-
reusable: true
|
35
|
-
- run:
|
36
|
-
name: Install dependencies
|
37
|
-
command: |
|
38
|
-
.circleci/install_dep.sh
|
39
|
-
- run:
|
40
|
-
name: Run unit tests
|
41
|
-
command: |
|
42
|
-
bundle exec rake test -t -v
|
43
|
-
|
44
|
-
func_test_main:
|
45
|
-
docker:
|
46
|
-
- image: circleci/ruby:2.6.1-node-browsers
|
47
|
-
working_directory: ~/repo
|
48
|
-
steps:
|
49
|
-
- checkout
|
50
|
-
- setup_remote_docker:
|
51
|
-
reusable: true
|
52
|
-
- run:
|
53
|
-
name: trigger
|
54
|
-
command: |
|
55
|
-
.circleci/trigger_func_test.sh main
|
56
|
-
|
57
|
-
func_test_develop:
|
58
|
-
docker:
|
59
|
-
- image: circleci/ruby:2.6.1-node-browsers
|
60
|
-
working_directory: ~/repo
|
61
|
-
steps:
|
62
|
-
- checkout
|
63
|
-
- setup_remote_docker:
|
64
|
-
reusable: true
|
65
|
-
- run:
|
66
|
-
name: trigger
|
67
|
-
command: |
|
68
|
-
.circleci/trigger_func_test.sh develop
|
69
|
-
|
70
|
-
workflows:
|
71
|
-
version: 2
|
72
|
-
build_test_push:
|
73
|
-
jobs:
|
74
|
-
- build:
|
75
|
-
filters:
|
76
|
-
branches:
|
77
|
-
ignore:
|
78
|
-
- /^release\/.*/
|
79
|
-
- main
|
80
|
-
- unit_test:
|
81
|
-
requires:
|
82
|
-
- build
|
83
|
-
- func_test_main:
|
84
|
-
requires:
|
85
|
-
- unit_test
|
86
|
-
- func_test_develop:
|
87
|
-
requires:
|
88
|
-
- unit_test
|
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# trigger SCK 'main' branch to introduce this new image from this commit
|
4
|
-
# to working version of every other component.
|
5
|
-
ORGANIZATION=splunk
|
6
|
-
PROJECT=splunk-connect-for-kubernetes
|
7
|
-
BRANCH=$1
|
8
|
-
|
9
|
-
# Trigger functional test
|
10
|
-
curl -X POST --header "Content-Type: application/json" \
|
11
|
-
-d '{"build_parameters": {"CIRCLE_JOB":"build_test", "TRIG_BRANCH":"'"$CIRCLE_BRANCH"'", "TRIG_PROJECT":"'"$CIRCLE_PROJECT_REPONAME"'", "TRIG_REPO":"'"$CIRCLE_REPOSITORY_URL"'"}}' "https://circleci.com/api/v1/project/$ORGANIZATION/$PROJECT/tree/$BRANCH?circle-token=$CIRCLE_TOKEN" > build.json
|
12
|
-
cat build.json
|
13
|
-
BUILD_NUM=$(jq -r .build_num build.json)
|
14
|
-
sleep 10
|
15
|
-
|
16
|
-
# Wait until finish or maximum 20 minutes
|
17
|
-
TIMEOUT=20
|
18
|
-
DONE="FALSE"
|
19
|
-
until [ "$TIMEOUT" -lt 0 ] || [ "$DONE" == "TRUE" ]; do
|
20
|
-
curl https://circleci.com/api/v1/project/$ORGANIZATION/$PROJECT/$BUILD_NUM?circle-token=$CIRCLE_TOKEN > build_progress.json
|
21
|
-
STATUS=$(jq -r .status build_progress.json)
|
22
|
-
echo "STATUS = $STATUS"
|
23
|
-
if [ "$STATUS" != "running" ] && [ "$STATUS" != "queued" ]; then
|
24
|
-
DONE="TRUE"
|
25
|
-
else
|
26
|
-
let TIMEOUT--
|
27
|
-
sleep 60
|
28
|
-
fi
|
29
|
-
done
|
30
|
-
|
31
|
-
BUILD_URL=$(jq -r .build_url build_progress.json)
|
32
|
-
if [ "$DONE" == "FALSE" ]; then
|
33
|
-
# Cancel hanging job and fail
|
34
|
-
curl -X POST https://circleci.com/api/v1/project/$ORGANIZATION/$PROJECT/$BUILD_NUM/cancel?circle-token=$CIRCLE_TOKEN
|
35
|
-
else
|
36
|
-
if [ "$STATUS" != "success" ] && [ "$STATUS" != "fixed" ]; then
|
37
|
-
echo "Functional test have failed please see:"
|
38
|
-
echo $BUILD_URL
|
39
|
-
exit 1
|
40
|
-
fi
|
41
|
-
exit 0
|
42
|
-
fi
|