Browse Source

Merge pull request #806 from bkane-msft/bkane/ns1_monitor_tcp_timeouts

Bkane/ns1 monitor tcp timeouts
pull/807/head
Ross McFarland 4 years ago
committed by GitHub
parent
commit
61c34cdd3e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 3 deletions
  1. +17
    -0
      docs/dynamic_records.md
  2. +18
    -2
      octodns/provider/ns1.py
  3. +15
    -1
      tests/test_octodns_provider_ns1.py

+ 17
- 0
docs/dynamic_records.md View File

@ -198,3 +198,20 @@ Sonar check regions (sonar_regions) possible values:
- EUROPE - EUROPE
sonar_type: TCP sonar_type: TCP
``` ```
#### NS1 Health Check Options
| Key | Description | Default |
|--|--|--|
| connect_timeout | Timeout (in seconds) before we give up trying to connect | 2 |
| response_timeout | Timeout (in seconds) after connecting to wait for output. | 10 |
```yaml
---
octodns:
ns1:
healthcheck:
connect_timeout: 2
response_timeout: 10
```

+ 18
- 2
octodns/provider/ns1.py View File

@ -1053,6 +1053,16 @@ class Ns1Provider(BaseProvider):
return monitor_id, self._feed_create(monitor) return monitor_id, self._feed_create(monitor)
def _healthcheck_connect_timeout(self, record):
return record._octodns.get('ns1', {}) \
.get('healthcheck', {}) \
.get('connect_timeout', 2)
def _healthcheck_response_timeout(self, record):
return record._octodns.get('ns1', {}) \
.get('healthcheck', {}) \
.get('response_timeout', 10)
def _monitor_gen(self, record, value): def _monitor_gen(self, record, value):
host = record.fqdn[:-1] host = record.fqdn[:-1]
_type = record._type _type = record._type
@ -1064,10 +1074,16 @@ class Ns1Provider(BaseProvider):
ret = { ret = {
'active': True, 'active': True,
'config': { 'config': {
'connect_timeout': 2000,
'connect_timeout':
# TCP monitors use milliseconds, so convert from
# seconds to milliseconds
self._healthcheck_connect_timeout(record) * 1000,
'host': value, 'host': value,
'port': record.healthcheck_port, 'port': record.healthcheck_port,
'response_timeout': 10000,
'response_timeout':
# TCP monitors use milliseconds, so convert from
# seconds to milliseconds
self._healthcheck_response_timeout(record) * 1000,
'ssl': record.healthcheck_protocol == 'HTTPS', 'ssl': record.healthcheck_protocol == 'HTTPS',
}, },
'frequency': 60, 'frequency': 60,


+ 15
- 1
tests/test_octodns_provider_ns1.py View File

@ -599,7 +599,13 @@ class TestNs1ProviderDynamic(TestCase):
'path': '/_ping', 'path': '/_ping',
'port': 80, 'port': 80,
'protocol': 'HTTP', 'protocol': 'HTTP',
}
},
'ns1': {
'healthcheck': {
'connect_timeout': 5,
'response_timeout': 6,
},
},
}, },
'ttl': 32, 'ttl': 32,
'type': 'A', 'type': 'A',
@ -919,6 +925,14 @@ class TestNs1ProviderDynamic(TestCase):
# No http response expected # No http response expected
self.assertFalse('rules' in monitor) self.assertFalse('rules' in monitor)
record._octodns['ns1']['healthcheck']['connect_timeout'] = 1
monitor = provider._monitor_gen(record, value)
self.assertEquals(1000, monitor['config']['connect_timeout'])
record._octodns['ns1']['healthcheck']['response_timeout'] = 2
monitor = provider._monitor_gen(record, value)
self.assertEquals(2000, monitor['config']['response_timeout'])
def test_monitor_gen_AAAA(self): def test_monitor_gen_AAAA(self):
provider = Ns1Provider('test', 'api-key') provider = Ns1Provider('test', 'api-key')


Loading…
Cancel
Save