-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added support for unscoped access, implemented caching mechanism to reduce API calls to Nova #1276
Conversation
99cc751
to
9299e18
Compare
9df513e
to
68b2da9
Compare
No need to specify project per instace if you want them all. [openstack] collect service catalog for unscoped instances
[openstack] fix typo
[openstack][test] adding some unscoped authentication test cases [openstack] tag is project_name - renaming
464ffd0
to
b7f9d06
Compare
* add metric about backoff * Small fixes * Remove yolo mode * Cleaner if statement * Fix test on argument position * fix'
…ghtly [openstack] watch out for references - copy list
07d482e
to
5406ba7
Compare
* Creates a caching system and calls the /servers/details endpoint directly
…1512) * Only set the changes-since once on run * Remove overall project_name tag, let individual servers do it * Add lots of debug logs * Gaurantees non active servers are removed from cache * Resilient double checking of active server * Final cleanup of code/comments
.github/PULL_REQUEST_TEMPLATE.md
Outdated
@@ -16,7 +16,7 @@ is available in our contribution guidelines. | |||
|
|||
### Versioning | |||
|
|||
- [ ] Bumped the check version in `manifest.json` | |||
- [ ] Bumped the check version in `manifest.json` (or update manifest version to 1.0.0 and drop check version) |
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.
Let's not say this as we can only do that for ported checks.
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.
Agreed, I think this got pulled in during some git magic to rebase things. I'll get rid of it. 🙇
auth_url = urljoin(keystone_server_url, "{0}/auth/tokens".format(DEFAULT_KEYSTONE_API_VERSION)) | ||
headers = {'Content-Type': 'application/json'} | ||
|
||
resp = requests.post(auth_url, headers=headers, data=json.dumps(payload), verify=ssl_verify, timeout=DEFAULT_API_REQUEST_TIMEOUT, proxies=proxy) |
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.
Just do data=payload
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.
It looks like you can only do that if you are using requests 2.14+ http://docs.python-requests.org/en/master/community/updates/#id20 Currently in testing on an Agent with a lower version doing this results in a 400 response code.
or not user.get('name')\ | ||
or not user.get('password')\ | ||
or not user.get("domain")\ | ||
or not user.get("domain").get("id"): |
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.
Could we make this
if not (
user and
user.get('name') and
user.get('password') and
user.get("domain") and
user.get("domain").get("id")
):
raise IncompleteAuthScope() | ||
|
||
if auth_scope['project'].get('name'): | ||
# We need to add a domain scope to avoid name clashes. Search for one. If not raise IncompleteConfig |
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.
Should this say we raise IncompleteAuthScope
?
auth_scope['project']['domain']['name'] = auth_scope['project']['domain'].pop('id') | ||
else: | ||
elif auth_scope: | ||
auth_scope['project']['name'] = auth_scope['project'].pop('id') |
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.
Let's make this
if auth_scope:
if 'domain' in auth_scope['project']:
auth_scope['project']['domain']['name'] = auth_scope['project']['domain'].pop('id')
else:
auth_scope['project']['name'] = auth_scope['project'].pop('id')
if not keystone_server_url: | ||
raise IncompleteConfig() | ||
|
||
ssl_verify = init_config.get("ssl_verify", False) |
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.
Shouldn't this default to True
?
# ssl_verify: true |
project_auth_token = token_resp.headers.get('X-Subject-Token') | ||
except (requests.exceptions.HTTPError, requests.exceptions.Timeout, requests.exceptions.ConnectionError) as e: | ||
# TODO: Raise something | ||
pass |
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.
Let's handle this todo
headers = {'Content-Type': 'application/json'} | ||
auth_url = urljoin(keystone_server_url, "{0}/auth/tokens".format(DEFAULT_KEYSTONE_API_VERSION)) | ||
|
||
resp = requests.post(auth_url, headers=headers, data=json.dumps(payload), verify=ssl_verify, timeout=DEFAULT_API_REQUEST_TIMEOUT, proxies=proxy) |
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.
data=payload
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.
Same comment as above about getting a 400 from the request
try: | ||
resp = requests.get(url, headers=headers, verify=self._ssl_verify, params=params, | ||
timeout=DEFAULT_API_REQUEST_TIMEOUT, proxies=self.proxy_config) | ||
resp.raise_for_status() | ||
except requests.exceptions.HTTPError: | ||
except requests.HTTPError as e: |
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.
requests.exceptions.HTTPError
was correct
@truthbk As this was originally the work of your PR, do you have any concerns with this being merged as-is? Tests have been added with regards to the caching feature and I think all is well here from my side. |
What does this PR do?
This PR aims to enable unscoped access to multiple projects a user may authenticate to via a single configuration instance. As such a user shall only provide the set of credentials which we will then use to collect all authorized projects, create scopes for each individual project, and then iterate the projects collecting metrics and tagging them accordingly.
This PR also implements a caching mechanism to hold information about server details between check runs, things like project_name, server_id, etc. This was we can reduce the size of the API call on each check run and uses the
changes-since
filter on the/servers/details
endpoint to only pull in newly ACTIVE servers into the cache. We remove servers when we hit an exception trying to access thediagnostics
endpoint on that server because that is an indication that its DOWN.We also cache the project name to remove a redundant API call of mapping tenant id to project name multiple times in the check.
Motivation
Added flexibility, ease for maintenance, shorten collection time and reduce stress on the openstack suite of APIs.
Testing Guidelines
An overview on testing
is available in our contribution guidelines.
Versioning
manifest.json
datadog_checks/{integration}/__init__.py
CHANGELOG.md
. Please useUnreleased
as the date in the titlefor the new section.
Additional Notes
Refactoring of the project scopes is in order (and in progress)