Skip to content
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

Merged
merged 21 commits into from
May 24, 2018

Conversation

truthbk
Copy link
Member

@truthbk truthbk commented Mar 19, 2018

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 the diagnostics 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

  • Bumped the check version in manifest.json
  • Bumped the check version in datadog_checks/{integration}/__init__.py
  • Updated CHANGELOG.md. Please use Unreleased as the date in the title
    for the new section.
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo

Additional Notes

Refactoring of the project scopes is in order (and in progress)

truthbk added 5 commits March 19, 2018 18:40
No need to specify project per instace if you want
them all.

[openstack] collect service catalog for unscoped instances
[openstack][test] adding some unscoped authentication test cases

[openstack] tag is project_name - renaming
@truthbk truthbk force-pushed the jaime/openstack_unscoped branch from 464ffd0 to b7f9d06 Compare March 19, 2018 17:40
truthbk and others added 3 commits March 21, 2018 13:12
* 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
@truthbk truthbk force-pushed the jaime/openstack_unscoped branch from 07d482e to 5406ba7 Compare March 28, 2018 16:03
nmuesch added 8 commits April 11, 2018 16:02
* 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
@@ -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)
Copy link
Contributor

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.

Copy link
Collaborator

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do data=payload

Copy link
Collaborator

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"):
Copy link
Contributor

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
Copy link
Contributor

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')
Copy link
Contributor

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)
Copy link
Contributor

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?

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
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data=payload

Copy link
Collaborator

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:
Copy link
Contributor

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

ofek
ofek previously approved these changes May 11, 2018
@nmuesch nmuesch changed the title [openstack] adding support for unscoped access Added support for unscoped access May 18, 2018
@nmuesch nmuesch changed the title Added support for unscoped access Added support for unscoped access, implemented caching mechanism to reduce API calls to Nova May 18, 2018
@nmuesch nmuesch added this to the 6.3 milestone May 22, 2018
@nmuesch
Copy link
Collaborator

nmuesch commented May 22, 2018

@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.

@nmuesch nmuesch merged commit f1128ea into master May 24, 2018
@masci masci deleted the jaime/openstack_unscoped branch September 3, 2018 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants