-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #808 from chef/ssd/add-ha-proxy
Use HAProxy to route Postgresql and ElasticSearch connections
- Loading branch information
Showing
14 changed files
with
556 additions
and
3 deletions.
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
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.