kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [3/3] kudu git commit: [KUDU-754] add an environment variable for kudu client debugging to stderr
Date Tue, 02 May 2017 21:13:55 GMT
[KUDU-754] add an environment variable for kudu client debugging to stderr

Read environment variable "KUDU_CLIENT_VERBOSE" to get verbose level.
Calls SetVerboseLogLevel to set the specific verbose level.
Notes: The InitGoogleLoggingSafeBasic() already sets the debugging to stderr.

Change-Id: Iab5c7c24395c25184489200283dd38da024c07bb
Reviewed-on: http://gerrit.cloudera.org:8080/6736
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <adar@cloudera.com>
Reviewed-by: Alexey Serbin <aserbin@cloudera.com>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/867fc91c
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/867fc91c
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/867fc91c

Branch: refs/heads/master
Commit: 867fc91cb89def6a46ad1f8173e87ca6970cfa85
Parents: 72e58ec
Author: William Li <william.li.inspur@gmail.com>
Authored: Wed Apr 26 12:02:23 2017 -0700
Committer: Adar Dembo <adar@cloudera.com>
Committed: Tue May 2 21:12:11 2017 +0000

----------------------------------------------------------------------
 src/kudu/client/client-internal.h |  4 ++++
 src/kudu/client/client-test.cc    | 21 +++++++++++++++++++++
 src/kudu/client/client.cc         | 18 ++++++++++++++++++
 3 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/867fc91c/src/kudu/client/client-internal.h
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-internal.h b/src/kudu/client/client-internal.h
index 864a734..c211639 100644
--- a/src/kudu/client/client-internal.h
+++ b/src/kudu/client/client-internal.h
@@ -256,6 +256,10 @@ Status RetryFunc(const MonoTime& deadline,
                  const std::string& timeout_msg,
                  const boost::function<Status(const MonoTime&, bool*)>& func);
 
+// Set logging verbose level through environment variable.
+void SetVerboseLevelFromEnvVar();
+extern const char* kVerboseEnvVar;
+
 } // namespace client
 } // namespace kudu
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/867fc91c/src/kudu/client/client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index c4f41b2..a78fadc 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -5231,5 +5231,26 @@ TEST_F(ClientTest, TestInvalidPartitionerBuilder) {
   ASSERT_EQ("Invalid argument: null table", s.ToString());
 }
 
+// Test that, log verbose level can be set through environment varialble
+// and it reflects to the FLAGS_v.
+TEST_F(ClientTest, TestVerboseLevelByEnvVar) {
+  FLAGS_v = 0;
+  setenv(kVerboseEnvVar, "5", 1); // 1 = overwrite if variable already exists.
+  SetVerboseLevelFromEnvVar();
+  ASSERT_EQ(5, FLAGS_v);
+
+  // negative values are to be ignored.
+  FLAGS_v = 0;
+  setenv(kVerboseEnvVar, "-1", 1);
+  SetVerboseLevelFromEnvVar();
+  ASSERT_EQ(0, FLAGS_v);
+
+  // non-parsable values are to be ignored.
+  FLAGS_v = 0;
+  setenv(kVerboseEnvVar, "abc", 1);
+  SetVerboseLevelFromEnvVar();
+  ASSERT_EQ(0, FLAGS_v);
+}
+
 } // namespace client
 } // namespace kudu

http://git-wip-us.apache.org/repos/asf/kudu/blob/867fc91c/src/kudu/client/client.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client.cc b/src/kudu/client/client.cc
index e3e06dd..87d4e55 100644
--- a/src/kudu/client/client.cc
+++ b/src/kudu/client/client.cc
@@ -18,6 +18,7 @@
 #include "kudu/client/client.h"
 
 #include <algorithm>
+#include <cstdlib>
 #include <memory>
 #include <set>
 #include <string>
@@ -55,6 +56,7 @@
 #include "kudu/common/wire_protocol.h"
 #include "kudu/gutil/map-util.h"
 #include "kudu/gutil/stl_util.h"
+#include "kudu/gutil/strings/numbers.h"
 #include "kudu/gutil/strings/substitute.h"
 #include "kudu/master/master.pb.h"
 #include "kudu/master/master.proxy.h"
@@ -126,6 +128,7 @@ using internal::MetaCache;
 using sp::shared_ptr;
 
 static const char* kProgName = "kudu_client";
+const char* kVerboseEnvVar = "KUDU_CLIENT_VERBOSE";
 
 // We need to reroute all logging to stderr when the client library is
 // loaded. GoogleOnceInit() can do that, but there are multiple entry
@@ -138,6 +141,21 @@ static const char* kProgName = "kudu_client";
 __attribute__((constructor))
 static void InitializeBasicLogging() {
   InitGoogleLoggingSafeBasic(kProgName);
+
+  SetVerboseLevelFromEnvVar();
+}
+
+// Set Client logging verbose level from environment variable.
+void SetVerboseLevelFromEnvVar() {
+  int32_t level = 0; // this is the default logging level;
+  const char* env_verbose_level = std::getenv(kVerboseEnvVar);
+  if (env_verbose_level != nullptr) {
+     if (safe_strto32(env_verbose_level, &level) && (level >= 0)) {
+       SetVerboseLogLevel(level);
+     } else {
+       LOG(WARNING) << "Invalid verbose level from environment variable " <<
kVerboseEnvVar;
+     }
+  }
 }
 
 // Adapts between the internal LogSeverity and the client's KuduLogSeverity.


Mime
View raw message