Skip to content

Commit 12e5a2d

Browse files
author
hemanth-1321
committed
logging
1 parent 0dba5e4 commit 12e5a2d

4 files changed

Lines changed: 37 additions & 33 deletions

File tree

server/agentic/utils/qdrant_db.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import uuid
33
import json
4+
import logging
45
from qdrant_client import QdrantClient, models
56
from qdrant_client.models import PointStruct, VectorParams, HnswConfig, Distance
67
from dotenv import load_dotenv
@@ -9,6 +10,8 @@
910

1011
load_dotenv()
1112

13+
logger = logging.getLogger(__name__)
14+
1215
collection_name = "pr_context"
1316

1417
URL = os.getenv("QDRANT_DB")
@@ -22,36 +25,36 @@
2225

2326
# Initialize Qdrant
2427
qdrant_client = QdrantClient(url=URL, api_key=API_KEY)
25-
print("Qdrant client initialized successfully")
28+
logger.info("Qdrant client initialized successfully")
2629

2730
# Initialize embeddings
2831
if not os.getenv("GOOGLE_API_KEY"):
2932
raise ValueError("GOOGLE_API_KEY not found")
3033

3134
embeddings = GoogleGenerativeAIEmbeddings(model="models/gemini-embedding-001")
3235
VECTOR_DIM = len(embeddings.embed_query("dimension test"))
33-
print(f"✓ Embedding dimension detected: {VECTOR_DIM}")
36+
logger.info(f"✓ Embedding dimension detected: {VECTOR_DIM}")
3437

3538
# Check or create collection with optimized HNSW indexing
3639
collections = [c.name for c in qdrant_client.get_collections().collections]
3740
if collection_name not in collections:
38-
print(f"Creating Qdrant collection '{collection_name}' with HNSW index...")
41+
logger.info(f"Creating Qdrant collection '{collection_name}' with HNSW index...")
3942
qdrant_client.create_collection(
4043
collection_name=collection_name,
4144
vectors_config=VectorParams(
4245
size=VECTOR_DIM,
4346
distance=Distance.COSINE,
4447
hnsw_config=HnswConfig(
45-
m=16, # neighbors per node (memory vs accuracy tradeoff)
46-
ef_construct=200 # index build accuracy
48+
m=16,
49+
ef_construct=200,
4750
)
4851
),
4952
shard_number=6,
5053
replication_factor=2,
5154
)
52-
print(f"Collection '{collection_name}' created successfully!")
55+
logger.info(f"Collection '{collection_name}' created successfully!")
5356
else:
54-
print(f"Collection '{collection_name}' already exists")
57+
logger.info(f"Collection '{collection_name}' already exists")
5558

5659
def prepare_and_store_context(pr_contexts: List[Dict]):
5760
"""
@@ -85,6 +88,5 @@ def prepare_and_store_context(pr_contexts: List[Dict]):
8588
},
8689
))
8790

88-
# Upsert all points in one call (faster for large batches)
8991
qdrant_client.upsert(collection_name=collection_name, points=points)
90-
print(f"[Agent] Stored batch of {len(points)} PR contexts in Qdrant")
92+
logger.info(f"[Agent] Stored batch of {len(points)} PR contexts in Qdrant")

server/agentic/utils/vector_tool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def search_vector_tool(query: str, limit: int = 10) -> list[dict]:
1212
query_vector=query_vector,
1313
limit=limit
1414
)
15-
print("")
1615
out = []
1716
for r in results:
1817
payload = r.payload or {}

server/routes/webhook.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import hmac
33
import hashlib
44
import json
5+
import logging
56
from server.worker.main import process_pr
67
from dotenv import load_dotenv
78
from fastapi import APIRouter, Request, HTTPException
@@ -11,19 +12,20 @@
1112

1213
load_dotenv()
1314

15+
logger = logging.getLogger(__name__)
1416
router = APIRouter()
1517

1618
REDIS_URL = os.getenv("REDIS_URL")
17-
print("redis url", REDIS_URL)
19+
logger.info(f"redis url {REDIS_URL}")
1820
if not REDIS_URL:
1921
raise RuntimeError("REDIS_URL is not set")
2022

2123
try:
2224
connection = Redis.from_url(REDIS_URL, decode_responses=False)
2325
connection.ping()
24-
print("Connected to Redis successfully")
26+
logger.info("Connected to Redis successfully")
2527
except Exception as e:
26-
print("Redis connection failed:", e)
28+
logger.error(f"Redis connection failed: {e}")
2729
raise
2830

2931
queue = Queue("github_prs", connection=connection)
@@ -72,10 +74,10 @@ def post_progress_comment(pr_number: int, owner: str, repo: str, installation_id
7274
try:
7375
response = post_pr_comment(pr_number, owner, repo, progress_body, installation_id)
7476
comment_id = response.get("id")
75-
print(f"[Progress] Posted progress comment ID: {comment_id}")
77+
logger.info(f"[Progress] Posted progress comment ID: {comment_id}")
7678
return comment_id
7779
except Exception as e:
78-
print(f"[Progress] Failed to post progress comment: {e}")
80+
logger.error(f"[Progress] Failed to post progress comment: {e}")
7981
return None
8082

8183

@@ -101,7 +103,6 @@ async def webhook(request: Request):
101103
installation = payload.get("installation", {})
102104
installation_id = installation.get("id")
103105

104-
105106
pr_number = payload.get("number")
106107
repo_name = repo.get("full_name")
107108
owner, repo_name_only = repo_name.split("/")
@@ -116,16 +117,15 @@ async def webhook(request: Request):
116117
"repo_name": repo_name,
117118
"action": action,
118119
"commit_sha": pr.get("head", {}).get("sha"),
119-
"progress_comment_id": comment_id,
120+
"progress_comment_id": comment_id,
120121
"installation_id": installation_id,
121122
"owner": owner,
122123
"repo": repo_name_only
123124
}
124125

125-
print("Enqueuing PR:", pr_data)
126-
queue.enqueue(process_pr, pr_data, retry=Retry(max=3, interval=[10, 30, 60]))
126+
logger.info(f"Enqueuing PR: {pr_data}")
127+
queue.enqueue(process_pr, pr_data, retry=Retry(max=3, interval=[10, 30, 60]))
127128

128129
return {"status": "queued", "pr": pr_data, "progress_comment_id": comment_id}
129130

130-
131-
return {"status": "ignored"}
131+
return {"status": "ignored"}

server/worker/main.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import networkx as nx
55
import json
66
import boto3
7+
import logging
78
from redis import Redis
89
from rq import Queue
910
from dotenv import load_dotenv
@@ -16,19 +17,19 @@
1617

1718
load_dotenv()
1819

20+
logger = logging.getLogger(__name__)
1921

2022
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0")
2123
try:
2224
connection = Redis.from_url(REDIS_URL, decode_responses=False)
2325
connection.ping()
24-
print("[Worker] Connected to Redis successfully")
26+
logger.info("[Worker] Connected to Redis successfully")
2527
except Exception as e:
26-
print("[Worker] Redis connection failed:", e)
28+
logger.error(f"[Worker] Redis connection failed: {e}")
2729
raise
2830

2931
queue = Queue("pr_context_queue", connection=connection)
3032

31-
3233
s3_client = boto3.client(
3334
"s3",
3435
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
@@ -47,24 +48,25 @@ def upload_to_s3(file_path, key_prefix):
4748
return f"s3://{bucket_name}/{s3_key}"
4849

4950
def process_pr(pr_data):
50-
print("pr_data",pr_data)
51+
logger.info(f"pr_data {pr_data}")
52+
5153
repo_url = pr_data["clone_url"]
5254
pr_number = pr_data["pr_number"]
5355
base_branch = pr_data["base_branch"]
5456
head_branch = pr_data["head_branch"]
5557
repo_name = pr_data.get("repo_name", os.path.basename(repo_url).replace(".git", ""))
5658
commit_sha = pr_data.get("commit_sha")
57-
59+
5860
progress_comment_id = pr_data.get("progress_comment_id")
5961
installation_id = pr_data.get("installation_id")
60-
print("installationid",installation_id)
62+
logger.info(f"installationid {installation_id}")
6163
owner = pr_data.get("owner")
6264
repo = pr_data.get("repo")
63-
65+
6466
safe_repo_name = repo_name.replace("/", "_")
6567
s3_prefix = f"pr_contexts/{safe_repo_name}_{pr_number}"
6668

67-
print(f"[Worker] Reviewing PR #{pr_number} from {repo_name}")
69+
logger.info(f"[Worker] Reviewing PR #{pr_number} from {repo_name}")
6870

6971
temp_dir = tempfile.mkdtemp()
7072

@@ -133,7 +135,7 @@ def parse_file_if_needed(file_path, file_name):
133135

134136
s3_json_uri = upload_to_s3(context_json_path, s3_prefix)
135137
s3_txt_uri = upload_to_s3(context_txt_path, s3_prefix)
136-
print(f"[Worker] Uploaded context files to S3: {s3_json_uri}, {s3_txt_uri}")
138+
logger.info(f"[Worker] Uploaded context files to S3: {s3_json_uri}, {s3_txt_uri}")
137139

138140
queue_data = {
139141
"pr_number": pr_number,
@@ -148,7 +150,8 @@ def parse_file_if_needed(file_path, file_name):
148150
"owner": owner,
149151
"repo": repo
150152
}
151-
print("queue",queue_data)
153+
logger.info(f"queue {queue_data}")
154+
152155
queue.enqueue(process_ai_job, queue_data)
153156

154157
return {
@@ -162,8 +165,8 @@ def parse_file_if_needed(file_path, file_name):
162165
}
163166

164167
except Exception as e:
165-
print(f"[Worker] Error: {e}")
168+
logger.error(f"[Worker] Error: {e}")
166169
return {"error": str(e)}
167170

168171
finally:
169-
shutil.rmtree(temp_dir)
172+
shutil.rmtree(temp_dir)

0 commit comments

Comments
 (0)