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

[flare] Add JMXFetch-specific info #1726

Merged
merged 10 commits into from
Jul 2, 2015
Merged

Conversation

olivielpeau
Copy link
Member

Adds in a jmxinfo directory:

  • 2 JMXFetch status files: jmx_status.yaml and jmx_status_python.yaml
  • JMXfetch commands output: list_matching_attributes and list_everything
  • java -version output (using the configured java path) in a java_version.log file

@remh One thing that may not work properly in flare is the change I've made here https://github.com/DataDog/dd-agent/compare/olivielpeau/jmx-flare?expand=1#diff-64a477c26f008c29252aad6c1499c099R271 , which basically leaves file descriptors open (close_fds=False) when the JMXFetch subprocess is launched from the flare command. Do you know what issues can happen when the main process leaves the file descriptors open ?

cc @degemer @yannmh

if os.path.exists(temp_path):
os.remove(temp_path)
backup_out, backup_err = sys.stdout, sys.stderr
backup_handlers = logging.root.handlers[:]
out, err = StringIO.StringIO(), StringIO.StringIO()
if logger_name:
# If specified, redirect logger output to `out`
logger = logging.getLogger(logger_name)
Copy link
Member

Choose a reason for hiding this comment

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

Since you send the output of jmxfetch to stdout (https://github.com/DataDog/dd-agent/pull/1726/files#diff-64a477c26f008c29252aad6c1499c099R283), do you still need this ? I guess it's for jmxfetch.py, what does it log ? (I have no idea, just asking)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's for jmxfetch.py indeed, it logs exceptions that occur, problems with configuration files, and the exact command that is used to launch JMXFetch (which includes the java bin path and JVM options)

@degemer
Copy link
Member

degemer commented Jun 29, 2015

Really nice, thanks !
Two remarks on the output of the flare command:

  • jmx commands output is always collected even if no integration is setup (files are ~empty, but you still display collecting java version), I think it might mislead users, could you not collect it if no integration using jmxfetch is setup ? (JMXFetch.should_run() ?)
  • when LOG_LEVEL: DEBUG (support recommends to do it before sending logs, so it's quite often), the ouptut is really verbose, maybe too much. Do you know if you could remove these debug statements (users won't have to debug flare) ?
    screen shot 2015-06-29 at 12 20 51

Watchdog,
)
from utils.flare import configcheck, Flare
from utils.jmx_command import jmx_command
Copy link
Member

Choose a reason for hiding this comment

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

👍 for the cleanup !

Maybe we should merge utils.jmx_command and utils.jmxfiles to have only a single JMX util package. What do you think ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, that makes a lot of sense, I'll regroup them in one utils.jmx module ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm actually I get circular imports when the two are merged together, as jmxfetch imports utils.jmx (for the JMXFiles class) that itself imports jmxfetch (for the JMXFetch class used by jmx_command).

So unless there's a better solution I'll leave the two modules separated for now...

Copy link
Member

Choose a reason for hiding this comment

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

Importing JMXFetch in the scope of the method only, would prevent this:

def jmx_command()
  from jmxfetch import JMX_LIST_COMMANDS, JMXFetch
  ...

@yannmh
Copy link
Member

yannmh commented Jun 29, 2015

Another great feature, that will make support way easier. Thanks @olivielpeau.

Can you attach an example of a flare archive to have an idea of what it looks like ?

@olivielpeau olivielpeau force-pushed the olivielpeau/jmx-flare branch from b507c0b to 7047f84 Compare June 29, 2015 21:12
@olivielpeau olivielpeau force-pushed the olivielpeau/jmx-flare branch 2 times, most recently from 7733c03 to 378fdae Compare June 29, 2015 22:30
@olivielpeau
Copy link
Member Author

Thanks a lot for your reviews @yannmh and @degemer!

I've added two commits that:

  • capture the whole output of the commands run by flare (so that users only see the actual output from flare)
  • only add jmx info if a valid jmx config file is present (as evaluated by JMXFetch.should_run())

And here is an example flare archive: https://www.dropbox.com/s/orjuu2kbn9d1aol/datadog-agent-2015-06-30-15-03-16.tar.bz2?dl=0

os.path.join('jmxinfo', 'java_version.log'),
# We use lambda so that JMXFetch.get_configuration is evaluated in _add_command_output_tar,
# which captures the logging output from JMXFetch
lambda: self._java_version(JMXFetch.get_configuration(get_confd_path())[2])
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicky: we are also adding the output of JMXFetch.get_configuration(get_confd_path()) to java_version.log. Is it intended ?

>>>> STDOUT <<<<
tomcat check does not have a valid JMX configuration: You need to have at least one instance defined in the YAML file for this check
Popen(['java', '-version'], stderr = -2, stdout = -1) called
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

>>>> STDERR <<<<

Maybe we could drop it and add a >>>> CMD <<<< section to _add_command_output_tar with the actual command printed (in this case it's interesting as it may contains a custom java path).

@yannmh
Copy link
Member

yannmh commented Jul 1, 2015

Looks great @olivielpeau. Let's merge it whenever you want.

- extract JMXFetch setup and launch from agent.py to a separate
module to allow JMXFetch call from flare
- put all jmx utils (ie JMXFiles and the new jmx_command)
in a single utils.jmx module
- To make it easier to get JMXFetch's configuration from flare,
`get_configuration` becomes a classmethod that calls `_is_jmx_check` as
a staticmethod
- For more consistency, `check_list` is renamed to `checks_list`
The user should not see any output from the called commands.

In `check_status.py`, stop assuming that all streams have a `name` attribute
(for instance `StringIO.StringIO` instances do not have one).
The output/loggers capturing logic has been extracted in a
separate method to allow retrieving the returned value of the command
(useful here to get the value `jmx_process.shoud_run()`)
@olivielpeau olivielpeau force-pushed the olivielpeau/jmx-flare branch from 5660d86 to a4dd433 Compare July 1, 2015 22:50
@olivielpeau
Copy link
Member Author

Thanks @yannmh for your very good points ;)

I've merged jmx_command and JMXFiles in a single utils.jmx module and fixed an issue that could make flare fail silently (see 5c75b06).

Now commands can also have an optional description. jmxinfo/java_version.log now looks like (note that the Popen line is only there when the log_level is DEBUG):

>>>> CMD <<<<
java -version
>>>> STDOUT <<<<
Popen(['java', '-version'], stderr = -2, stdout = -1) called
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

>>>> STDERR <<<<

from config import _windows_commondata_path
from util import yDumper
from config import _windows_commondata_path, get_confd_path
from util import get_os, yDumper
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this import ? (get_os) If get_confd_path doesn't have a get_os(), it will call it itself, so it's no necessary.

These exceptions are output either to stderr or to the returned err stream
Also remove the output of JMXFetch.get_configuration as it is redundant
Removed it as get_confd_path calls get_os on its own.
@olivielpeau olivielpeau force-pushed the olivielpeau/jmx-flare branch from a4dd433 to 3ce28db Compare July 2, 2015 19:16
@olivielpeau
Copy link
Member Author

Thanks again @degemer! I've changed the get_os import and the handling of exceptions:

  • exceptions from commands which output is printed to a file in the tar are printed in the file
  • exceptions from commands which output is not printed at all are printed in stderr
  • all Exceptions raised in those commands are handled by flare

@degemer
Copy link
Member

degemer commented Jul 2, 2015

[flare] Fix typo is not going to work as a commit short desc.
Otherwise, really nice additions, when it's fixed, :shipit: !

@olivielpeau olivielpeau force-pushed the olivielpeau/jmx-flare branch from 3ce28db to 4981b5a Compare July 2, 2015 19:34
@olivielpeau
Copy link
Member Author

Haha, I guess I got lazy on this one, I've fixed it, thanks!

Will merge as soon as the ci passes.

@olivielpeau olivielpeau added this to the 5.5.0 milestone Jul 2, 2015
olivielpeau added a commit that referenced this pull request Jul 2, 2015
@olivielpeau olivielpeau merged commit 5ba2c66 into master Jul 2, 2015
@olivielpeau olivielpeau deleted the olivielpeau/jmx-flare branch July 2, 2015 20:17
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