Skip to content

Conversation

@tovar-rodrigo
Copy link

Adding methods to get excluded request URL paths and response status codes

Avoid metrics creation in HandlerFunc based on excludedPaths and excludedStatusCodes slices

Adding methods to get excluded request URL paths and response status codes

Avoid metrics creation in HandlerFunc based on excludedPaths and excludedStatusCodes slices
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @tovar-rodrigo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces functionality to exclude specific request URL paths and response status codes from being monitored by Prometheus. This is achieved by adding methods to set and retrieve lists of excluded paths and status codes. The middleware handler is then modified to check incoming requests against these exclusion lists, preventing metrics creation for excluded requests.

Highlights

  • Exclusion Methods: Adds ExcludePaths and ExcludeStatusCodes methods to the Prometheus struct, allowing users to specify URL paths and status codes to exclude from Prometheus monitoring (lines 362-379).
  • Exclusion Logic: Modifies the HandlerFunc to check if the request URL path or response status code is in the exclusion lists before creating metrics (lines 385-393).
  • State variables: Introduces excludedPaths and excludedStatusCodes variables to store the lists of excluded paths and status codes (lines 19-21).

Changelog

  • middleware.go
    • Adds slices import for checking if a slice contains a value (line 8).
    • Introduces excludedPaths and excludedStatusCodes variables to store the lists of excluded paths and status codes (lines 19-21).
    • Adds ExcludePaths, GetExcludedPaths, ExcludeStatusCodes, and GetExcludedStatusCodes methods to the Prometheus struct (lines 362-379).
    • Modifies the HandlerFunc to check if the request URL path or response status code is in the exclusion lists before creating metrics (lines 385-393).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is the purpose of the slices package in Go, introduced in Go 1.21?

Click here for the answer
The `slices` package in Go provides various utility functions for working with slices, such as searching, comparing, and manipulating slices. It aims to provide a more convenient and efficient way to perform common slice operations.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces functionality to exclude specific URL paths and response status codes from being monitored by Prometheus. This is a useful addition for filtering out irrelevant or noisy metrics. The implementation appears straightforward, but there are a few areas that could be improved for clarity and efficiency.

Summary of Findings

  • Global variable usage: The use of global variables excludedPaths and excludedStatusCodes can lead to potential issues with concurrency and testability. Consider using options or a configuration struct to manage these exclusions.
  • Inefficient slice appending: Appending to slices in the ExcludePaths and ExcludeStatusCodes functions without pre-allocation can lead to performance issues if a large number of paths or status codes are excluded. Pre-allocate the slice with the expected capacity to avoid reallocations.
  • Duplicated conditional logic: The conditional logic to check for excluded paths and status codes is duplicated in the HandlerFunc. This can be simplified by combining the conditions into a single check.

Merge Readiness

While the changes introduce valuable functionality, the use of global variables and potential performance issues with slice appending should be addressed before merging. I recommend refactoring the code to use options or a configuration struct for managing exclusions and pre-allocating the slices to improve efficiency. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

Adding appendEfficiently generic function to be used in Exclude functions

Unifying logic to avoid metric creation based on exclusion list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant