Permalink
Browse files

added support to follow cnames

  • Loading branch information...
1 parent 6028a73 commit 0e5ca7f669e47215393a66cb9f724d85be426acd @mbroome committed May 1, 2011
Showing with 40 additions and 24 deletions.
  1. +13 −1 README
  2. +23 −22 bin/backend.py
  3. +3 −1 bin/view.py
  4. +1 −0 etc/poller.xml
View
14 README
@@ -1,6 +1,14 @@
Welcome to Open Global Server LoadBalancer!
-Open Global Server LoadBalancer (oGSLB) is a way to use dns to distribute requests to destinations while accounting for additional metrics about the destination. Metrics can include such things as health, bandwidth and even arbitrary priorities associated with destinations. The metrics data collected by oGSLB is feed into PowerDNS via a piped backend to be served to clients.
+Open Global Server LoadBalancer (ogslb) is a way to use dns to distribute requests to destinations while accounting for additional metrics about the destination. Metrics can include such things as health, bandwidth and even arbitrary priorities associated with destinations. The metrics data collected by oGSLB is feed into PowerDNS via a piped backend to be served to clients.
+
+Features:
+Balance requests evenly across multiple destinations
+Destinations can include ip addresses (A records) as well as hostnames (CNAME records) or a mix of both
+Custom protocols. User created metrics can include anything such as requests/sec, bandwidth, response time.
+Fallthrough architecture. If a problem arises in ogslb, powerdns will bypass it.
+Only need to configure addresses that need healthchecking. If ogslb does not own the address, it tells powerdns so and lets it be served normally.
+Ability to create primary/secondary configuration with automatic dns failover.
Metrics:
Metrics within oGSLB are collected via custom python modules used to collect data about a destination. All such metrics have a default 10sec timeout on the test. These modules live in the proto directory and are named after the kind of test they perform. Metrics are stored in a redis database for use by the pdns backend process when filling dns requests. Currently, the metrics oGSLB understands how to collect include:
@@ -17,3 +25,7 @@ oGSLB associates priorities with each of the collected metrics. Priorities are
Traffic Balancing:
oGSLB uses the combination of metrics and thier associated priorities to rank destinations. Each metric about a destination includes the priority of that metric. When a dns request is being filled, the last 120seconds of metrics about the hostname is pulled from redis. For each ip address that could be used for the given name, all of the priority numbers are added up. Once each ip address has it's total priority number calculated, a random selection is made from the highest priority number. That selection is the ip address returned to the client as the destination for the requested hostname.
+
+Mitchell Broome
+mitchell.broome@gmail.com
+
View
@@ -1,11 +1,10 @@
#!/usr/bin/python
import sys, os
-#scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))
+scriptPath = os.path.realpath(os.path.dirname(sys.argv[0]))
# account for where we live
-#sys.path.append(scriptPath + '/..')
-#sys.path.append(scriptPath + '/../lib')
-sys.path.append('/opt/ogslb/lib')
+sys.path.append(scriptPath + '/..')
+sys.path.append(scriptPath + '/../lib')
from TimeSeries import *
import time
@@ -26,23 +25,27 @@ def __init__(self, query):
"""
(_type, qname, qclass, qtype, _id, ip) = query
self.has_result = False # has a DNS query response
+
+ # we only deal with a few of the query types
if(qtype == 'A' or qtype == 'ANY' or qtype == 'CNAME'):
qname_lower = qname.lower()
self.results = []
+ selectedAddres = ''
+ recordType = ''
try:
t = TimeSeries()
r = t.zget(qname_lower)
+ addressData = {}
priorities = {}
for a in r:
try:
priorities[a['address']] = int(priorities[a['address']]) + int(a['priority'])
except:
priorities[a['address']] = int(a['priority'])
-
-# priorities['1.2.3.4'] = 70
+ addressData[a['address']] = a
high = 0
@@ -57,29 +60,29 @@ def __init__(self, query):
addresss.append(k)
+ debug_log("########## address list");
debug_log(addresss)
-# debug_log( random.choice(ips) )
+ debug_log("########## pick an address");
+ selectedAddres = random.choice(addresss)
+
+ try:
+ if addressData[selectedAddres]['recordtype']:
+ recordType = addressData[selectedAddres]['recordtype']
+ except:
+ recordType = 'A'
+
+ debug_log("############## here");
+ debug_log(selectedAddres)
+ debug_log(recordType)
- self.results.append('DATA\t%s\t%s\tA\t%d\t-1\t%s' % (qname, qclass, DNSLookup.ttl, random.choice(addresss)))
+ self.results.append('DATA\t%s\t%s\t%s\t%d\t-1\t%s' % (qname, qclass, recordType, DNSLookup.ttl, selectedAddres))
self.has_result = True
except:
debug_log("no record")
-# if (qtype == 'A' or qtype == 'ANY') and qname_lower == 'webserver.example.com':
-# self.results.append('DATA\t%s\t%s\tA\t%d\t-1\t1.2.3.4' %
-# (qname, qclass, DNSLookup.ttl))
-# self.results.append('DATA\t%s\t%s\tA\t%d\t-1\t1.2.3.5' %
-# (qname, qclass, DNSLookup.ttl))
-# self.results.append('DATA\t%s\t%s\tA\t%d\t-1\t1.2.3.6' %
-# (qname, qclass, DNSLookup.ttl))
-# self.has_result = True
-# elif (qtype == 'CNAME' or qtype == 'ANY') and qname_lower == 'www.example.com':
-# self.results.append('DATA\t%s\t%s\tCNAME\t%d\t-1\twebserver.example.com' %
-# (qname, qclass, DNSLookup.ttl))
-# self.has_result = True
def str_result(self):
"""return string result suitable for pipe-backend output to PowerDNS."""
@@ -155,8 +158,6 @@ def _fprint(self, message):
if __name__ == '__main__':
logger = Logger()
infile = sys.stdin
- #sys.stdout.close()
- #outfile = os.fdopen(1, 'w', 1)
outfile = sys.stdout
try:
PowerDNSbackend(infile, outfile)
View
@@ -28,15 +28,17 @@
#t.zexpire('www.yahoo.com')
-
+addressData = {}
priorities = {}
for a in r:
try:
priorities[a['address']] = int(priorities[a['address']]) + int(a['priority'])
except:
priorities[a['address']] = int(a['priority'])
+ addressData[a['address']] = a
#priorities['1.2.3.4'] = 70
+pp.pprint(addressData)
pp.pprint(priorities)
View
@@ -5,6 +5,7 @@
<Poll Type="HTTP" url="/" response="google" address="74.125.113.105" tag="homepage" priority="20"/>
<Poll Type="HTTP" url="/" response="google" address="74.125.113.147" tag="homepage" priority="20"/>
<Poll Type="HTTP" url="/" response="google" address="74.125.113.103" tag="homepage" priority="20"/>
+ <Poll Type="HTTP" url="/" address="www.1.google.com" recordtype="CNAME" tag="homepage" priority="20"/>
</VIP>

0 comments on commit 0e5ca7f

Please sign in to comment.