Repository: mesos Updated Branches: refs/heads/master de7fb43a0 -> 0bbeab258
Generated usage help information in libprocess. Review: https://reviews.apache.org/r/37586 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ed1df952 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ed1df952 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ed1df952 Branch: refs/heads/master Commit: ed1df9520826e55f67f915d251702cacff16db9b Parents: de7fb43 Author: haosdent huang <[email protected]> Authored: Thu Sep 10 01:21:26 2015 -0700 Committer: Michael Park <[email protected]> Committed: Thu Sep 10 02:21:04 2015 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/include/process/help.hpp | 28 +++++++++-------- 3rdparty/libprocess/include/process/system.hpp | 2 -- 3rdparty/libprocess/src/help.cpp | 33 ++++++++++++--------- 3rdparty/libprocess/src/logging.cpp | 4 +-- 3rdparty/libprocess/src/metrics/metrics.cpp | 1 - 3rdparty/libprocess/src/profiler.cpp | 20 +++---------- 6 files changed, 39 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/ed1df952/3rdparty/libprocess/include/process/help.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/help.hpp b/3rdparty/libprocess/include/process/help.hpp index 441f6d1..e7dc670 100644 --- a/3rdparty/libprocess/include/process/help.hpp +++ b/3rdparty/libprocess/include/process/help.hpp @@ -33,32 +33,24 @@ namespace process { // Constructs a Markdown based help "page" for a route with the // following template: // -// ### TL;DR; ### -// tldr -// // ### USAGE ### // usage // +// ### TL;DR; ### +// tldr +// // ### DESCRIPTION ### // description // // references // -// See the 'TLDR', 'USAGE', 'DESCRIPTION', and 'REFERENCES' helpers +// See the 'USAGE', 'TLDR', 'DESCRIPTION', and 'REFERENCES' helpers // below to more easily construct your help pages. std::string HELP( std::string tldr, - std::string usage, std::string description, const Option<std::string>& references = None()); -// Helper for single-line TL;DR; that adds a newline. -inline std::string TLDR(const std::string& tldr) -{ - return tldr + "\n"; -} - - // Helper for single-line usage that puts it in a blockquote as code // and adds a newline. inline std::string USAGE(const std::string& usage) @@ -67,6 +59,13 @@ inline std::string USAGE(const std::string& usage) } +// Helper for single-line TL;DR; that adds a newline. +inline std::string TLDR(const std::string& tldr) +{ + return tldr + "\n"; +} + + template <typename... T> inline std::string DESCRIPTION(T&&... args) { @@ -118,7 +117,10 @@ private: // process. Future<http::Response> help(const http::Request& request); - std::map<std::string, std::map<std::string, std::string> > helps; + // Helper function to get usage path by process id and endpoint name. + std::string getUsagePath(const std::string& id, const std::string& name); + + std::map<std::string, std::map<std::string, std::string>> helps; }; } // namespace process { http://git-wip-us.apache.org/repos/asf/mesos/blob/ed1df952/3rdparty/libprocess/include/process/system.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/include/process/system.hpp b/3rdparty/libprocess/include/process/system.hpp index 7c8b49e..264d948 100644 --- a/3rdparty/libprocess/include/process/system.hpp +++ b/3rdparty/libprocess/include/process/system.hpp @@ -88,8 +88,6 @@ private: return HELP( TLDR( "Shows local system metrics."), - USAGE( - "/system/stats.json"), DESCRIPTION( "> cpus_total Total number of available CPUs", "> load_1min Average system load for last" http://git-wip-us.apache.org/repos/asf/mesos/blob/ed1df952/3rdparty/libprocess/src/help.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/help.cpp b/3rdparty/libprocess/src/help.cpp index e4e0bb6..d358b93 100644 --- a/3rdparty/libprocess/src/help.cpp +++ b/3rdparty/libprocess/src/help.cpp @@ -40,19 +40,14 @@ namespace process { string HELP( string tldr, - string usage, string description, const Option<string>& references) { - // Make sure 'tldr', 'usage', and 'description' end with a newline. + // Make sure 'tldr' and 'description' end with a newline. if (!strings::endsWith(tldr, "\n")) { tldr += "\n"; } - if (!strings::endsWith(usage, "\n")) { - usage += "\n"; - } - if (!strings::endsWith(description, "\n")) { description += "\n"; } @@ -62,9 +57,6 @@ string HELP( "### TL;DR; ###\n" + tldr + "\n" + - "### USAGE ###\n" + - usage + - "\n" + "### DESCRIPTION ###\n" + description; @@ -80,16 +72,29 @@ string HELP( Help::Help() : ProcessBase("help") {} -void Help::add(const string& id, +string Help::getUsagePath(const string& id, const string& name) +{ + return id + strings::remove(name, "/", strings::Mode::SUFFIX); +} + + +void Help::add( + const string& id, const string& name, const Option<string>& help) { - if (id != "help") { // TODO(benh): Enable help for help. + // TODO(benh): Enable help for help. + if (id != "help" && id != "__processes__") { + // Remove tail slash in usage information. + const string path = "/" + getUsagePath(id, name); + if (help.isSome()) { - helps[id][name] = help.get(); + string usage = "### USAGE ###\n" + USAGE(path) + "\n"; + helps[id][name] = usage + help.get(); } else { - helps[id][name] = "## No help page for `/" + id + name + "`\n"; + helps[id][name] = "## No help page for `" + path + "`\n"; } + route("/" + id, "Help for " + id, &Help::help); } } @@ -135,7 +140,7 @@ Future<http::Response> Help::help(const http::Request& request) document += "## `/" + id.get() + "` ##\n"; foreachkey (const string& name, helps[id.get()]) { - const string path = id.get() + name; + const string path = getUsagePath(id.get(), name); document += "> [/" + path + "][" + path + "]\n"; references += "[" + path + "]: " + path + "\n"; } http://git-wip-us.apache.org/repos/asf/mesos/blob/ed1df952/3rdparty/libprocess/src/logging.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/logging.cpp b/3rdparty/libprocess/src/logging.cpp index 3d855e9..db76abe 100644 --- a/3rdparty/libprocess/src/logging.cpp +++ b/3rdparty/libprocess/src/logging.cpp @@ -80,8 +80,6 @@ const std::string Logging::TOGGLE_HELP() return HELP( TLDR( "Sets the logging verbosity level for a specified duration."), - USAGE( - "/logging/toggle?level=VALUE&duration=VALUE"), DESCRIPTION( "The libprocess library uses [glog][glog] for logging. The library", "only uses verbose logging which means nothing will be output unless", @@ -91,7 +89,7 @@ const std::string Logging::TOGGLE_HELP() "**NOTE:** If your application uses glog this will also affect", "your verbose logging.", "", - "Required query parameters:", + "Query parameters:", "", "> level=VALUE Verbosity level (e.g., 1, 2, 3)", "> duration=VALUE Duration to keep verbosity level", http://git-wip-us.apache.org/repos/asf/mesos/blob/ed1df952/3rdparty/libprocess/src/metrics/metrics.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/metrics/metrics.cpp b/3rdparty/libprocess/src/metrics/metrics.cpp index b961750..943ba63 100644 --- a/3rdparty/libprocess/src/metrics/metrics.cpp +++ b/3rdparty/libprocess/src/metrics/metrics.cpp @@ -68,7 +68,6 @@ string MetricsProcess::help() { return HELP( TLDR("Provides a snapshot of the current metrics."), - USAGE("/metrics/snapshot"), DESCRIPTION( "This endpoint provides information regarding the current metrics ", "tracked by the system.", http://git-wip-us.apache.org/repos/asf/mesos/blob/ed1df952/3rdparty/libprocess/src/profiler.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/profiler.cpp b/3rdparty/libprocess/src/profiler.cpp index 65a2e05..0c51556 100644 --- a/3rdparty/libprocess/src/profiler.cpp +++ b/3rdparty/libprocess/src/profiler.cpp @@ -41,15 +41,9 @@ const std::string Profiler::START_HELP() { return HELP( TLDR( - "Starts profiling ..."), - USAGE( - "/profiler/start..."), + "Start profiling."), DESCRIPTION( - "...", - "", - "Query parameters:", - "", - "> param=VALUE Some description here")); + "Start to use google perftools do profiling.")); } @@ -57,15 +51,9 @@ const std::string Profiler::STOP_HELP() { return HELP( TLDR( - "Stops profiling ..."), - USAGE( - "/profiler/stop..."), + "Stops profiling."), DESCRIPTION( - "...", - "", - "Query parameters:", - "", - "> param=VALUE Some description here")); + "Stop to use google perftools do profiling.")); }
