Skip to content

En/1672 disable health check log #1686

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

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

kevin-lockhart-1001
Copy link

Description:

  • Added a dedicated logging middleware to address the issue described in the ticket Disable Logs for Health and Alive Routes #1672
  • Refactored the newHTTPServer function to conditionally include the logging middleware based on the LOG_DISABLE_PROBES environment variable

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

port := testutil.GetFreePort(t)

t.Setenv("HTTP_PORT", strconv.Itoa(port))
t.Setenv("LOG_DISABLE_PROBES", "true")
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the constant you define in the other file

@@ -9,6 +9,8 @@ import (
"gofr.dev/pkg/gofr/config"
)

const LogDisableProbeKey = "LOG_DISABLE_PROBES"
Copy link
Contributor

Choose a reason for hiding this comment

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

The constant should have a clear comment about its purpose

Or simpl prefix it with EnvVar

Suggested change
const LogDisableProbeKey = "LOG_DISABLE_PROBES"
const EnvVarLogDisableProbeKey = "LOG_DISABLE_PROBES"

Comment on lines +39 to +43
if ok, _ := strconv.ParseBool(middlewareConfigs[middleware.LogDisableProbeKey]); !ok {
r.Use(middleware.Logging(c.Logger))
} else {
r.Use(middleware.LoggingSkipHealthCheck(c.Logger))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code looks strange to me

I mean, why having two middlewares?

Copy link
Contributor

Choose a reason for hiding this comment

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

True. Same middleware behaviour should be changed.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, so changing how that logging middleware works now would mean we'd have to toss in a flag as an argument, and since that Logging function is out there for everyone, that'd be a big ol' breaking change. So, wouldn't it make more sense to just spin up a separate logging middleware and then just kinda decide whether to use it or not when we're setting up the server, based on that flag?

@ccoVeille @vikash

@@ -9,6 +9,8 @@ import (
"gofr.dev/pkg/gofr/config"
)

const LogDisableProbeKey = "LOG_DISABLE_PROBES"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this one need to be exported ?

Copy link
Author

Choose a reason for hiding this comment

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

If followed this suggestion, then yes

@@ -9,6 +9,8 @@ import (
"gofr.dev/pkg/gofr/config"
)

const LogDisableProbeKey = "LOG_DISABLE_PROBES"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have used

Suggested change
const LogDisableProbeKey = "LOG_DISABLE_PROBES"
const LogDisableProbeKey = "LOG_PROBES_DISABLED"

Or something like that. Maybe there are other env variables about disabling something

@vikash
Copy link
Contributor

vikash commented May 2, 2025

@kevin-lockhart-1001 Someone else has been implementing this as well: #1681 It might be a good idea to collaborate on this.

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.

4 participants