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

script to add dashboards and other Kibana UI objects #518

Merged
merged 1 commit into from Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions elasticsearch/Dockerfile
Expand Up @@ -42,6 +42,8 @@ RUN rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch && \
ADD sgconfig/ ${HOME}/sgconfig/
ADD index_templates/ /usr/share/elasticsearch/index_templates/
ADD index_patterns/ /usr/share/elasticsearch/index_patterns/
ADD kibana_ui_objects/ /usr/share/elasticsearch/kibana_ui_objects/

ADD probe/ /usr/share/elasticsearch/probe/
ADD install.sh ${HOME}/
RUN ${HOME}/install.sh
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -190,6 +190,22 @@
},
"kubernetes": {
"properties": {
"container_name": {
"doc_values": true,
"fields": {
"raw": {
"doc_values": true,
"ignore_above": 256,
"index": "not_analyzed",
"type": "string"
}
},
"index": "not_analyzed",
"norms": {
"enabled": true
},
"type": "string"
},
"host": {
"doc_values": true,
"index": "not_analyzed",
Expand All @@ -198,6 +214,38 @@
},
"type": "string"
},
"labels": {
"properties": {
"component": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
},
"deployment": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
},
"deploymentconfig": {
"doc_values": true,
"fields": {
"raw": {
"doc_values": true,
"ignore_above": 64,
"index": "not_analyzed",
"type": "string"
}
},
"index": "not_analyzed",
"type": "string"
},
"provider": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
}
}
},
"master_url": {
"doc_values": true,
"index": "not_analyzed",
Expand Down
Expand Up @@ -190,6 +190,22 @@
},
"kubernetes": {
"properties": {
"container_name": {
"doc_values": true,
"fields": {
"raw": {
"doc_values": true,
"ignore_above": 256,
"index": "not_analyzed",
"type": "string"
}
},
"index": "not_analyzed",
"norms": {
"enabled": true
},
"type": "string"
},
"host": {
"doc_values": true,
"index": "not_analyzed",
Expand All @@ -198,6 +214,38 @@
},
"type": "string"
},
"labels": {
"properties": {
"component": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
},
"deployment": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
},
"deploymentconfig": {
"doc_values": true,
"fields": {
"raw": {
"doc_values": true,
"ignore_above": 64,
"index": "not_analyzed",
"type": "string"
}
},
"index": "not_analyzed",
"type": "string"
},
"provider": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
}
}
},
"master_url": {
"doc_values": true,
"index": "not_analyzed",
Expand Down
Expand Up @@ -875,6 +875,22 @@
},
"kubernetes": {
"properties": {
"container_name": {
"doc_values": true,
"fields": {
"raw": {
"doc_values": true,
"ignore_above": 256,
"index": "not_analyzed",
"type": "string"
}
},
"index": "not_analyzed",
"norms": {
"enabled": true
},
"type": "string"
},
"host": {
"doc_values": true,
"index": "not_analyzed",
Expand All @@ -883,6 +899,38 @@
},
"type": "string"
},
"labels": {
"properties": {
"component": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
},
"deployment": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
},
"deploymentconfig": {
"doc_values": true,
"fields": {
"raw": {
"doc_values": true,
"ignore_above": 64,
"index": "not_analyzed",
"type": "string"
}
},
"index": "not_analyzed",
"type": "string"
},
"provider": {
"doc_values": true,
"index": "not_analyzed",
"type": "string"
}
}
},
"master_url": {
"doc_values": true,
"index": "not_analyzed",
Expand Down
21 changes: 21 additions & 0 deletions elasticsearch/kibana_ui_objects/k8s-dashboard.json
@@ -0,0 +1,21 @@
[
{
"_id": "Kubernetes-Overview",
"_type": "dashboard",
"_source": {
"title": "Kubernetes Overview",
"hits": 0,
"description": "",
"panelsJSON": "[{\"id\":\"Kubernetes-Logs-by-Namespace,-DC,-Pod,-Container\",\"type\":\"visualization\",\"panelIndex\":1,\"size_x\":4,\"size_y\":4,\"col\":1,\"row\":1},{\"id\":\"Kubernetes-Logs-over-Time-w-slash-Container-Name\",\"type\":\"visualization\",\"panelIndex\":2,\"size_x\":8,\"size_y\":4,\"col\":5,\"row\":1},{\"id\":\"k8s-logs\",\"type\":\"search\",\"panelIndex\":3,\"size_x\":12,\"size_y\":18,\"col\":1,\"row\":5,\"columns\":[\"kubernetes.namespace_name\",\"kubernetes.labels.deploymentconfig\",\"kubernetes.pod_name\",\"kubernetes.container_name\",\"message\"],\"sort\":[\"@timestamp\",\"desc\"]}]",
"optionsJSON": "{\"darkTheme\":false}",
"uiStateJSON": "{}",
"version": 1,
"timeRestore": true,
"timeTo": "now",
"timeFrom": "now-1h/h",
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"filter\":[{\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}}}]}"
}
}
}
]
26 changes: 26 additions & 0 deletions elasticsearch/kibana_ui_objects/k8s-search.json
@@ -0,0 +1,26 @@
[
{
"_id": "k8s-logs",
"_type": "search",
"_source": {
"title": "k8s-logs",
"description": "",
"hits": 0,
"columns": [
"kubernetes.namespace_name",
"kubernetes.labels.deploymentconfig",
"kubernetes.pod_name",
"kubernetes.container_name",
"message"
],
"sort": [
"@timestamp",
"desc"
],
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"project.*\",\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}},\"filter\":[],\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}},\"require_field_match\":false,\"fragment_size\":2147483647}}"
}
}
}
]
32 changes: 32 additions & 0 deletions elasticsearch/kibana_ui_objects/k8s-visualizations.json
@@ -0,0 +1,32 @@
[
{
"_id": "Kubernetes-Logs-by-Namespace,-DC,-Pod,-Container",
"_type": "visualization",
"_source": {
"title": "Kubernetes Logs by Namespace, DC, Pod, Container",
"visState": "{\"title\":\"New Visualization\",\"type\":\"pie\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"isDonut\":false},\"aggs\":[{\"id\":\"1\",\"type\":\"count\",\"schema\":\"metric\",\"params\":{}},{\"id\":\"2\",\"type\":\"terms\",\"schema\":\"segment\",\"params\":{\"field\":\"kubernetes.namespace_name\",\"size\":50,\"order\":\"desc\",\"orderBy\":\"1\"}},{\"id\":\"3\",\"type\":\"terms\",\"schema\":\"segment\",\"params\":{\"field\":\"kubernetes.labels.deploymentconfig.raw\",\"size\":50,\"order\":\"desc\",\"orderBy\":\"1\"}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"segment\",\"params\":{\"field\":\"kubernetes.pod_name\",\"size\":50,\"order\":\"desc\",\"orderBy\":\"1\"}},{\"id\":\"5\",\"type\":\"terms\",\"schema\":\"segment\",\"params\":{\"field\":\"kubernetes.container_name.raw\",\"size\":50,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}",
"uiStateJSON": "{}",
"description": "",
"savedSearchId": "k8s-logs",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"filter\":[]}"
}
}
},
{
"_id": "Kubernetes-Logs-over-Time-w-slash-Container-Name",
"_type": "visualization",
"_source": {
"title": "Kubernetes Logs over Time w/ Container Name",
"visState": "{\"title\":\"New Visualization\",\"type\":\"histogram\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"scale\":\"linear\",\"mode\":\"stacked\",\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"count\",\"schema\":\"metric\",\"params\":{}},{\"id\":\"2\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"kubernetes.container_name.raw\",\"size\":25,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}",
"uiStateJSON": "{}",
"description": "",
"savedSearchId": "k8s-logs",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"filter\":[]}"
}
}
}
]
67 changes: 67 additions & 0 deletions elasticsearch/utils/es_load_kibana_ui_objects
@@ -0,0 +1,67 @@
#!/bin/bash -e

source "logging"

set -euo pipefail

if [ -n "${DEBUG:-}" -o $loglevelint = 7 ] ; then
set -x
curl_output() {
python -mjson.tool
}
else
curl_output() {
cat > /dev/null 2>&1
}
fi

usage() {
error Usage: $0 user-name
error The kibana index for the given user must already exist
}

if [ -z "${1:-}" ] ; then
usage
exit 1
fi

kibindex=$( get_kibana_index_name "$1" )

resp_code=$( QUERY="/$kibindex" es_util -XHEAD -w '%{response_code}' )

if [ "$resp_code" != 200 ] ; then
error Could not find kibana index $kibindex for user $1: $resp_code
exit 1
fi

info Adding Kibana dashboards and other UI objects for user $1 index $kibindex

INDEX_PATTERN=${INDEX_PATTERN:-project.*}
INDEX_PATTERN_FILE=${INDEX_PATTERN_FILE:-/usr/share/elasticsearch/index_patterns/com.redhat.viaq-openshift.index-pattern.json}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider refactoring '/usr/share/elasticsearch/' into a var like ES_HOME. If I ever get the reconciliation PR complete I think this will simply the impact and additional modifications we need to make.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok - but there are likely other places which will need to change

INDEX_PATTERN_TYPE=${INDEX_PATTERN_TYPE:-index-pattern}
KIBANA_UI_OBJECTS_DIR=${KIBANA_UI_OBJECTS_DIR:-/usr/share/elasticsearch/kibana_ui_objects}

info Adding the index pattern for "$INDEX_PATTERN" . . .

cat $INDEX_PATTERN_FILE | \
sed "s/[$]TITLE[$]/$INDEX_PATTERN/g" | \
QUERY="/$kibindex/$INDEX_PATTERN_TYPE/$INDEX_PATTERN" es_util -XPUT --data-binary @- | curl_output

info Adding the Kibana UI objects . . .
{
for file in $KIBANA_UI_OBJECTS_DIR/*.json ; do
cat "$file" | python -c '
import sys
import json
obj = json.load(sys.stdin)
for doc in obj:
hdr = {"create":{"_type":doc["_type"],"_id":doc["_id"]}}
json.dump(hdr, sys.stdout)
sys.stdout.write("\n")
json.dump(doc["_source"], sys.stdout)
sys.stdout.write("\n")
'
done
} | QUERY="/$kibindex/_bulk" es_util -XPOST --data-binary @- | curl_output

info Success
2 changes: 1 addition & 1 deletion elasticsearch/utils/es_util
Expand Up @@ -17,4 +17,4 @@ if [ -z "${QUERY:-}" ]; then
QUERY="$INDEX/$TYPE?$OPTIONS"
fi

curl -s -k --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key "$ES_BASE/$QUERY"
curl -s -k --cert /etc/elasticsearch/secret/admin-cert --key /etc/elasticsearch/secret/admin-key "$ES_BASE/$QUERY" "$@"
7 changes: 7 additions & 0 deletions elasticsearch/utils/logging
Expand Up @@ -40,3 +40,10 @@ error() {
log 4 ERROR "$@"
}

get_hash() {
printf "%s" "$1" | sha1sum | awk '{print $1}'
}

get_kibana_index_name() {
echo .kibana.$(get_hash "$1")
}
5 changes: 5 additions & 0 deletions hack/testing/test-kibana-dashboards.sh
@@ -0,0 +1,5 @@
#!/bin/bash

source "$(dirname "${BASH_SOURCE[0]}" )/../lib/init.sh"

exec ${OS_O_A_L_DIR}/test/kibana_dashboards.sh
6 changes: 5 additions & 1 deletion kibana/run.sh
Expand Up @@ -25,6 +25,10 @@ regex='^([[:digit:]]+)([GgMm])?i?$'

export NODE_OPTIONS=""

if [ -n "${KIBANA_DEFAULTAPPID:-}" ] ; then
KIBANA_OPTS="${KIBANA_OPTS:-} --kibana.defaultAppId=$KIBANA_DEFAULTAPPID"
fi

if [[ "${KIBANA_MEMORY_LIMIT:-}" =~ $regex ]]; then
num=${BASH_REMATCH[1]}
unit=${BASH_REMATCH[2]}
Expand All @@ -50,4 +54,4 @@ fi

echo "Using NODE_OPTIONS: '$NODE_OPTIONS' Memory setting is in MB"

exec ${KIBANA_HOME}/bin/kibana
exec ${KIBANA_HOME}/bin/kibana ${KIBANA_OPTS:-}