Skip to content

Commit

Permalink
Clm hostname fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso-ascani committed Jun 25, 2024
1 parent 48384e5 commit 3c9b15c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions imageroot/actions/set-clm-forwarder/10set
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#

import subprocess
import hashlib
import agent
import json
import uuid
Expand All @@ -23,6 +24,7 @@ if not bool(subscription):

if (request['active']):
agent.set_env('CLOUD_LOG_MANAGER_UUID', uuid.uuid5(uuid.NAMESPACE_DNS, cluster_uuid))
agent.set_env('CLOUD_LOG_MANAGER_HOSTNAME', 'cluster-' + hashlib.sha256(cluster_uuid.encode("utf-8")).hexdigest()[:8])
agent.set_env('CLOUD_LOG_MANAGER_ADDRESS', f"{request['address']}")
agent.set_env('CLOUD_LOG_MANAGER_TENANT', f"{request['tenant']}")

Expand Down
7 changes: 3 additions & 4 deletions imageroot/bin/cloud-log-manager-forwarder
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import sys

try:
UUID = os.environ.get('CLOUD_LOG_MANAGER_UUID')
HOSTNAME = os.environ.get('CLOUD_LOG_MANAGER_HOSTNAME')
START_TIME = os.environ.get('CLOUD_LOG_MANAGER_START_TIME', '')
ADDRESS = os.environ.get('CLOUD_LOG_MANAGER_ADDRESS', 'https://nar.nethesis.it')
TENANT = os.environ.get('CLOUD_LOG_MANAGER_TENANT')

HOSTNAME = os.popen('hostname').read().rstrip('\n')

os.environ['LOKI_ADDR'] = f"http://127.0.0.1:{os.environ['LOKI_HTTP_PORT']}"
os.environ['LOKI_USERNAME'] = os.environ['LOKI_API_AUTH_USERNAME']
os.environ['LOKI_PASSWORD'] = os.environ['LOKI_API_AUTH_PASSWORD']
Expand Down Expand Up @@ -120,8 +119,8 @@ while True:
# Save log timestamp only when socket send succeed
last_timestamp = json_object["timestamp"]

# If list size is bigger than 1 MB, send
if sys.getsizeof(logs_list) >= 1048576:
# If list size is bigger than 128 kB, send
if sys.getsizeof(logs_list) >= 131072:
send_logs_list(logs_list, last_timestamp)
logs_list.clear()
except Exception as exc:
Expand Down
6 changes: 6 additions & 0 deletions imageroot/events/default-instance-changed/10set
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import os
import sys
import datetime
import subprocess
import hashlib

import agent

Expand Down Expand Up @@ -40,6 +41,8 @@ if os.getenv("AGENT_EVENT_SOURCE") == 'cluster':
stderr=sys.stderr,
text=True,
check=True)

agent.unset_env('CLOUD_LOG_MANAGER_HOSTNAME')

# New instance
if 'current' in data and data['current'] == os.getenv('MODULE_ID'):
Expand All @@ -49,7 +52,10 @@ if os.getenv("AGENT_EVENT_SOURCE") == 'cluster':

# If cloud log manager service was active in old instance, start on new instacnce
if all(key in previous_environment for key in ('CLOUD_LOG_MANAGER_ADDRESS', 'CLOUD_LOG_MANAGER_TENANT', 'CLOUD_LOG_MANAGER_UUID')) and bool(subscription):
cluster_uuid = rdb.get('cluster/uuid')

agent.set_env('CLOUD_LOG_MANAGER_UUID', previous_environment['CLOUD_LOG_MANAGER_UUID'])
agent.set_env('CLOUD_LOG_MANAGER_HOSTNAME', 'cluster-' + hashlib.sha256(cluster_uuid.encode("utf-8")).hexdigest()[:8])
agent.set_env('CLOUD_LOG_MANAGER_ADDRESS', previous_environment['CLOUD_LOG_MANAGER_ADDRESS'])
agent.set_env('CLOUD_LOG_MANAGER_TENANT', previous_environment['CLOUD_LOG_MANAGER_TENANT'])

Expand Down
Empty file modified imageroot/events/subscription-changed/10check_forwarder
100644 → 100755
Empty file.

0 comments on commit 3c9b15c

Please sign in to comment.