Skip to content

Commit e378a73

Browse files
authored
Merge pull request #173 from DrDroidLab/fix/victoria_logs_headers
Fix/victoria logs headers
2 parents c719a38 + 43f1694 commit e378a73

File tree

4 files changed

+89
-7
lines changed

4 files changed

+89
-7
lines changed

agent/tasks.py

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,99 @@
99
logger = logging.getLogger(__name__)
1010

1111

12+
def get_pod_details(namespace='drdroid'):
13+
# Import kubernetes here to avoid loading at module import time
14+
from kubernetes import client, config
15+
16+
try:
17+
# Try to load in-cluster config first, then local config
18+
try:
19+
config.load_incluster_config()
20+
except config.ConfigException:
21+
config.load_kube_config()
22+
23+
v1 = client.CoreV1Api()
24+
25+
# Get all pods in the namespace
26+
pods = v1.list_namespaced_pod(namespace)
27+
events = v1.list_namespaced_event(namespace)
28+
29+
pod_data = []
30+
31+
for pod in pods.items:
32+
# Extract container statuses
33+
container_statuses = []
34+
if pod.status.container_statuses:
35+
for container in pod.status.container_statuses:
36+
state = "unknown"
37+
if container.state.running:
38+
state = "running"
39+
elif container.state.terminated:
40+
state = "terminated"
41+
elif container.state.waiting:
42+
state = "waiting"
43+
44+
last_state = "unknown"
45+
if container.last_state.running:
46+
last_state = "running"
47+
elif container.last_state.terminated:
48+
last_state = "terminated"
49+
elif container.last_state.waiting:
50+
last_state = "waiting"
51+
52+
container_statuses.append({
53+
"name": container.name,
54+
"state": state,
55+
"last_state": last_state,
56+
"ready": container.ready,
57+
"restart_count": container.restart_count
58+
})
59+
60+
# Extract events for this pod
61+
pod_events = []
62+
for event in events.items:
63+
if event.involved_object.kind == 'Pod' and event.involved_object.name == pod.metadata.name:
64+
pod_events.append({
65+
"type": event.type,
66+
"reason": event.reason,
67+
"message": event.message,
68+
"count": event.count,
69+
"last_timestamp": event.last_timestamp.isoformat() if event.last_timestamp else None
70+
})
71+
72+
pod_data.append({
73+
"name": pod.metadata.name,
74+
"status": pod.status.phase,
75+
"containers": container_statuses,
76+
"events": pod_events
77+
})
78+
79+
return pod_data
80+
81+
except Exception as e:
82+
logger.error(f"Error fetching pod details: {e}")
83+
return []
84+
85+
1286
@shared_task(max_retries=3, default_retry_delay=10)
1387
def send_ping_to_drd_cloud():
1488
drd_cloud_host = settings.DRD_CLOUD_API_HOST
1589
drd_cloud_api_token = settings.DRD_CLOUD_API_TOKEN
1690
commit_hash = settings.VPC_AGENT_COMMIT_HASH
1791
current_epoch = current_epoch_timestamp()
1892

93+
# Get pod details
94+
pod_details = get_pod_details()
95+
1996
# Establish reachability with DRD Cloud
20-
response = requests.get(f'{drd_cloud_host}/connectors/proxy/ping',
97+
payload = {
98+
'commit_hash': commit_hash,
99+
'pods': pod_details
100+
}
101+
102+
response = requests.post(f'{drd_cloud_host}/connectors/proxy/ping',
21103
headers={'Authorization': f'Bearer {drd_cloud_api_token}'},
22-
params={'commit_hash': commit_hash})
104+
json=payload)
23105

24106
if response.status_code != 200:
25107
logger.error(f'Failed to connect to DRD Cloud at {current_epoch} with code: {response.status_code} '

helm/Chart.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
apiVersion: v2
22
name: drd-vpc-agent
33
description: Celery-only deployment
4-
version: 0.1.1
4+
version: 0.1.2
55

66
dependencies:
77
- name: celery-beat
8-
version: 0.1.1
8+
version: 0.1.2
99
repository: "file://charts/celery_beat"
1010
- name: celery-worker
11-
version: 0.1.1
11+
version: 0.1.2
1212
repository: "file://charts/celery_worker"
1313
- name: redis
14-
version: 0.1.1
14+
version: 0.1.2
1515
repository: "file://charts/redis"
4.28 KB
Binary file not shown.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ wcwidth==0.2.13
149149
websocket-client==1.8.0
150150
yarl==1.12.1
151151
zstandard==0.23.0
152-
# Latest version of drdroid-debug-toolkit -> victoria logs headers handling
152+
# Latest version of drdroid-debug-toolkit -> victoria logs & sentry test connection returns
153153
git+https://github.com/DrDroidLab/drdroid-debug-toolkit.git@master

0 commit comments

Comments
 (0)