Skip to content

Commit fa8d780

Browse files
author
alxf
authored
Merge pull request #223 from scality/improvement/kibana-index
Pre-provision Kibana index configuration
2 parents 99409fd + af844d7 commit fa8d780

File tree

8 files changed

+141
-0
lines changed

8 files changed

+141
-0
lines changed

ChangeLog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Kubespray
2626

2727
:ghpull:`218` - update versions of Kibana and `fluent-bit`
2828

29+
:ghpull:`223` - pre-provision Kibana index configuration (:ghissue:`174`)
30+
2931
Bugs fixed
3032
----------
3133
:ghissue:`220` - 'Kubernetes Calico (Alternative)' dashboard doesn't work (:ghpull:`221`)

roles/cluster_logging/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ kibana_version: '0.10.0'
3737
kibana_repo: 'https://kubernetes-charts.storage.googleapis.com'
3838
kibana_namespace: 'kube-ops'
3939
kibana_release_name: 'kibana'
40+
kibana_addons_dir: '/etc/kubernetes/addons/kibana'
4041

4142
elasticsearch_exporter_chart: 'elasticsearch-exporter'
4243
elasticsearch_exporter_version: '0.2.0'
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
3+
#
4+
# Script to setup the default index pattern in kibana
5+
#
6+
7+
set -ue
8+
9+
INDEX_ID="logstash-*"
10+
11+
API_HOSTNAME="$KIBANA_SERVICE_HOST:$KIBANA_SERVICE_PORT"
12+
13+
COUNTDOWN=10
14+
SLEEP_DELAY=5
15+
16+
set_index_pattern()
17+
{
18+
curl -s -o /dev/null -w "%{http_code}" \
19+
-XPOST \
20+
-H "Content-type: application/json" \
21+
-H "kbn-xsrf: anything" \
22+
"http://$API_HOSTNAME/api/saved_objects/index-pattern/$INDEX_ID" \
23+
-d "{\"attributes\": {\"title\": \"$INDEX_ID\", \"timeFieldName\": \"@timestamp\"}}"
24+
}
25+
26+
set_default_index()
27+
{
28+
curl -s -o /dev/null -w "%{http_code}" \
29+
-XPOST \
30+
-H "Content-type: application/json" \
31+
-H "kbn-xsrf: anything" \
32+
"http://$API_HOSTNAME/api/kibana/settings/defaultIndex" \
33+
-d "{\"value\": \"$INDEX_ID\"}"
34+
}
35+
36+
37+
# Wait for kibana service to be ready
38+
while [ "$COUNTDOWN" -gt 0 ]; do
39+
http_code=$(curl -s -o /dev/null -w "%{http_code}" "$API_HOSTNAME")
40+
if [ "$http_code" = "200" ]; then
41+
break
42+
else
43+
COUNTDOWN=$((COUNTDOWN - 1))
44+
if [ "$COUNTDOWN" -le 0 ]; then
45+
echo "Error: Can't connect to the Kibana API server"
46+
exit 1
47+
else
48+
sleep $SLEEP_DELAY
49+
fi
50+
fi
51+
done
52+
53+
http_code=$(set_index_pattern)
54+
55+
if [ "$http_code" = "409" ]; then
56+
echo "Index pattern '$INDEX_ID' is already registered"
57+
elif [ "$http_code" != "200" ]; then
58+
echo "Error: An error occurred when trying to set the Kibana index pattern (http code: $http_code)"
59+
exit 1
60+
fi
61+
62+
http_code=$(set_default_index)
63+
64+
if [ "$http_code" != "200" ]; then
65+
echo "Error: An error occurred when trying to set the default Kibana index (http code: $http_code)"
66+
exit 1
67+
fi
68+
69+
echo "Successful registered '$INDEX_ID' as Kibana index pattern"

roles/cluster_logging/files/kibana/values.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ service:
66
env:
77
ELASTICSEARCH_URL: 'http://elasticsearch-client:9200'
88
SERVER_BASEPATH: '/api/v1/namespaces/kube-ops/services/http:kibana:/proxy'
9+
SERVER_DEFAULTROUTE: '/app/kibana#/discover'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
3+
- name: 'create remote addons directory'
4+
file:
5+
state: directory
6+
path: '{{ kibana_addons_dir }}'
7+
8+
- name: 'push addons files'
9+
template:
10+
src: '{{ item }}.j2'
11+
dest: '{{ kibana_addons_dir }}/{{ item }}'
12+
register: kibana_setup_manifests
13+
with_items:
14+
- kibana-index-provisioning-configmap.yml
15+
- kibana-index-provisioning-job.yml
16+
17+
- name: 'apply the Kibana job setup'
18+
run_once: true
19+
kube:
20+
kubectl: '{{ bin_dir }}/kubectl'
21+
filename: '{{ item.dest }}'
22+
namespace: '{{ kibana_namespace }}'
23+
state: 'latest'
24+
with_items: '{{ kibana_setup_manifests.results | default([]) }}'

roles/cluster_logging/tasks/kibana.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232
dest: '{{ kibana_values_file.path }}'
3333
state: absent
3434
when: remove_metal_k8s_temporary_file|bool
35+
36+
- name: 'include Kibana index provisioning job'
37+
import_tasks: kibana-index-provisioning.yml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: kibana-index-provisioning
5+
labels:
6+
app: kibana
7+
heritage: MetalK8s
8+
component: index-provisioning
9+
data:
10+
provision-index.sh: |-
11+
{{ lookup('file', role_path ~ '/files/kibana/provision-index.sh') | indent(8) }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: kibana-index-provisioning
5+
labels:
6+
app: kibana
7+
heritage: MetalK8s
8+
component: index-provisioning
9+
spec:
10+
template:
11+
metadata:
12+
name: kibana-index-provisioning
13+
labels:
14+
app: kibana
15+
heritage: MetalK8s
16+
component: index-provisioning
17+
spec:
18+
containers:
19+
- name: provision-index
20+
image: appropriate/curl
21+
command: ['sh', '/scripts/provision-index.sh']
22+
volumeMounts:
23+
- name: scripts
24+
mountPath: /scripts
25+
readOnly: true
26+
restartPolicy: OnFailure
27+
volumes:
28+
- name: scripts
29+
configMap:
30+
name: kibana-index-provisioning

0 commit comments

Comments
 (0)