Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump copilot requests, too if CODEGATE_DUMP_DIR is set #1196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/codegate/providers/copilot/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
TEMPDIR = tempfile.TemporaryDirectory(prefix="codegate-", dir=basedir, delete=False)


def _dump_data(suffix, func):
def _dump_data(suffix, func, trigger: bytes | None = None):
if os.getenv("CODEGATE_DUMP_DIR"):
buf = bytearray(b"")

Expand All @@ -48,7 +48,7 @@ def inner(self, data: bytes):
func(self, data)
buf.extend(data)

if data == b"0\r\n\r\n":
if not trigger or data == trigger:
ts = datetime.datetime.now()
fname = os.path.join(TEMPDIR.name, ts.strftime(f"{suffix}-%Y%m%dT%H%M%S%f.txt"))
with open(fname, mode="wb") as fd:
Expand All @@ -58,14 +58,11 @@ def inner(self, data: bytes):
return inner
return func


def _dump_request(func):
return _dump_data("request", func)


def _dump_response(func):
return _dump_data("response", func)

return _dump_data("response", func, b"0\r\n\r\n")

# Constants
MAX_BUFFER_SIZE = 10 * 1024 * 1024 # 10MB
Expand Down Expand Up @@ -336,7 +333,12 @@ def _check_buffer_size(self, new_data: bytes) -> bool:
"""Check if adding new data would exceed buffer size limit"""
return len(self.buffer) + len(new_data) <= MAX_BUFFER_SIZE

@_dump_request
def _dump_create_http_request(self, data: bytes) -> bytes:
return data

async def _forward_data_through_pipeline(self, data: bytes) -> Union[HttpRequest, HttpResponse]:
self._dump_create_http_request(data)
http_request = http_request_from_bytes(data)
if not http_request:
# we couldn't parse this into an HTTP request, so we just pass through
Expand Down
Loading