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

HAProxy: Extend configuration options #193

Conversation

matrixik
Copy link

@matrixik matrixik commented Apr 7, 2017

We configure Monasca using the ansible-based monasca-installer, which is run from Crowbar. This means that the Monasca API services we want to put behind haproxy are not directly under Crowbar's aegis. To put them behind Crowbar-managed haproxy instances we need these new options.

attribute :address, kind_of: String, default: "0.0.0.0"
attribute :port, kind_of: Integer, default: 0
attribute :mode, kind_of: String, default: "http", equal_to: ["http", "tcp", "health"]
attribute :balance, kind_of: String, default: "", equal_to: ["", "roundrobin", "static-rr", "leastconn", "first", "source"]

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [132/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)

Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Copy link
Author

Choose a reason for hiding this comment

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

Done

attribute :options, kind_of: Array, default: []
attribute :servers, kind_of: Array, default: []
attribute :name, kind_of: String, name_attribute: true
attribute :type, kind_of: String, default: "listen", equal_to: ["listen", "backend", "frontend"]

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [108/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)

Copy link
Member

Choose a reason for hiding this comment

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

Any chance you could break the equal_to: ... onto a continuation line?

Copy link
Author

Choose a reason for hiding this comment

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

Done, but hound complain now about Style/ExtraSpacing: Unnecessary spacing detected. in next line...
#193 (comment)

raise "One of the servers has no name." if server["name"].nil?
raise "Server #{server["name"]} has no address." if server["address"].nil?
raise "Server #{server["name"]} has no port." if server["port"].nil?
raise "Server #{server["name"]} has invalid port." if server["port"] < 1 || server["port"] > 65535

Choose a reason for hiding this comment

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

Metrics/LineLength: Line is too long. [104/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)

@matrixik
Copy link
Author

matrixik commented Apr 7, 2017

Sorry about previous PR

@aspiers
Copy link
Member

aspiers commented Apr 7, 2017

@matrixik No problem :) I'm missing context so I could be completely wrong, but you might find this blog post useful?

unless new_resource.default_backend.empty?
section["default_backend"] = new_resource.default_backend
end
unless new_resource.servers.empty?

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)

section["use_ssl"] = new_resource.use_ssl
if new_resource.use_ssl
section["mode"] = "tcp"
else
section["mode"] = new_resource.mode
end
unless new_resource.balance.empty?

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)

unless new_resource.address.empty?
section["address"] = new_resource.address
end
unless new_resource.port == 0

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)
Style/NumericPredicate: Use new_resource.port.zero? instead of new_resource.port == 0. (https://github.com/bbatsov/ruby-style-guide#predicate-methods)

end

section = {}
section["address"] = new_resource.address
section["port"] = new_resource.port
unless new_resource.address.empty?

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)

raise "One of the servers has no name." if server["name"].nil?
raise "Server #{server['name']} has no address." if server["address"].nil?
raise "Server #{server['name']} has no port." if server["port"].nil?
raise "Server #{server['name']} has invalid port." if (server["port"] < 1 || server["port"] > 65535)

Choose a reason for hiding this comment

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

Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)
Style/ParenthesesAroundCondition: Don't use parentheses around the condition of an if. (https://github.com/bbatsov/ruby-style-guide#no-parens-around-condition)
Metrics/LineLength: Line is too long. [106/100] (https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength)

Copy link
Member

Choose a reason for hiding this comment

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

I disagree with Hound CI regarding Style/StringLiteralsInInterpolation, but I agree regarding Style/ParenthesesAroundCondition and Metrics/LineLength.

Copy link
Author

Choose a reason for hiding this comment

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

Should I change back and allow hound to complain about Style/StringLiteralsInInterpolation? Rest done.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to change back :-) Thanks!

new_resource.servers.each do |server|
raise "One of the servers has no name." if server["name"].nil?
raise "Server #{server['name']} has no address." if server["address"].nil?
raise "Server #{server['name']} has no port." if server["port"].nil?

Choose a reason for hiding this comment

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

Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)

else
new_resource.servers.each do |server|
raise "One of the servers has no name." if server["name"].nil?
raise "Server #{server['name']} has no address." if server["address"].nil?

Choose a reason for hiding this comment

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

Style/StringLiteralsInInterpolation: Prefer double-quoted strings inside interpolations. (https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation)

raise "Server #{server['name']} has no address." if server["address"].nil?
raise "Server #{server['name']} has no port." if server["port"].nil?
raise "Server #{server['name']} has invalid port." if (server["port"] < 1 || server["port"] > 65535)
if new_resource.type != "frontend"

Choose a reason for hiding this comment

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

Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||. (https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier)

@@ -23,30 +23,42 @@
# While there is no way to have an include directive for haproxy
# configuration file, this provider will only modify attributes !

if new_resource.port < 1 || new_resource.port > 65535
raise "Invalid port: #{new_resource.port}."
if ! new_resource.port == 0 && new_resource.type == "backend"

Choose a reason for hiding this comment

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

Style/NumericPredicate: Use ! new_resource.port.zero? instead of ! new_resource.port == 0. (https://github.com/bbatsov/ruby-style-guide#predicate-methods)
Style/SpaceAfterNot: Do not leave space between ! and its argument. (https://github.com/bbatsov/ruby-style-guide#no-space-bang)

sjamgade
sjamgade previously approved these changes Apr 10, 2017
@matrixik matrixik force-pushed the update_haproxy branch 2 times, most recently from a9d0618 to bc4402e Compare April 12, 2017 06:53
Copy link
Member

@aspiers aspiers left a comment

Choose a reason for hiding this comment

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

Looks OK modulo the Hound CI style warnings.

attribute :options, kind_of: Array, default: []
attribute :servers, kind_of: Array, default: []
attribute :name, kind_of: String, name_attribute: true
attribute :type, kind_of: String, default: "listen", equal_to: ["listen", "backend", "frontend"]
Copy link
Member

Choose a reason for hiding this comment

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

Any chance you could break the equal_to: ... onto a continuation line?

attribute :address, kind_of: String, default: "0.0.0.0"
attribute :port, kind_of: Integer, default: 0
attribute :mode, kind_of: String, default: "http", equal_to: ["http", "tcp", "health"]
attribute :balance, kind_of: String, default: "", equal_to: ["", "roundrobin", "static-rr", "leastconn", "first", "source"]
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

raise "One of the servers has no name." if server["name"].nil?
raise "Server #{server['name']} has no address." if server["address"].nil?
raise "Server #{server['name']} has no port." if server["port"].nil?
raise "Server #{server['name']} has invalid port." if (server["port"] < 1 || server["port"] > 65535)
Copy link
Member

Choose a reason for hiding this comment

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

I disagree with Hound CI regarding Style/StringLiteralsInInterpolation, but I agree regarding Style/ParenthesesAroundCondition and Metrics/LineLength.

attribute :mode, kind_of: String, default: "http", equal_to: [
"http", "tcp", "health"
]
attribute :balance, kind_of: String, default: "", equal_to: [

Choose a reason for hiding this comment

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

Style/ExtraSpacing: Unnecessary spacing detected.

Copy link
Member

@aspiers aspiers left a comment

Choose a reason for hiding this comment

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

Thanks, I can't see anything obviously wrong with the aggregate changes now. It's a bit hard for me to give a confident +1 however, as I don't know the context surrounding the PR. Normally I would get this from the PR description and the commit messages, but the functionality changes are split across several commits and there is no PR description explaining all the changes. In particular I'm a bit confused why some checks are introduced and then removed again in a later commit. Maybe someone else who knows more about the context can +1.

@matrixik
Copy link
Author

matrixik commented May 23, 2017

It was long time ago and I'm not sure who suggested me to remove this checks. I think they was removed because they are already checked/handled in chef/cookbooks/haproxy/providers/loadbalancer.rb.
Also regarding this change it was needed for when Monasca was supposed to be installed in HA mode and we needed more advanced HAProxy configuration to handle relaying communication with influxdb and influxdb-relay in consistent manner so that from the outside this two looks exactly the same as communicating with only influxdb.

@matrixik
Copy link
Author

I also wanted to have separate commits for each functionality but I can squash all if you want.

attribute :mode, kind_of: String, default: "http", equal_to: [
"http", "tcp", "health"
]
attribute :balance, kind_of: String, default: "", equal_to: [

Choose a reason for hiding this comment

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

Layout/ExtraSpacing: Unnecessary spacing detected.

@matrixik
Copy link
Author

matrixik commented Jun 2, 2017

@aspiers Squashed and rebased.

@jgrassler
Copy link

Some high level context on why we need this: we configure Monasca using the ansible based monasca-installer, which is run from Crowbar. This means that the Monasca API services we want to put behind haproxy are not directly under Crowbar's aegis. To put them behind Crowbar managed haproxy instances we need these new options.

@aspiers
Copy link
Member

aspiers commented Jun 16, 2017

@jgrassler Thanks a lot, that's really helpful. In the future please just add this kind of context to the PR description :-) It's hard to find it when it's buried in a stream of comments. (On this occasion I've just copied your info to the description.)

Now it's possible to configure separately frontend and backend and hide
many different services with one frontend based on access path.
E.g. `/write` can go to writable backend and `/read` could go only
to read-only backend.

Add `acl`, `use_backend` and `default_backend` to configurable
attributes.
Does not require server for frontend and does not require bind
configuration, frontent services does not need to bind to any
address when they are only used for backend services.
@matrixik
Copy link
Author

Rebased.

@matrixik
Copy link
Author

matrixik commented Oct 6, 2017

I no longer actively work on this so closing.

@matrixik matrixik closed this Oct 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

7 participants