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

chore(heartbeat): Refactor heartbeat. #344

Merged
merged 1 commit into from
Jun 7, 2023

Conversation

Blokje5
Copy link
Collaborator

@Blokje5 Blokje5 commented Jun 2, 2023

Description

This is mostly an enablement PR for future follow-ups (e.g. TCP healthcheck). This PR decouples the Heartbeat from e.g. ClusterUser and moves it to a seperate package. I also changed the tests to focus on the actual HeartBeat functionality as opposed of asserting on the struct itself.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Checklist

  • Linter passes correctly
  • Add tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

Does this introduce a breaking change?

  • Yes
  • No

Further comments

"github.com/contentsquare/chproxy/config"
)

var ErrUnexpectedResponse = fmt.Errorf("unexpected response")
Copy link
Collaborator

Choose a reason for hiding this comment

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

since we only use this variable once and only in this package, it might be better to rename it errUnexpectedResponse to avoid polluting the IDE with "useless" variables when using autocomplete (and because it seems cleaner conceptually)

}

// User credentials are not needed
const DefaultEndpoint string = "/ping"
Copy link
Collaborator

Choose a reason for hiding this comment

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

some comment as the one for ErrUnexpectedResponse

if err != nil {
return err
}
if hb.request != DefaultEndpoint && hb.user != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

although it was in the previous code, the hb.user != "" seems useless because this condition is not possible at this point of the code since the NewHeartbeat use a default user in the worst case scenario and this default user must be not empty cf config.go:L461 & proxy.go:L669 .

If we don't want to rely on business code outside of this package (although the test coverage should spot this issue), it might be cleaner to do a check in the func NewHeartbeat(c config.HeartBeat, options ...Option) HeartBeat that there is at least a user not empty (and return an error otherwise). Because, with the current logic, if there is a regression outside of the package, it might result of have the authentication not working.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good point, I included a check in NewHeartbeat to make sure that authentication can't be broken by forgetting to pass a default user.

This is mostly an enablement PR for future follow-ups (e.g. TCP healthcheck).

Signed-off-by: Lennard Eijsackers <lennardeijsackers92@gmail.com>
@Blokje5 Blokje5 force-pushed the chore/refactor-heartbeat branch from 25a963e to 4899a1b Compare June 7, 2023 15:01
@Blokje5 Blokje5 merged commit b1219e0 into ContentSquare:master Jun 7, 2023
@Blokje5 Blokje5 deleted the chore/refactor-heartbeat branch June 7, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants