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

Maintain sticky flag on LB method validation failure. #1585

Conversation

timoreimann
Copy link
Contributor

@timoreimann timoreimann commented May 10, 2017

We previously did not copy the sticky flag if the load-balancer method validation failed, causing enabled stickiness to be dropped in case of a validation error (which, technically, for us is the same as a load-balancer configuration without an explicitly set method). This change fixes that.

A few refactorings and improvements along the way:

  • Move the frontend and backend configuration steps into separate methods/functions for better testability.
  • Include the invalid method name in the error value and avoid log duplication.
  • Add tests for the backend configuration part.

Fixes #1568.

@timoreimann
Copy link
Contributor Author

@containous/traefik FYI.

/cc @ kleinsasserm.

server/server.go Outdated
log.Debugf("Validation of load balancer method for backend %s failed: %s. Using default method wrr.", backendName, err)
backend.LoadBalancer = &types.LoadBalancer{
Method: "wrr",
Sticky: backend.LoadBalancer.Sticky,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Effectively, this should be the only addition to the production code.

@timoreimann
Copy link
Contributor Author

Integration tests keep failing. Not exactly sure why, will have to investigate.

server/server.go Outdated
}
}

func configureBackends(backends map[string]*types.Backend) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not func (server *Server) configureBackends?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the backend configuration requires nothing from server for now.

Copy link
Member

Choose a reason for hiding this comment

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

I also find this a bit odd to be honest ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can turn it into a receiver method if you really want to, but it would carry the wrong message to the reader (and my IDE's "find usage" function) that server is somehow needed for this method to work properly, which it isn't. It also makes things like testing more complicated.

Effectively, it'd be similar to passing an unused variable to a function call.

Copy link
Member

Choose a reason for hiding this comment

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

@timoreimann I think there is at least 2 reasons to add func (server *Server) to both functions:

  1. it's homogeneous (to the reader, it would be easier to understand if configureFrontends and configureBackends add the same signature)
  2. we could only call configureBackends if we had a reference to a Server which is makes more sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, converted configureBackends into a method.

PTAL again.

@timoreimann timoreimann force-pushed the 1-3-maintain-sticky-flag-on-lb-method-validation-failure branch from 6de81f4 to 1d526a6 Compare May 12, 2017 15:45
Copy link
Member

@emilevauge emilevauge left a comment

Choose a reason for hiding this comment

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

Thanks a lot @timoreimann !
LGTM!

}
}

func (*Server) configureBackends(backends map[string]*types.Backend) {
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@timoreimann timoreimann force-pushed the 1-3-maintain-sticky-flag-on-lb-method-validation-failure branch from 38a2c39 to 1d47418 Compare May 15, 2017 22:05
Copy link
Contributor

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🦁

We previously did not copy the sticky flag if the load-balancer
method validation failed, causing enabled stickiness to be dropped in
case of a validation error (which, technically, for us is the same as a
load-balancer configuration without an explicitly set method). This
change fixes that.

A few refactorings and improvements along the way:

- Move the frontend and backend configuration steps into separate
  methods/functions for better testability.
- Include the invalid method name in the error value and avoid log
  duplication.
- Add tests for the backend configuration part.
@timoreimann timoreimann force-pushed the 1-3-maintain-sticky-flag-on-lb-method-validation-failure branch from 1d47418 to f9839f7 Compare May 15, 2017 22:06
@timoreimann timoreimann merged commit f8e7b55 into traefik:v1.3 May 15, 2017
@timoreimann timoreimann deleted the 1-3-maintain-sticky-flag-on-lb-method-validation-failure branch May 15, 2017 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants