-
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
Make OpenMetrics use the RequestsWrapper #5414
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ab10063
Make OpenMetrics use the RequestsWrapper
ofek bfb8de0
fix crio
ofek 7132c57
fix kube_controller_manager
ofek def45f5
fix kube_metrics_server
ofek 5af0373
fix kube_proxy
ofek 69e8b1d
fix kube_scheduler
ofek 080a4c4
fix linkerd
ofek c331c4a
fix nginx_ingress_controller
ofek 12cbd52
fix openmetrics
ofek 6e61bdf
refactor
ofek 6e9375a
final refactor
ofek a9fbda8
fix headers
ofek dc94b6e
fix kubelet
ofek ccd86db
add note
ofek 6a37ed7
address reviews
ofek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,11 @@ | |
import requests | ||
from prometheus_client.parser import text_fd_to_metric_families | ||
from six import PY3, iteritems, itervalues, string_types | ||
from urllib3.exceptions import InsecureRequestWarning | ||
|
||
from ...config import is_affirmative | ||
from ...errors import CheckException | ||
from ...utils.common import to_string | ||
from ...utils.warnings_util import disable_warnings_ctx | ||
from ...utils.http import RequestsWrapper | ||
from .. import AgentCheck | ||
|
||
if PY3: | ||
|
@@ -288,6 +287,25 @@ def create_scraper_configuration(self, instance=None): | |
if config['metadata_metric_name'] and config['metadata_label_map']: | ||
config['_default_metric_transformers'][config['metadata_metric_name']] = self.transform_metadata | ||
|
||
# Set up the HTTP wrapper for this endpoint | ||
ofek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# TODO: Deprecate this behavior | ||
ofek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if config['ssl_verify'] is False: | ||
config.setdefault('tls_ignore_warning', True) | ||
|
||
http_handler = self.http_handlers[endpoint] = RequestsWrapper( | ||
config, self.init_config, self.HTTP_CONFIG_REMAPPER, self.log | ||
) | ||
ofek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
headers = http_handler.options['headers'] | ||
|
||
bearer_token = config['_bearer_token'] | ||
if bearer_token is not None: | ||
headers['Authorization'] = 'Bearer {}'.format(bearer_token) | ||
ofek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# TODO: Determine if we really need this | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we determine now? What's needed to answer this question? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
headers.setdefault('accept-encoding', 'gzip') | ||
ofek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return config | ||
|
||
def parse_metric_family(self, response, scraper_config): | ||
|
@@ -556,53 +574,12 @@ def poll(self, scraper_config, headers=None): | |
raise | ||
|
||
def send_request(self, endpoint, scraper_config, headers=None): | ||
# Determine the headers | ||
if headers is None: | ||
headers = {} | ||
if 'accept-encoding' not in headers: | ||
headers['accept-encoding'] = 'gzip' | ||
headers.update(scraper_config['extra_headers']) | ||
|
||
# Add the bearer token to headers | ||
bearer_token = scraper_config['_bearer_token'] | ||
if bearer_token is not None: | ||
auth_header = {'Authorization': 'Bearer {}'.format(bearer_token)} | ||
headers.update(auth_header) | ||
|
||
# Determine the SSL verification settings | ||
cert = None | ||
if isinstance(scraper_config['ssl_cert'], string_types): | ||
if isinstance(scraper_config['ssl_private_key'], string_types): | ||
cert = (scraper_config['ssl_cert'], scraper_config['ssl_private_key']) | ||
else: | ||
cert = scraper_config['ssl_cert'] | ||
|
||
verify = scraper_config['ssl_verify'] | ||
# TODO: deprecate use as `ssl_verify` boolean | ||
if scraper_config['ssl_ca_cert'] is False: | ||
verify = False | ||
|
||
disable_insecure_warnings = False | ||
if isinstance(scraper_config['ssl_ca_cert'], string_types): | ||
verify = scraper_config['ssl_ca_cert'] | ||
elif verify is False: | ||
disable_insecure_warnings = True | ||
|
||
# Determine the authentication settings | ||
username = scraper_config['username'] | ||
password = scraper_config['password'] | ||
auth = (username, password) if username is not None and password is not None else None | ||
|
||
with disable_warnings_ctx(InsecureRequestWarning, disable=disable_insecure_warnings): | ||
return requests.get( | ||
endpoint, | ||
headers=headers, | ||
stream=True, | ||
timeout=scraper_config['prometheus_timeout'], | ||
cert=cert, | ||
verify=verify, | ||
auth=auth, | ||
) | ||
# We set this up at the first run, but check it again just | ||
# in case a subclass alters the expected order of calls. | ||
if not self.http_handlers: | ||
self.set_up_http_handlers() | ||
ofek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return self.http_handlers[scraper_config['prometheus_url']].get(endpoint, stream=True) | ||
|
||
def get_hostname_for_sample(self, sample, scraper_config): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Mean we need to update all integrations config examples?
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.
Yes, though they'd still work of course so no rush