Skip to content

Commit

Permalink
Add allow_redirect option (DataDog#10160)
Browse files Browse the repository at this point in the history
* Set  allow_redirects to true by default

* Adds allow_redirects to all tests

* update .gitignore

New folder generated by docker if using docker compose v2

* Fixing tests

* Fix Style

* format fix

* Fix config model and config tests

* fix styles

* Set  allow_redirects to true by default

* Adds allow_redirects to all tests

* update .gitignore

New folder generated by docker if using docker compose v2

* Fixing tests

* Fix Style

* format fix

* Fix config model and config tests

* fix styles

* validate config and models

* Update typo

Co-authored-by: Paul <[email protected]>

* Update checks dependency provider

Co-authored-by: Paul <[email protected]>

* add allow_redirects to http template

* Update .gitignore

Co-authored-by: Paul <[email protected]>

* Validate config

* Validate new models

* validate models

* adds the option in ddev test

Co-authored-by: Paul <[email protected]>
  • Loading branch information
HantingZhang2 and coignetp authored Sep 21, 2021
1 parent 51c8e6c commit 49fbb43
Show file tree
Hide file tree
Showing 147 changed files with 614 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
5 changes: 5 additions & 0 deletions airflow/datadog_checks/airflow/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def shared_timeout(field, value):
return 10


def instance_allow_redirects(field, value):
return True


def instance_assume_role(field, value):
return get_default_field_value(field, value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

allow_redirects: Optional[bool]
assume_role: Optional[str]
auth_token: Optional[AuthToken]
auth_type: Optional[str]
Expand Down
5 changes: 5 additions & 0 deletions amazon_msk/datadog_checks/amazon_msk/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
5 changes: 5 additions & 0 deletions ambari/datadog_checks/ambari/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
4 changes: 4 additions & 0 deletions apache/datadog_checks/apache/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def shared_timeout(field, value):
return 10


def instance_allow_redirects(field, value):
return True


def instance_auth_token(field, value):
return get_default_field_value(field, value)

Expand Down
1 change: 1 addition & 0 deletions apache/datadog_checks/apache/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

allow_redirects: Optional[bool]
apache_status_url: str
auth_token: Optional[AuthToken]
auth_type: Optional[str]
Expand Down
5 changes: 5 additions & 0 deletions apache/datadog_checks/apache/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def shared_timeout(field, value):
return 10


def instance_allow_redirects(field, value):
return True


def instance_auth_token(field, value):
return get_default_field_value(field, value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

allow_redirects: Optional[bool]
auth_token: Optional[AuthToken]
auth_type: Optional[str]
avi_controller_url: str
Expand Down
5 changes: 5 additions & 0 deletions avi_vantage/datadog_checks/avi_vantage/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ instances:
#
# log_requests: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
5 changes: 5 additions & 0 deletions cilium/datadog_checks/cilium/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
5 changes: 5 additions & 0 deletions cisco_aci/datadog_checks/cisco_aci/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## All options defined here are available to all instances.
#
init_config:
Expand Down
5 changes: 5 additions & 0 deletions cockroachdb/datadog_checks/cockroachdb/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
4 changes: 4 additions & 0 deletions consul/datadog_checks/consul/config_models/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def instance_acl_token(field, value):
return get_default_field_value(field, value)


def instance_allow_redirects(field, value):
return True


def instance_auth_token(field, value):
return get_default_field_value(field, value)

Expand Down
1 change: 1 addition & 0 deletions consul/datadog_checks/consul/config_models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Config:
allow_mutation = False

acl_token: Optional[str]
allow_redirects: Optional[bool]
auth_token: Optional[AuthToken]
auth_type: Optional[str]
aws_host: Optional[str]
Expand Down
5 changes: 5 additions & 0 deletions consul/datadog_checks/consul/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
8 changes: 7 additions & 1 deletion consul/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,13 @@ def test_config(test_case, extra_config, expected_http_kwargs, mocker):
check.check(None)

http_wargs = dict(
auth=mock.ANY, cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=mock.ANY, verify=mock.ANY
auth=mock.ANY,
cert=mock.ANY,
headers=mock.ANY,
proxies=mock.ANY,
timeout=mock.ANY,
verify=mock.ANY,
allow_redirects=mock.ANY,
)
http_wargs.update(expected_http_kwargs)
r.get.assert_called_with('/v1/status/leader', **http_wargs)
5 changes: 5 additions & 0 deletions coredns/datadog_checks/coredns/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param service - string - optional
## Attach the tag `service:<SERVICE>` to every metric, event, and service check emitted by this integration.
##
Expand Down
5 changes: 5 additions & 0 deletions couch/datadog_checks/couch/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## Log Section
##
## type - required - Type of log input source (tcp / udp / file / windows_event)
Expand Down
8 changes: 7 additions & 1 deletion couch/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def test_config(test_case, extra_config, expected_http_kwargs):
check.check(instance)

http_wargs = dict(
auth=mock.ANY, cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=mock.ANY, verify=mock.ANY
auth=mock.ANY,
cert=mock.ANY,
headers=mock.ANY,
proxies=mock.ANY,
timeout=mock.ANY,
verify=mock.ANY,
allow_redirects=mock.ANY,
)
http_wargs.update(expected_http_kwargs)

Expand Down
5 changes: 5 additions & 0 deletions couchbase/datadog_checks/couchbase/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
8 changes: 7 additions & 1 deletion couchbase/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ def test_config(test_case, extra_config, expected_http_kwargs, instance):
check.check(instance)

http_wargs = dict(
auth=mock.ANY, cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=mock.ANY, verify=mock.ANY
auth=mock.ANY,
cert=mock.ANY,
headers=mock.ANY,
proxies=mock.ANY,
timeout=mock.ANY,
verify=mock.ANY,
allow_redirects=mock.ANY,
)
http_wargs.update(expected_http_kwargs)
r.get.assert_called_with('http://localhost:8091/pools/default/tasks', **http_wargs)
5 changes: 5 additions & 0 deletions crio/datadog_checks/crio/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ instances:
#
# persist_connections: false

## @param allow_redirects - boolean - optional - default: true
## Whether or not allow following URL redirection.
#
# allow_redirects: true

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down
4 changes: 4 additions & 0 deletions datadog_checks_base/datadog_checks/base/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
DEFAULT_TIMEOUT = 10

STANDARD_FIELDS = {
'allow_redirects': True,
'auth_token': None,
'auth_type': 'basic',
'aws_host': None,
Expand Down Expand Up @@ -217,6 +218,8 @@ def __init__(self, instance, init_config, remapper=None, logger=None):

auth = AUTH_TYPES[auth_type](config)

allow_redirects = is_affirmative(config['allow_redirects'])

# http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification
verify = True
if isinstance(config['tls_ca_cert'], string_types):
Expand Down Expand Up @@ -268,6 +271,7 @@ def __init__(self, instance, init_config, remapper=None, logger=None):
'proxies': proxies,
'timeout': (connect_timeout, read_timeout),
'verify': verify,
'allow_redirects': allow_redirects,
}

# For manual parsing until `requests` properly handles `no_proxy`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,7 @@ def test_requests_wrapper_config():
timeout=(42.0, 42.0),
proxies=None,
verify=True,
allow_redirects=True,
)

check.poll(instance_http['prometheus_endpoint'])
Expand All @@ -2039,4 +2040,5 @@ def test_requests_wrapper_config():
timeout=(42.0, 42.0),
proxies=None,
verify=True,
allow_redirects=True,
)
Loading

0 comments on commit 49fbb43

Please sign in to comment.