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

checkshttp #230

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

checkshttp #230

wants to merge 26 commits into from

Conversation

jesusfcr
Copy link
Contributor

@jesusfcr jesusfcr commented Dec 4, 2024

  • Accept requests from http
  • Add NewCheckLogFromContext func
  • Upgrade dependencies
  • Fix lints
  • Allow env variables in command exec helpers
  • Migrate from travis to GH actions

bootstrapper.go Outdated Show resolved Hide resolved
internal/http/check.go Outdated Show resolved Hide resolved
internal/http/check.go Show resolved Hide resolved
internal/http/check.go Outdated Show resolved Hide resolved
internal/http/check.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
@jesusfcr jesusfcr requested a review from seilagamo December 16, 2024 13:34
helpers/command/command.go Outdated Show resolved Hide resolved
helpers/command/command.go Outdated Show resolved Hide resolved
helpers/command/command.go Outdated Show resolved Hide resolved
internal/http/check_test.go Outdated Show resolved Hide resolved
internal/http/check.go Outdated Show resolved Hide resolved
internal/http/check_test.go Outdated Show resolved Hide resolved
internal/http/check_test.go Outdated Show resolved Hide resolved
internal/http/check_test.go Outdated Show resolved Hide resolved
internal/http/check_test.go Outdated Show resolved Hide resolved
internal/http/check_test.go Outdated Show resolved Hide resolved
@jesusfcr jesusfcr force-pushed the checkshttp branch 5 times, most recently from 82a6f10 to 7913b74 Compare December 18, 2024 13:55
@jesusfcr jesusfcr force-pushed the checkshttp branch 5 times, most recently from 1fabcb4 to 48daaf8 Compare December 18, 2024 16:54
.github/workflows/build.yaml Outdated Show resolved Hide resolved
.github/workflows/build.yaml Outdated Show resolved Hide resolved
config/config.go Outdated
Comment on lines 127 to 134
port := os.Getenv(httpPort)
if port != "" {
p, err := strconv.Atoi(port)
if err == nil {
c.Port = &p
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change the signature of the function to return an error if the port is not valid.

Suggested change
port := os.Getenv(httpPort)
if port != "" {
p, err := strconv.Atoi(port)
if err == nil {
c.Port = &p
}
}
port := os.Getenv(httpPort)
if port != "" {
if p, err := strconv.Atoi(port); err != nil {
return fmt.Errorf("invalid port number: %v", port)
}
c.Port = &p
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

This API is a mess. There are too many functions that do the same with small variations and very verbose names. It should be rewritten. But, of course, not in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only that, IMHO they should be in an internal package inside vulcan-checks. See adevinta/vulcan-checks#786

helpers/git.go Outdated Show resolved Hide resolved
// shutting down the http server and waiting
func (c *Check) Shutdown() error {
// Send the exit signal to shutdown the server.
c.exitSignal <- syscall.SIGTERM
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 use different channels for the signals and the user shutdown order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 877c330

// Send the exit signal to shutdown the server.
c.exitSignal <- syscall.SIGTERM

c.shuttedDown = make(chan int)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd initialize the channel on the constructor and maybe rename it to done and change its type to chan bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 877c330

Comment on lines 133 to 137
if c.shuttedDown != nil {
c.Logger.Info("Notifying shuttedDown")
c.shuttedDown <- 1
c.Logger.Info("Notified shuttedDown")
}
Copy link
Contributor

@jroimartin jroimartin Jan 23, 2025

Choose a reason for hiding this comment

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

With the proposed changes I think this can be replaced with:

Suggested change
if c.shuttedDown != nil {
c.Logger.Info("Notifying shuttedDown")
c.shuttedDown <- 1
c.Logger.Info("Notified shuttedDown")
}
c.Logger.Info("Notifying shutdown")
c.done <- true
c.Logger.Info("Notified shutdown")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 877c330

}
}()

s := <-c.exitSignal
Copy link
Contributor

@jroimartin jroimartin Jan 23, 2025

Choose a reason for hiding this comment

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

I would replace it with a select that checks both the signals and the user channels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 877c330


// ServeHTTP implements an HTTP POST handler that receives a JSON encoded job, and returns an
// agent.State JSON encoded response.
func (c *Check) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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 not call this function ServeHttp. It is like Check implements http.Handler but that's not the real purpose.

Copy link
Contributor Author

@jesusfcr jesusfcr Jan 24, 2025

Choose a reason for hiding this comment

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

done 877c330

@jesusfcr jesusfcr requested a review from jroimartin January 24, 2025 14:58
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.

3 participants