-
Notifications
You must be signed in to change notification settings - Fork 210
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
Use HAProxy to route Postgresql and ElasticSearch connections #808
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9e9b699
WIP Use HAProxy as to route Postgresql and ElasticSearch connections
stevendanna e6470d4
[omnibus] Better handle bootstrapping with HAProxy
stevendanna a3e3675
[omnibus] Refactor HAProxy cookbook and increase test coverage
stevendanna b48d029
[haproxy] Use default-server to simplify configuration
stevendanna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# | ||
# Copyright 2016 Chef Software, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
name "haproxy" | ||
default_version "1.6.4" | ||
|
||
dependency "zlib" | ||
dependency "pcre" | ||
dependency "openssl" | ||
|
||
license "GPLv2" | ||
license_file "LICENSE" | ||
|
||
# HTTPS is available but certificate validation fails on OS X | ||
source url: "http://www.haproxy.org/download/1.6/src/haproxy-#{version}.tar.gz", | ||
sha256: "e5fa3c604f1fe9ecb6974ccda6705c105ebee14b3a913069fb08f00e860cd230" | ||
|
||
relative_path "haproxy-#{version}" | ||
|
||
build do | ||
env = with_standard_compiler_flags(with_embedded_path) | ||
# | ||
# Many of these are the same environment variables that debian sets | ||
# PREFIX and TARGET are mandatory to get it building under omnibus. | ||
# | ||
build_options = { | ||
"PREFIX" => "#{install_dir}/embedded", | ||
# Use libpcre for regex, libpcre > 8.32 required | ||
# for JIT | ||
"USE_PCRE" => "1", | ||
"USE_PCRE_JIT" => "1", | ||
"USE_ZLIB" => "1", | ||
"USE_OPENSSL" => "1", | ||
} | ||
# Required to resolve hostnames to IPv6 addresses | ||
# off-by-default because of prolems on older glibc's | ||
# TODO(ssd): Should we turn this off on RHEL5? | ||
build_options['USE_GETADDRINFO'] = "1" | ||
if intel? | ||
build_options["USE_REGPARM"] = "1" | ||
end | ||
build_options['TARGET'] = if ohai["kernel"] && ohai["kernel"]["name"] == "Linux" | ||
version = Gem::Version.new(String(ohai["kernel"]["release"]).split("-").first) | ||
case | ||
when version >= Gem::Version.new("2.6.28") | ||
"linux2628" | ||
when version >= Gem::Version.new("2.6") | ||
"linux26" | ||
else | ||
"linux24e" | ||
end | ||
else | ||
"generic" | ||
end | ||
build_args = "" | ||
build_options.each { |k,v| build_args << " #{k}=#{v}"} | ||
make "haproxy #{build_args}", env: env | ||
make "install #{build_args}", env: env | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
omnibus/files/private-chef-cookbooks/private-chef/libraries/chef_backend.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'json' | ||
require 'uri' | ||
require 'chef/http' | ||
|
||
module ChefBackend | ||
ETCD_MEMBERS_URL = "/v2/members" | ||
def self.configured_members(node) | ||
ret = {} | ||
node['private_chef']['chef_backend_members'].each_with_index do |member, i| | ||
ret["backend#{i}"] = member | ||
end | ||
ret | ||
end | ||
|
||
def self.etcd_members(ip, port) | ||
ret = {} | ||
raw_members = JSON.parse(etcd_get(ETCD_MEMBERS_URL, ip, port))["members"] | ||
raw_members.each do |m| | ||
ret[m["name"]] = URI.parse(m["peerURLs"].first).host | ||
end | ||
ret | ||
end | ||
|
||
def self.etcd_get(url, ip, port) | ||
client = Chef::HTTP.new("http://#{ip}:#{port}") | ||
client.get(url) | ||
end | ||
end |
55 changes: 55 additions & 0 deletions
55
omnibus/files/private-chef-cookbooks/private-chef/libraries/haproxy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class HAProxyStatus | ||
|
||
attr_accessor :socket | ||
def initialize(sock) | ||
@socket = sock | ||
end | ||
|
||
def server_stats | ||
stats(" -1 4 -1") | ||
end | ||
|
||
def stats(args=nil) | ||
socket.puts("show stat#{args}") | ||
parse_stats_table(read_until_end(socket)) | ||
end | ||
|
||
private | ||
def read_until_end(socket) | ||
ret = [] | ||
while line = socket.gets | ||
ret << line | ||
end | ||
ret | ||
end | ||
|
||
def parse_stats_table(table) | ||
return [] if table.empty? | ||
header, *data = table | ||
header = transform_header(header) | ||
data.map do |line| | ||
parse_status_line(line, header) | ||
end.compact | ||
end | ||
|
||
def transform_header(line) | ||
columns = line.split(",").map(&:strip) | ||
columns[0] = columns[0].gsub("# ", "") | ||
columns | ||
end | ||
|
||
# Incomplete parser for the output of show stats; | ||
# | ||
# Currently only returns the pxname, svname, status | ||
# | ||
def parse_status_line(line, header) | ||
split_line = line.split(",").map(&:strip) | ||
if split_line.first == "" && split_line.length == 1 # Empty line | ||
nil | ||
else | ||
{ pxname: split_line[header.index("pxname")], | ||
svname: split_line[header.index("svname")], | ||
status: split_line[header.index("status")] } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,8 +125,13 @@ def initialize(node) | |
# the defaults set in the recipe. | ||
def run! | ||
begin | ||
BootstrapPreflightValidator.new(node).run! | ||
PostgresqlPreflightValidator.new(node).run! | ||
# When Chef Backend is configured, this is too early to verify | ||
# postgresql accessibility since we need to configure HAProxy | ||
# first | ||
if ! PrivateChef['use_chef_backend'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this flag, we can at some point get rid of the hacky "derive whether we really care about bootstrap" logic that's used to allow a front-end to do bootstrapping. |
||
BootstrapPreflightValidator.new(node).run! | ||
PostgresqlPreflightValidator.new(node).run! | ||
end | ||
SolrPreflightValidator.new(node).run! | ||
BookshelfPreflightValidator.new(node).run! | ||
rescue PreflightValidationFailed => e | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of the dependencies run time dependencies? Is it worth it to prune the non-runtime deps at this time? I'm OK if there's another task to clean this up later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these are runtime deps since we don't do static linking, so zlib, pcre, openssl all have to be in the package.