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

Support Fluentd config API endpoint for metadata collection #6062

Merged
merged 6 commits into from
Mar 18, 2020

Conversation

hithwen
Copy link
Contributor

@hithwen hithwen commented Mar 16, 2020

Use updated config rest endpoint for metadata collection and fallback to cli for older versions of fluentd

@hithwen hithwen requested a review from a team as a code owner March 16, 2020 11:48
@codecov
Copy link

codecov bot commented Mar 16, 2020

Codecov Report

Merging #6062 into master will increase coverage by 6.44%.
The diff coverage is 90.69%.

Impacted Files Coverage Δ
fluentd/datadog_checks/fluentd/fluentd.py 88.75% <81.81%> (-2.56%) ⬇️
fluentd/tests/test_integration.py 100.00% <100.00%> (ø)
fluentd/tests/test_integration_and_e2e.py 86.95% <100.00%> (+0.59%) ⬆️
fluentd/tests/test_metadata.py 100.00% <100.00%> (ø)
fluentd/tests/util.py 100.00% <100.00%> (ø)
vsphere/datadog_checks/vsphere/config.py
...tadog_checks/base/checks/kube_leader/base_check.py
etcd/tests/common.py
linux_proc_extras/tests/common.py
iis/datadog_checks/iis/__init__.py
... and 901 more

Copy link
Contributor

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

Awesome! Just a bunch of nits

from .common import FLUENTD_VERSION

requires_1_9 = pytest.mark.skipif(
FLUENTD_VERSION is None or FLUENTD_VERSION != '1.9.3',
Copy link
Member

@AlexandreYang AlexandreYang Mar 16, 2020

Choose a reason for hiding this comment

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

Should be >= instead of != ?

That will ease maintenance if we add new versions to tox.ini that also need metadata test or update 1.9.3 to something higher.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wary of using >= with a string

>>> '1.9.3' > '1.10.3'
True

Copy link
Member

Choose a reason for hiding this comment

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

You can maybe use this:

>>> from packaging import version
>>> version.parse("1.9.3") >= version.parse("1.10.3")
False

Copy link
Contributor

Choose a reason for hiding this comment

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

We could even build a pair of @requires_below_1_8_0/@requires_above_1_8_0 since this is the exact pivot version for the things we're testing (we don't actually care that we use 1.9.0 vs 0.12, it's only important that there's a version before 1.8.0 and one after).

Copy link
Contributor

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

New bunch of nits building on @AlexandreYang's comments :-)

config = r.json()
raw_version = config.get('version')
except Exception as e:
self.log.debug("No config could be retrieved from %s: %s", self.config_url, e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we can simplify the logic a bit by applying the fallback here, dropping the need for raw_version = None initially. Maybe we can also embed the minimal fluentd version for background:

Suggested change
self.log.debug("No config could be retrieved from %s: %s", self.config_url, e)
self.log.debug("No config could be retrieved from %s: %s", self.config_url, e)
# Fall back to command line as this may be an older version of Fluentd (< 1.8.0)
raw_version = self._get_version_from_command_line()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

raw_version = config.get('version')
Will return None (no exception) if the request to the config endpoint is succesfull but is an older version of fluentd

from .common import FLUENTD_VERSION

requires_1_9 = pytest.mark.skipif(
FLUENTD_VERSION is None or FLUENTD_VERSION != '1.9.3',
Copy link
Contributor

Choose a reason for hiding this comment

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

We could even build a pair of @requires_below_1_8_0/@requires_above_1_8_0 since this is the exact pivot version for the things we're testing (we don't actually care that we use 1.9.0 vs 0.12, it's only important that there's a version before 1.8.0 and one after).

@florimondmanca florimondmanca changed the title update fluentd metadata collection Support Fluentd config API endpoint for metadata collection Mar 17, 2020
@florimondmanca
Copy link
Contributor

I went ahead and updated the PR title :-)

@hithwen hithwen requested a review from florimondmanca March 18, 2020 12:15
Copy link
Member

@AlexandreYang AlexandreYang left a comment

Choose a reason for hiding this comment

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

LGTM, just a small nit.

self.url = self.instance.get('monitor_agent_url')
parsed_url = urlparse(self.url)
self.monitor_agent_host = parsed_url.hostname
self.monitor_agent_port = parsed_url.port or 24220
Copy link
Member

Choose a reason for hiding this comment

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

(nit) Might be good to have the default port as constant DEFAULT_PORT = 24220.

@hithwen hithwen merged commit 666f871 into master Mar 18, 2020
@hithwen hithwen deleted the julia/update-fluentd-metadata-collection branch March 18, 2020 13:59
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