Merge "[elasticsearch] Add migration for Kibana 6.x index" into stable/train

This commit is contained in:
Zuul 2020-06-12 18:19:56 +00:00 committed by Gerrit Code Review
commit 2855a4027b
3 changed files with 366 additions and 0 deletions

View File

@ -0,0 +1,264 @@
{
"settings" : {
"number_of_shards" : 1,
"index.mapper.dynamic": false
},
"mappings" : {
"doc": {
"properties": {
"type": {
"type": "keyword"
},
"updated_at": {
"type": "date"
},
"config": {
"properties": {
"buildNum": {
"type": "keyword"
}
}
},
"index-pattern": {
"properties": {
"fieldFormatMap": {
"type": "text"
},
"fields": {
"type": "text"
},
"intervalName": {
"type": "keyword"
},
"notExpandable": {
"type": "boolean"
},
"sourceFilters": {
"type": "text"
},
"timeFieldName": {
"type": "keyword"
},
"title": {
"type": "text"
}
}
},
"visualization": {
"properties": {
"description": {
"type": "text"
},
"kibanaSavedObjectMeta": {
"properties": {
"searchSourceJSON": {
"type": "text"
}
}
},
"savedSearchId": {
"type": "keyword"
},
"title": {
"type": "text"
},
"uiStateJSON": {
"type": "text"
},
"version": {
"type": "integer"
},
"visState": {
"type": "text"
}
}
},
"search": {
"properties": {
"columns": {
"type": "keyword"
},
"description": {
"type": "text"
},
"hits": {
"type": "integer"
},
"kibanaSavedObjectMeta": {
"properties": {
"searchSourceJSON": {
"type": "text"
}
}
},
"sort": {
"type": "keyword"
},
"title": {
"type": "text"
},
"version": {
"type": "integer"
}
}
},
"dashboard": {
"properties": {
"description": {
"type": "text"
},
"hits": {
"type": "integer"
},
"kibanaSavedObjectMeta": {
"properties": {
"searchSourceJSON": {
"type": "text"
}
}
},
"optionsJSON": {
"type": "text"
},
"panelsJSON": {
"type": "text"
},
"refreshInterval": {
"properties": {
"display": {
"type": "keyword"
},
"pause": {
"type": "boolean"
},
"section": {
"type": "integer"
},
"value": {
"type": "integer"
}
}
},
"timeFrom": {
"type": "keyword"
},
"timeRestore": {
"type": "boolean"
},
"timeTo": {
"type": "keyword"
},
"title": {
"type": "text"
},
"uiStateJSON": {
"type": "text"
},
"version": {
"type": "integer"
}
}
},
"url": {
"properties": {
"accessCount": {
"type": "long"
},
"accessDate": {
"type": "date"
},
"createDate": {
"type": "date"
},
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 2048
}
}
}
}
},
"server": {
"properties": {
"uuid": {
"type": "keyword"
}
}
},
"timelion-sheet": {
"properties": {
"description": {
"type": "text"
},
"hits": {
"type": "integer"
},
"kibanaSavedObjectMeta": {
"properties": {
"searchSourceJSON": {
"type": "text"
}
}
},
"timelion_chart_height": {
"type": "integer"
},
"timelion_columns": {
"type": "integer"
},
"timelion_interval": {
"type": "keyword"
},
"timelion_other_interval": {
"type": "keyword"
},
"timelion_rows": {
"type": "integer"
},
"timelion_sheet": {
"type": "text"
},
"title": {
"type": "text"
},
"version": {
"type": "integer"
}
}
},
"graph-workspace": {
"properties": {
"description": {
"type": "text"
},
"kibanaSavedObjectMeta": {
"properties": {
"searchSourceJSON": {
"type": "text"
}
}
},
"numLinks": {
"type": "integer"
},
"numVertices": {
"type": "integer"
},
"title": {
"type": "text"
},
"version": {
"type": "integer"
},
"wsState": {
"type": "text"
}
}
}
}
}
}
}

View File

@ -0,0 +1,99 @@
---
- name: Set fact for Elasticsearch URL
set_fact:
elasticsearch_url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ elasticsearch_port }}"
- name: Wait for Elasticsearch
become: true
uri:
url: "{{ elasticsearch_url }}"
delegate_to: "{{ groups['elasticsearch'][0] }}"
run_once: true
retries: 10
delay: 5
register: result
until: ('status' in result) and result.status == 200
- name: Check state of migration
become: true
uri:
url: "{{ elasticsearch_url }}/.kibana/_mappings/doc"
status_code: [200, 404]
delegate_to: "{{ groups['elasticsearch'][0] }}"
run_once: true
register: kibana_6_index
# The official procedure for migrating the Kibana index:
# https://www.elastic.co/guide/en/kibana/6.x/migrating-6.0-index.html
- name: Migrate Kibana index to 6.x
block:
- name: Set .kibana index to read-only
become: true
uri:
url: "{{ elasticsearch_url }}/.kibana/_settings"
method: PUT
status_code: 200
return_content: yes
body: |
{
"index.blocks.write": true
}
body_format: json
delegate_to: "{{ groups['elasticsearch'][0] }}"
run_once: true
- name: Create .kibana-6 index
become: true
uri:
url: "{{ elasticsearch_url }}/.kibana-6"
method: PUT
status_code: 200
return_content: yes
body: "{{ lookup('file', 'kibana-6-index.json') }}"
body_format: json
delegate_to: "{{ groups['elasticsearch'][0] }}"
run_once: true
- name: Reindex .kibana into .kibana-6
become: true
uri:
url: "{{ elasticsearch_url }}/_reindex"
method: POST
status_code: 200
return_content: yes
body: |
{
"source": {
"index": ".kibana"
},
"dest": {
"index": ".kibana-6"
},
"script": {
"inline": "ctx._source = [ ctx._type : ctx._source ]; ctx._source.type = ctx._type; ctx._id = ctx._type + \":\" + ctx._id; ctx._type = \"doc\"; ",
"lang": "painless"
}
}
body_format: json
delegate_to: "{{ groups['elasticsearch'][0] }}"
run_once: true
- name: Alias .kibana-6 to .kibana and remove legacy .kibana index
become: true
uri:
url: "{{ elasticsearch_url }}/_aliases"
method: POST
status_code: 200
return_content: yes
body: |
{
"actions" : [
{ "add": { "index": ".kibana-6", "alias": ".kibana" } },
{ "remove_index": { "index": ".kibana" } }
]
}
body_format: json
delegate_to: "{{ groups['elasticsearch'][0] }}"
run_once: true
when: ('status' in kibana_6_index) and kibana_6_index.status != 200

View File

@ -1,5 +1,8 @@
---
- include_tasks: config.yml
- include_tasks: migrate-kibana-index.yml
when: kibana_use_v6 | bool
- name: Flush handlers
meta: flush_handlers