ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-10099 - Web Alerts Create Confusing Errors And Warnings (jonathanhurley)
Date Tue, 17 Mar 2015 13:23:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.0 ac882c67f -> 15020c0c2


AMBARI-10099 - Web Alerts Create Confusing Errors And Warnings (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/15020c0c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/15020c0c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/15020c0c

Branch: refs/heads/branch-2.0.0
Commit: 15020c0c2fca7cc4e85023bd280b828a979325ce
Parents: ac882c6
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Mar 16 22:42:28 2015 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Mar 17 09:23:20 2015 -0400

----------------------------------------------------------------------
 .../python/ambari_agent/alerts/web_alert.py     | 31 +++++++++++++++-----
 .../src/test/python/ambari_agent/TestAlerts.py  |  8 ++---
 .../FALCON/0.5.0.2.1/alerts.json                |  4 +--
 .../common-services/HDFS/2.1.0.2.0/alerts.json  |  8 ++---
 .../common-services/OOZIE/4.0.0.2.0/alerts.json |  4 +--
 .../common-services/STORM/0.9.1.2.1/alerts.json |  4 +--
 .../common-services/YARN/2.1.0.2.0/alerts.json  | 16 +++++-----
 .../stacks/BIGTOP/0.8/services/HDFS/alerts.json |  8 ++---
 .../BIGTOP/0.8/services/OOZIE/alerts.json       |  4 +--
 .../stacks/BIGTOP/0.8/services/YARN/alerts.json | 16 +++++-----
 10 files changed, 58 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
index 2db4996..1a6540a 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/web_alert.py
@@ -23,6 +23,7 @@ import time
 import subprocess
 import os
 import urllib2
+from urllib2 import HTTPError
 import uuid
 
 from  tempfile import gettempdir
@@ -89,10 +90,12 @@ class WebAlert(BaseAlert):
     if status_code == 0:
       return (self.RESULT_CRITICAL, [status_code, url, time_seconds, error_message])
 
+    # anything that's less than 400 is OK
     if status_code < 400:
       return (self.RESULT_OK, [status_code, url, time_seconds])
 
-    return (self.RESULT_WARNING, [status_code, url, time_seconds])
+    # everything else is WARNING
+    return (self.RESULT_WARNING, [status_code, url, time_seconds, error_message])
 
 
   def _build_web_query(self, alert_uri):
@@ -140,6 +143,7 @@ class WebAlert(BaseAlert):
     """    
 
     try:
+      response_code = 0
       kerberos_keytab = None
       kerberos_principal = None
 
@@ -199,22 +203,26 @@ class WebAlert(BaseAlert):
             '%{http_code}', url, '--connect-timeout', CURL_CONNECTION_TIMEOUT,
             '-o', '/dev/null'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=kerberos_env)
 
-          out, err = curl.communicate()
+          curl_stdout, curl_stderr = curl.communicate()
         finally:
           if os.path.isfile(cookie_file):
             os.remove(cookie_file)
 
-        if err != '':
-          raise Exception(err)
+        # empty quotes evaluates to false
+        if curl_stderr:
+          raise Exception(curl_stderr)
+
+        # empty quotes evaluates to false
+        if curl_stdout:
+          response_code = int(curl_stdout)
 
-        response_code = int(out)
         time_millis = time.time() - start_time
       else:
         # kerberos is not involved; use urllib2
-        response_code, time_millis = self._make_web_request_urllib(url)
+        response_code, time_millis, error_msg = self._make_web_request_urllib(url)
 
       return WebResponse(status_code=response_code, time_millis=time_millis,
-        error_msg=None)
+        error_msg=error_msg)
 
     except Exception, exception:
       if logger.isEnabledFor(logging.DEBUG):
@@ -230,6 +238,8 @@ class WebAlert(BaseAlert):
     :return: a tuple of the response code and the total time in ms
     """
     response = None
+    error_message = None
+
     start_time = time.time()
 
     try:
@@ -237,7 +247,12 @@ class WebAlert(BaseAlert):
       response_code = response.getcode()
       time_millis = time.time() - start_time
 
-      return response_code, time_millis
+      return response_code, time_millis, error_message
+    except HTTPError, httpError:
+      time_millis = time.time() - start_time
+      error_message = str(httpError)
+
+      return httpError.code, time_millis, error_message
     finally:
       if response is not None:
         try:

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
index 3133c57..a574422 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestAlerts.py
@@ -380,9 +380,7 @@ class TestAlerts(TestCase):
     self.assertEquals('OK', alerts[0]['state'])
 
     # run the alert and check HTTP 500
-
-
-    wa_make_web_request_mock.return_value = WebResponse(500,1.234,None)
+    wa_make_web_request_mock.return_value = WebResponse(500,1.234,"Internal Server Error")
     collector = AlertCollector()
     alert = WebAlert(definition_json, definition_json['source'], None)
     alert.set_helpers(collector, cluster_configuration)
@@ -393,7 +391,7 @@ class TestAlerts(TestCase):
     self.assertEquals(0, len(collector.alerts()))
     
     self.assertEquals('WARNING', alerts[0]['state'])
-    self.assertEquals('(Unit Tests) warning: 500', alerts[0]['text'])
+    self.assertEquals('(Unit Tests) warning: 500 (Internal Server Error)', alerts[0]['text'])
 
     # run the alert and check critical
     wa_make_web_request_mock.return_value = WebResponse(0,0,'error message')
@@ -1067,7 +1065,7 @@ class TestAlerts(TestCase):
             "text": "(Unit Tests) ok: {0}",
           },
           "warning": {
-            "text": "(Unit Tests) warning: {0}",
+            "text": "(Unit Tests) warning: {0} ({3})",
           },
           "critical": {
             "text": "(Unit Tests) critical: {1}. {3}",

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/common-services/FALCON/0.5.0.2.1/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/FALCON/0.5.0.2.1/alerts.json
b/ambari-server/src/main/resources/common-services/FALCON/0.5.0.2.1/alerts.json
index e028ed5..cd1bd73 100644
--- a/ambari-server/src/main/resources/common-services/FALCON/0.5.0.2.1/alerts.json
+++ b/ambari-server/src/main/resources/common-services/FALCON/0.5.0.2.1/alerts.json
@@ -44,10 +44,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json
index d5dccbf..3f0a926 100644
--- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json
+++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json
@@ -103,10 +103,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -506,10 +506,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json
b/ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json
index 01d9148..975fea0 100644
--- a/ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json
+++ b/ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json
@@ -17,10 +17,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/alerts.json
b/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/alerts.json
index 002fd07..6557df9 100644
--- a/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/alerts.json
+++ b/ambari-server/src/main/resources/common-services/STORM/0.9.1.2.1/alerts.json
@@ -67,10 +67,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/alerts.json b/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/alerts.json
index fe1ae8a..a446808 100644
--- a/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/alerts.json
+++ b/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/alerts.json
@@ -20,10 +20,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -183,10 +183,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -231,10 +231,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -360,10 +360,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/HDFS/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/HDFS/alerts.json
b/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/HDFS/alerts.json
index ac5ab37..8e08ef2 100644
--- a/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/HDFS/alerts.json
+++ b/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/HDFS/alerts.json
@@ -103,10 +103,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -506,10 +506,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/OOZIE/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/OOZIE/alerts.json
b/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/OOZIE/alerts.json
index 17c2b23..f13bb63 100644
--- a/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/OOZIE/alerts.json
+++ b/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/OOZIE/alerts.json
@@ -15,10 +15,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1}"

http://git-wip-us.apache.org/repos/asf/ambari/blob/15020c0c/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/YARN/alerts.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/YARN/alerts.json
b/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/YARN/alerts.json
index aeabc93..94f0926 100644
--- a/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/YARN/alerts.json
+++ b/ambari-server/src/main/resources/stacks/BIGTOP/0.8/services/YARN/alerts.json
@@ -20,10 +20,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -183,10 +183,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -231,10 +231,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"
@@ -348,10 +348,10 @@
           },
           "reporting": {
             "ok": {
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response in {2:.3f}s"
             },
             "warning":{
-              "text": "HTTP {0} response in {2:.3f} seconds"
+              "text": "HTTP {0} response from {1} in {2:.3f}s ({3})"
             },
             "critical": {
               "text": "Connection failed to {1} ({3})"


Mime
View raw message