1 From 4f42518e2e15a65e340e15029c50b53b20e119e9 Mon Sep 17 00:00:00 2001
2 From: Kevin Smith <kevin.smith@windriver.com>
3 Date: Sat, 14 Sep 2019 12:10:44 -0400
4 Subject: [PATCH 1/1] add system info
7 stable/filebeat/templates/configmap.yaml | 22 ++++++++++++++---
8 stable/filebeat/templates/daemonset.yaml | 36 ++++++++++++++++++++++++++++
9 stable/filebeat/values.yaml | 4 ++++
10 stable/logstash/templates/statefulset.yaml | 10 ++++++++
11 stable/logstash/values.yaml | 3 +++
12 stable/metricbeat/templates/configmap.yaml | 22 ++++++++++++++---
13 stable/metricbeat/templates/daemonset.yaml | 37 ++++++++++++++++++++++++++++-
14 stable/metricbeat/templates/deployment.yaml | 18 ++++++++++++++
15 stable/metricbeat/values.yaml | 4 ++++
16 9 files changed, 149 insertions(+), 7 deletions(-)
18 diff --git a/stable/filebeat/templates/configmap.yaml b/stable/filebeat/templates/configmap.yaml
19 index 8377e5a..c08a4bc 100644
20 --- a/stable/filebeat/templates/configmap.yaml
21 +++ b/stable/filebeat/templates/configmap.yaml
22 @@ -18,7 +18,9 @@ data:
23 BEAT_VER=$($BEAT version | awk '{print $3}')
25 ADDR=$OUTPUT_ELASTICSEARCH_HOSTS
27 + ESPATH=$OUTPUT_ELASTICSEARCH_PATH
31 # Check if this is a map of entries. If so, we'll only export the template
32 # to the first address
33 @@ -28,7 +30,7 @@ data:
34 # Take the first entry in case there are more than one
40 # Check if user has formatted with http:// on front, if not we need to add
42 @@ -53,7 +55,21 @@ data:
43 # remove the lifecycle section of the yaml, as elasticsearch will choke
44 # on it as oss version does not support ilm.
45 sed -i '/lifecycle/,+3d' /tmp/beat.template.json
46 - curl -v $CURL_G -XPUT -H "Content-Type: application/json" $HTTP$ADDR/_template/$BEAT-$BEAT_VER -d@/tmp/beat.template.json
48 + # "unset" is the special system name when none has been set through
49 + # overrides.. We key on that to know what template name and index pattern to set
50 + if [[ $SYSTEM_NAME_FOR_INDEX != unset ]]; then
51 + # replace the standard index pattern with one including our system name,
52 + # which will match our created indices
53 + sed -i "s/$BEAT-$BEAT_VER/$BEAT-$BEAT_VER$SYSTEM_NAME_FOR_INDEX/g" /tmp/beat.template.json
54 + # give the template a name with the system name appended.
55 + curl -v $CURL_G -XPUT -H "Content-Type: application/json" $HTTP$ADDR$ESPATH/_template/$BEAT-$BEAT_VER$SYSTEM_NAME_FOR_INDEX -d@/tmp/beat.template.json
57 + # apply a higher order to this template in case there are templates with system names
58 + # which should be applied first
59 + sed -i "s/\"order\": 1/\"order\": 2/g" /tmp/beat.template.json
60 + curl -v $CURL_G -XPUT -H "Content-Type: application/json" $HTTP$ADDR$ESPATH/_template/$BEAT-$BEAT_VER -d@/tmp/beat.template.json
63 echo "logstash not configured, not exporting template, should be done for us."
65 diff --git a/stable/filebeat/templates/daemonset.yaml b/stable/filebeat/templates/daemonset.yaml
66 index b8536fb..b1833a9 100644
67 --- a/stable/filebeat/templates/daemonset.yaml
68 +++ b/stable/filebeat/templates/daemonset.yaml
69 @@ -64,6 +64,24 @@ spec:
73 + ## make system name and index parms visible
74 + {{- if .Values.systemNameForIndex}}
75 + {{ $systemNameNoSpecial := regexReplaceAll "[^A-Za-z0-9-]+" .Values.systemNameForIndex "" }}
76 + {{ $systemNameFormatted := $systemNameNoSpecial | lower | trunc 200 }}
77 + - name: SYSTEM_NAME_FOR_INDEX
78 + value: {{ printf "-%s" $systemNameFormatted | quote }}
79 + - name: INDEX_PATTERN
80 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}-*"
82 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}"
84 + - name: SYSTEM_NAME_FOR_INDEX
86 + - name: INDEX_PATTERN
87 + value: "{{ .Values.indexNamePrefix }}-*"
89 + value: "{{ .Values.indexNamePrefix }}"
91 {{- if .Values.indexTemplateLoad }}
92 - name: "load-es-template"
93 image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
94 @@ -116,6 +134,24 @@ spec:
98 + ## make system name and index parms visible
99 + {{- if .Values.systemNameForIndex}}
100 + {{ $systemNameNoSpecial := regexReplaceAll "[^A-Za-z0-9-]+" .Values.systemNameForIndex "" }}
101 + {{ $systemNameFormatted := $systemNameNoSpecial | lower | trunc 200 }}
102 + - name: SYSTEM_NAME_FOR_INDEX
103 + value: {{ printf "-%s" $systemNameFormatted | quote }}
104 + - name: INDEX_PATTERN
105 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}-*"
107 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}"
109 + - name: SYSTEM_NAME_FOR_INDEX
111 + - name: INDEX_PATTERN
112 + value: "{{ .Values.indexNamePrefix }}-*"
114 + value: "{{ .Values.indexNamePrefix }}"
116 {{- if .Values.extraVars }}
117 {{ toYaml .Values.extraVars | indent 8 }}
119 diff --git a/stable/filebeat/values.yaml b/stable/filebeat/values.yaml
120 index b4b766f..3897c82 100644
121 --- a/stable/filebeat/values.yaml
122 +++ b/stable/filebeat/values.yaml
123 @@ -68,6 +68,10 @@ extraVars: []
127 +# Will be used in index name
128 +systemNameForIndex: ""
129 +indexNamePrefix: filebeat-%{[agent.version]}
131 # Add additional volumes and mounts, for example to read other log files on the host
134 diff --git a/stable/logstash/templates/statefulset.yaml b/stable/logstash/templates/statefulset.yaml
135 index cca0050..070ef56 100644
136 --- a/stable/logstash/templates/statefulset.yaml
137 +++ b/stable/logstash/templates/statefulset.yaml
138 @@ -71,6 +71,16 @@ spec:
139 value: {{ .Values.elasticsearch.host | quote }}
140 - name: ELASTICSEARCH_PORT
141 value: {{ .Values.elasticsearch.port | quote }}
142 + ## make system name visible for in setting index.
143 + {{- if .Values.systemNameForIndex}}
144 + {{ $systemNameNoSpecial := regexReplaceAll "[^A-Za-z0-9-]+" .Values.systemNameForIndex "" }}
145 + {{ $systemNameFormatted := $systemNameNoSpecial | lower | trunc 200 }}
146 + - name: SYSTEM_NAME_FOR_INDEX
147 + value: {{ printf "-%s" $systemNameFormatted | quote }}
149 + - name: SYSTEM_NAME_FOR_INDEX
152 ## Additional env vars
153 {{- range $key, $value := .Values.config }}
154 - name: {{ $key | upper | replace "." "_" }}
155 diff --git a/stable/logstash/values.yaml b/stable/logstash/values.yaml
156 index 9a452b1..9ba80c9 100644
157 --- a/stable/logstash/values.yaml
158 +++ b/stable/logstash/values.yaml
159 @@ -220,6 +220,9 @@ patterns:
161 # TESTING {"foo":.*}$
163 +# Will be used in index names
164 +systemNameForIndex: ""
166 ## Custom files that can be referenced by plugins.
167 ## Each YAML heredoc will become located in the logstash home directory under
168 ## the files subdirectory.
169 diff --git a/stable/metricbeat/templates/configmap.yaml b/stable/metricbeat/templates/configmap.yaml
170 index 4249e7f..9ae276d 100644
171 --- a/stable/metricbeat/templates/configmap.yaml
172 +++ b/stable/metricbeat/templates/configmap.yaml
173 @@ -18,7 +18,9 @@ data:
174 BEAT_VER=$($BEAT version | awk '{print $3}')
176 ADDR=$OUTPUT_ELASTICSEARCH_HOSTS
178 + ESPATH=$OUTPUT_ELASTICSEARCH_PATH
182 # Check if this is a map of entries. If so, we'll only export the template
183 # to the first address
184 @@ -28,7 +30,7 @@ data:
185 # Take the first entry in case there are more than one
191 # Check if user has formatted with http:// on front, if not we need to add
193 @@ -53,7 +55,21 @@ data:
194 # remove the lifecycle section of the yaml, as elasticsearch will choke
195 # on it as oss version does not support ilm.
196 sed -i '/lifecycle/,+3d' /tmp/beat.template.json
197 - curl -v $CURL_G -XPUT -H "Content-Type: application/json" $HTTP$ADDR/_template/$BEAT-$BEAT_VER -d@/tmp/beat.template.json
199 + # "unset" is the special system name when none has been set through
200 + # overrides.. We key on that to know what template name and index pattern to set
201 + if [[ $SYSTEM_NAME_FOR_INDEX != unset ]]; then
202 + # replace the standard index pattern with one including our system name,
203 + # which will match our created indices
204 + sed -i "s/$BEAT-$BEAT_VER/$BEAT-$BEAT_VER$SYSTEM_NAME_FOR_INDEX/g" /tmp/beat.template.json
205 + # give the template a name with the system name appended.
206 + curl -v $CURL_G -XPUT -H "Content-Type: application/json" $HTTP$ADDR$ESPATH/_template/$BEAT-$BEAT_VER$SYSTEM_NAME_FOR_INDEX -d@/tmp/beat.template.json
208 + # apply a higher order to this template in case there are templates with system names
209 + # which should be applied first
210 + sed -i "s/\"order\": 1/\"order\": 2/g" /tmp/beat.template.json
211 + curl -v $CURL_G -XPUT -H "Content-Type: application/json" $HTTP$ADDR$ESPATH/_template/$BEAT-$BEAT_VER -d@/tmp/beat.template.json
214 echo "logstash not configured, not exporting template, should be done for us."
216 diff --git a/stable/metricbeat/templates/daemonset.yaml b/stable/metricbeat/templates/daemonset.yaml
217 index 1ae3a34..947e501 100644
218 --- a/stable/metricbeat/templates/daemonset.yaml
219 +++ b/stable/metricbeat/templates/daemonset.yaml
220 @@ -59,7 +59,24 @@ spec:
225 + ## make system name and index parms visible
226 + {{- if .Values.systemNameForIndex}}
227 + {{ $systemNameNoSpecial := regexReplaceAll "[^A-Za-z0-9-]+" .Values.systemNameForIndex "" }}
228 + {{ $systemNameFormatted := $systemNameNoSpecial | lower | trunc 200 }}
229 + - name: SYSTEM_NAME_FOR_INDEX
230 + value: {{ printf "-%s" $systemNameFormatted | quote }}
231 + - name: INDEX_PATTERN
232 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}-*"
234 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}"
236 + - name: SYSTEM_NAME_FOR_INDEX
238 + - name: INDEX_PATTERN
239 + value: "{{ .Values.indexNamePrefix }}-*"
241 + value: "{{ .Values.indexNamePrefix }}"
244 - name: {{ .Chart.Name }}
245 image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
246 @@ -94,6 +111,24 @@ spec:
250 + ## make system name and index parms visible
251 + {{- if .Values.systemNameForIndex}}
252 + {{ $systemNameNoSpecial := regexReplaceAll "[^A-Za-z0-9-]+" .Values.systemNameForIndex "" }}
253 + {{ $systemNameFormatted := $systemNameNoSpecial | lower | trunc 200 }}
254 + - name: SYSTEM_NAME_FOR_INDEX
255 + value: {{ printf "-%s" $systemNameFormatted | quote }}
256 + - name: INDEX_PATTERN
257 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}-*"
259 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}"
261 + - name: SYSTEM_NAME_FOR_INDEX
263 + - name: INDEX_PATTERN
264 + value: "{{ .Values.indexNamePrefix }}-*"
266 + value: "{{ .Values.indexNamePrefix }}"
268 {{- if .Values.extraEnv }}
269 {{ toYaml .Values.extraEnv | indent 8 }}
271 diff --git a/stable/metricbeat/templates/deployment.yaml b/stable/metricbeat/templates/deployment.yaml
272 index 47ada04..d1d08e3 100644
273 --- a/stable/metricbeat/templates/deployment.yaml
274 +++ b/stable/metricbeat/templates/deployment.yaml
275 @@ -55,6 +55,24 @@ spec:
278 fieldPath: spec.nodeName
279 + ## make system name and index parms visible
280 + {{- if .Values.systemNameForIndex}}
281 + {{ $systemNameNoSpecial := regexReplaceAll "[^A-Za-z0-9-]+" .Values.systemNameForIndex "" }}
282 + {{ $systemNameFormatted := $systemNameNoSpecial | lower | trunc 200 }}
283 + - name: SYSTEM_NAME_FOR_INDEX
284 + value: {{ printf "-%s" $systemNameFormatted | quote }}
285 + - name: INDEX_PATTERN
286 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}-*"
288 + value: "{{ .Values.indexNamePrefix }}-{{$systemNameFormatted}}"
290 + - name: SYSTEM_NAME_FOR_INDEX
292 + - name: INDEX_PATTERN
293 + value: "{{ .Values.indexNamePrefix }}-*"
295 + value: "{{ .Values.indexNamePrefix }}"
297 {{- if .Values.extraEnv }}
298 {{ toYaml .Values.extraEnv | indent 8 }}
300 diff --git a/stable/metricbeat/values.yaml b/stable/metricbeat/values.yaml
301 index c8f758c..b59c428 100644
302 --- a/stable/metricbeat/values.yaml
303 +++ b/stable/metricbeat/values.yaml
304 @@ -130,6 +130,10 @@ extraEnv:
308 +# Will be used in index name
309 +systemNameForIndex: ""
310 +indexNamePrefix: metricbeat-%{[agent.version]}
312 # Add additional volumes and mounts, for example to read other log files on the host