mohammed firdous

GitLab AI Gateway Contribution

My contribution to GitLab's AI Gateway, refactoring middleware code for better organization and maintainability.

What changed

  • Improved code structure by moving middleware into its own module.
  • Kept old behavior working during the refactor.
  • Improved test coverage for middleware and logging.

What I worked on

  • I moved InternalEventMiddleware into a dedicated module.
  • I added and updated tests after the move.
  • I fixed circular import and test issues during review.

Links

I refactored InternalEventMiddleware in GitLab AI Gateway by moving it from a crowded base module into a dedicated middleware file, with tests moved alongside it.

This was part of an ongoing cleanup effort to make middleware easier to locate, test, and maintain without breaking existing imports.

What I shipped in MR !2291:

  • extracted middleware into ai_gateway/api/middleware/internal_event.py,
  • split and updated tests into the middleware test module,
  • kept compatibility by re-exporting where needed.

During review, I fixed a circular import and logger-related test failures flagged by maintainers, then merged after final approval.

Links: MR !2291Issue #859