Skip to content

Commit

Permalink
feat: add list-loki-instances action to cluster actions (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Mar 20, 2024
1 parent 1175385 commit 167c0b1
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json
import sys

import agent
from cluster import modules

redis_client = agent.redis_connect()
default_instance = redis_client.get("cluster/default_instance/loki")
instances = modules.list_installed(redis_client).get("ghcr.io/nethserver/loki", [])

response = []
for instance in instances:
item = {
"instance_id": instance["id"],
"instance_label": instance["ui_name"],
"node_id": instance["node"],
"node_label": instance["node_ui_name"],
"active": instance["id"] == default_instance
}

task_response = agent.tasks.run(
agent_id=f'module/{instance["id"]}',
action='get-configuration',
endpoint="redis://cluster-leader"
)
if task_response["exit_code"] == 0:
item["retention_days"] = task_response["output"]["retention_days"]
item["active_from"] = "1970-01-01T00:00:00Z+00:00"
if not item["active"]:
item["active_to"] = "2024-12-31T23:59:59Z+00:00"

response.append(item)

json.dump({
'applications': response
}, sys.stdout)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "List loki instances",
"$id": "http://schema.nethserver.org/cluster/list-loki-instances-output.json",
"type": "object",
"required": [
"instances"
],
"properties": {
"instances": {
"type": "array",
"items": {
"type": "object",
"required": [
"instance_id",
"instance_label",
"node_id",
"node_label",
"active"
],
"properties": {
"instance_id": {
"type": "string",
"description": "The Loki instance identifier."
},
"instance_label": {
"type": "string",
"description": "The Loki instance label, if empty string, there's no label."
},
"node_id": {
"type": "string",
"description": "The node identifier where the Loki instance is running."
},
"node_label": {
"type": "string",
"description": "The node label where the Loki instance is running, can be empty."
},
"active": {
"type": "boolean",
"description": "The Loki instance is the currently active."
},
"retention_days": {
"type": "integer",
"description": "The retention days for the Loki instance."
},
"active_from": {
"type": "string",
"format": "date-time",
"description": "The ISO 8601 date-time when the Loki instance was activated."
},
"active_to": {
"type": "string",
"format": "date-time",
"description": "The ISO 8601 date-time when the Loki instance was deactivated."
}
}
}
}
}
}

0 comments on commit 167c0b1

Please sign in to comment.