Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/579-kibana-version-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Kibana follows a change of its cluster's version (S-024-9): changing the Elasticsearch service's `version` to a later patch or minor moves Kibana in the same converge, after every node. Before Kibana's held package changes, the `cloudfall_kibana` role reads every node's version (`GET /_nodes`, `no_log`) and, while one is older than the declared version, leaves Kibana as it is and stops the converge, which answers `PRECONDITION` with the code `service_kibana_node_older` and the nodes still behind. Kibana then restarts on the new version and the converge waits until it reports itself available, its saved objects migrated. A converge that finds Kibana at the declared version reads nothing more; a newer Kibana, or one of another major, is still refused before anything changes (#579)
6 changes: 6 additions & 0 deletions engine/ansible/playbooks/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@
(cloudfall_services_elasticsearch_files | default({}))
[cloudfall_service_item.kibana.elasticsearch] | default({})
}}
# Where a converge refused while a node of the cluster is older
# than the declared version is reported, the directory the
# MariaDB role reports to: the services converge answers it with
# PRECONDITION (S-024-9).
cloudfall_kibana_report_directory: >-
{{ cloudfall_services_mariadb_report_directory | default('') }}
loop: "{{ cloudfall_kibana_here }}"
loop_control:
loop_var: cloudfall_service_item
Expand Down
30 changes: 30 additions & 0 deletions engine/ansible/roles/cloudfall_kibana/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,33 @@ cloudfall_kibana_elasticsearch_url: >-
# How long Kibana may take to report itself available (10 s apart): a first
# start, or a new version, migrates its saved objects first.
cloudfall_kibana_available_retries: 60
# The Kibana dpkg has installed, read by "Read the installed Kibana version";
# '' when none is.
cloudfall_kibana_installed_version: >-
{{
cloudfall_kibana_installed.stdout.split(' ', 1) | last
if cloudfall_kibana_installed.rc == 0
and cloudfall_kibana_installed.stdout is match('installed ')
else ''
}}
# Where a converge refused while a node of the cluster is older than the
# declared version is reported, the directory the MariaDB and RabbitMQ roles
# report to: the services converge answers it with PRECONDITION (S-024-9).
cloudfall_kibana_report_directory: ""
cloudfall_kibana_node_older_code: service_kibana_node_older
# "name version" of each node GET /_nodes answered older than the declared
# version, read before Kibana's package changes.
cloudfall_kibana_older: >-
{{
cloudfall_kibana_nodes.json
| cloudfall_kibana_older_nodes(
cloudfall_kibana_elasticsearch_service.elasticsearch.version)
}}
cloudfall_kibana_node_older_message: >-
Kibana service {{ cloudfall_kibana_service.id }} on {{ cloudfall_server_id }}
is left at {{ cloudfall_kibana_installed_version or 'no version' }}: these
nodes of Elasticsearch service {{ cloudfall_kibana_elasticsearch_service.id }}
run older than the declared
{{ cloudfall_kibana_elasticsearch_service.elasticsearch.version }}:
{{ cloudfall_kibana_older | join(', ') }}. Kibana never runs ahead of a
node; converge every node to that version, then run the command again
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Read the nodes of Kibana's cluster before its package changes (S-024-9).

Elastic supports no Kibana newer than a node of its cluster, so the role
reads every node's version (``GET /_nodes``) and keeps Kibana as it is while
one is older than the declared version. Ansible loads this file itself; it
imports nothing from the SDK.
"""

from __future__ import annotations

import re
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable

_VERSION = re.compile(r"^(\d+)\.(\d+)\.(\d+)$")


def _parsed(version: object) -> tuple[int, int, int]:
"""Return a node or service version as three numbers; refuse anything else."""
found = _VERSION.match(version) if isinstance(version, str) else None
if found is None:
message = f"{version!r} is not a version of the form 9.2.4"
raise ValueError(message)
major, minor, patch = (int(part) for part in found.groups())
return major, minor, patch


def older_nodes(answer: object, version: str) -> list[str]:
"""Return ``name version`` of each node older than ``version``, by name.

``answer`` is the JSON of ``GET /_nodes?filter_path=nodes.*.name,
nodes.*.version``: ``{"nodes": {"<id>": {"name": ..., "version": ...}}}``.
An answer without a node, or a node without a name or version, is
refused: the role never decides on a cluster it could not read.
"""
wanted = _parsed(version)
nodes = answer.get("nodes") if isinstance(answer, dict) else None
if not isinstance(nodes, dict) or not nodes:
message = "the cluster answered GET /_nodes with no node"
raise ValueError(message)
found: list[str] = []
for node in nodes.values():
name = node.get("name") if isinstance(node, dict) else None
if not isinstance(name, str) or not name:
message = "the cluster answered GET /_nodes with a node without a name"
raise ValueError(message)
running = node.get("version")
if _parsed(running) < wanted:
found.append(f"{name} {running}")
return sorted(found)


class FilterModule:
"""The role's filters."""

def filters(self) -> dict[str, Callable[..., object]]:
"""Name the filters for Ansible."""
return {"cloudfall_kibana_older_nodes": older_nodes}
6 changes: 6 additions & 0 deletions engine/ansible/roles/cloudfall_kibana/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ argument_specs:
description: >-
Controller paths of the Elasticsearch service's staged account
files; the role reads 'cloudfallPassword'
cloudfall_kibana_report_directory:
type: str
description: >-
Controller directory where a converge refused while a node of the
cluster is older than the declared version is reported, for the
services converge to answer PRECONDITION; empty reports nothing
46 changes: 29 additions & 17 deletions engine/ansible/roles/cloudfall_kibana/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,27 @@
# A read: a dry run (--check) must refuse a drifted host too
check_mode: false

# Kibana runs at the version of its cluster. Moving it after the nodes when
# the service's version changes comes with a later release (#579), so a
# Kibana of another version is refused before anything changes.
- name: Refuse a Kibana of another version than the Elasticsearch service's
# Kibana runs at the version of its cluster and follows a change of it
# (S-024-9) as the node does (S-012): to a later patch or minor of the same
# major. APT does not downgrade it, and a new major needs Elastic's upgrade
# checks, so both are refused before anything changes.
- name: Refuse a Kibana version the converge can't move to the service's
ansible.builtin.assert:
that:
- >-
cloudfall_kibana_installed_version == ''
or cloudfall_kibana_installed_version
== cloudfall_kibana_elasticsearch_service.elasticsearch.version
or (
cloudfall_kibana_installed_version.split('.')[0]
== cloudfall_kibana_elasticsearch_service.elasticsearch.version.split('.')[0]
and cloudfall_kibana_installed_version
is version(cloudfall_kibana_elasticsearch_service.elasticsearch.version, '<=')
)
fail_msg: >-
kibana {{ cloudfall_kibana_installed_version }} is installed on
{{ cloudfall_server_id }}; Elasticsearch service
{{ cloudfall_kibana_elasticsearch_service.id }} declares
{{ cloudfall_kibana_elasticsearch_service.elasticsearch.version }}, and
this release does not move Kibana to another version
vars:
cloudfall_kibana_installed_version: >-
{{
cloudfall_kibana_installed.stdout.split(' ', 1) | last
if cloudfall_kibana_installed.rc == 0
and cloudfall_kibana_installed.stdout is match('installed ')
else ''
}}
{{ cloudfall_kibana_elasticsearch_service.elasticsearch.version }}, another
major or older, which this converge does not install

# Kibana comes from the repository of the service's major, which the
# Elasticsearch role configured on this node earlier in the run.
Expand All @@ -146,7 +143,22 @@
{{ cloudfall_kibana_service.kibana.elasticsearch }} first, which
configures it

# Every refusal above only reads; the host changes from here on.
# Whenever the package would change (a first install, or a new declared
# version), every node of the cluster is read first, and Kibana stays as it is
# while one is older (S-024-9). A converge that finds Kibana at the declared
# version reads nothing more. A dry run converges no node, so it reads none.
- name: Stop before Kibana's package changes while a node of its cluster is older
ansible.builtin.include_tasks: version.yml
when:
- not ansible_check_mode
- >-
cloudfall_kibana_installed_version
!= cloudfall_kibana_elasticsearch_service.elasticsearch.version

# Every refusal above only reads; the host changes from here on. The package
# is held, so the pinned install moves it to a new declared version, and the
# restart it notifies starts the new version, which migrates the saved objects
# before Kibana reports itself available below.
- name: Install the Elasticsearch service's version of Kibana
ansible.builtin.apt:
name: "kibana={{ cloudfall_kibana_elasticsearch_service.elasticsearch.version }}"
Expand Down
51 changes: 51 additions & 0 deletions engine/ansible/roles/cloudfall_kibana/tasks/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# Kibana moves to the Elasticsearch service's version after every node of its
# cluster (S-024-9): Elastic supports no Kibana newer than a node. services.yml
# runs Kibana after the nodes this run converges; a node the run did not
# converge (another server's --limit, a node left behind) is still read here,
# from the cluster itself, before the package changes. While one is older
# than the declared version, Kibana is left as it is and the services converge
# answers PRECONDITION. Only reads come before the stop.
- name: Read the version of every node of the cluster
ansible.builtin.uri:
url: >-
{{ cloudfall_kibana_elasticsearch_url
}}/_nodes?filter_path=nodes.*.name,nodes.*.version
ca_path: >-
{{
cloudfall_kibana_elasticsearch_ca_path
if cloudfall_kibana_elasticsearch_service.elasticsearch.remoteAccess is defined
else omit
}}
url_username: cloudfall
url_password: >-
{{ lookup('ansible.builtin.file',
cloudfall_kibana_elasticsearch_files.cloudfallPassword) }}
force_basic_auth: true
status_code: 200
register: cloudfall_kibana_nodes
no_log: true

- name: Report the converge refused while a node is older than the service's version
ansible.builtin.copy:
content: >-
{{ {'service': cloudfall_kibana_service.id,
'server': cloudfall_server_id,
'outcome': 'refused',
'code': cloudfall_kibana_node_older_code,
'message': cloudfall_kibana_node_older_message} | to_json }}
dest: >-
{{ cloudfall_kibana_report_directory }}/{{ cloudfall_kibana_service.id }}.json
mode: "0600"
delegate_to: localhost
become: false
when:
- cloudfall_kibana_older | length > 0
- cloudfall_kibana_report_directory | length > 0

- name: Stop before Kibana's package changes while a node is older than the service's version
ansible.builtin.fail:
msg: >-
PRECONDITION {{ cloudfall_kibana_node_older_code }}:
{{ cloudfall_kibana_node_older_message }}
when: cloudfall_kibana_older | length > 0
Loading