-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
list-loki-instances
action to cluster actions (wip)
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/10get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
60 changes: 60 additions & 0 deletions
60
core/imageroot/var/lib/nethserver/cluster/actions/list-loki-instances/validate-output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |