ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-15801 HDFS script alerts moved to UNKNOWN status with "Unable to calculate the standard deviation for 1 datapoints" (dsen)
Date Mon, 11 Apr 2016 17:36:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 20f9f8320 -> c704377fe


AMBARI-15801 HDFS script alerts moved to UNKNOWN status with "Unable to calculate the standard
deviation for 1 datapoints" (dsen)


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

Branch: refs/heads/branch-2.2
Commit: c704377fed10da5636a2ac445cf862ba94c3753a
Parents: 20f9f83
Author: Dmytro Sen <dsen@apache.org>
Authored: Mon Apr 11 20:33:45 2016 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Mon Apr 11 20:35:23 2016 +0300

----------------------------------------------------------------------
 .../package/alerts/alert_metrics_deviation.py   |   4 +-
 .../2.0.6/HDFS/test_alert_metrics_deviation.py  | 139 +++++++++++++++++++
 2 files changed, 141 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c704377f/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
index 9a122fa..8894a5a 100644
--- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
+++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
@@ -310,7 +310,7 @@ def execute(configurations={}, parameters={}, host_name=None):
   pass
 
   if not metrics or len(metrics) < 2:
-    return (RESULT_STATE_UNKNOWN, ["Unable to calculate the standard deviation for {0} datapoints".format(len(metrics))])
+    return (RESULT_STATE_SKIPPED, ["Unable to calculate the standard deviation for {0} datapoints".format(len(metrics))])
 
   if minimum_value_threshold:
     # Filter out points below min threshold
@@ -326,7 +326,7 @@ def execute(configurations={}, parameters={}, host_name=None):
     deviation_percent = stddev / mean * 100
   except ZeroDivisionError:
     # should not be a case for this alert
-    return (RESULT_STATE_UNKNOWN, ["Unable to calculate the standard deviation percentage.
The mean value is 0"])
+    return (RESULT_STATE_SKIPPED, ["Unable to calculate the standard deviation percentage.
The mean value is 0"])
 
   logger.debug("""
   AMS request parameters - {0}

http://git-wip-us.apache.org/repos/asf/ambari/blob/c704377f/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_alert_metrics_deviation.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_alert_metrics_deviation.py
b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_alert_metrics_deviation.py
new file mode 100644
index 0000000..8a35ab5
--- /dev/null
+++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_alert_metrics_deviation.py
@@ -0,0 +1,139 @@
+#!/usr/bin/env python
+
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+'''
+
+# System imports
+import os
+import sys
+
+from mock.mock import patch, MagicMock
+
+# Local imports
+from stacks.utils.RMFTestCase import *
+
+COMMON_SERVICES_ALERTS_DIR = "HDFS/2.1.0.2.0/package/alerts"
+
+file_path = os.path.dirname(os.path.abspath(__file__))
+file_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(file_path)))))
+file_path = os.path.join(file_path, "main", "resources", "common-services", COMMON_SERVICES_ALERTS_DIR)
+
+RESULT_STATE_OK = "OK"
+RESULT_STATE_WARNING = "WARNING"
+RESULT_STATE_CRITICAL = "CRITICAL"
+RESULT_STATE_UNKNOWN = "UNKNOWN"
+RESULT_STATE_SKIPPED = "SKIPPED"
+
+class TestAlertMetricsDeviation(RMFTestCase):
+
+  def setUp(self):
+    """
+    Import the class under test.
+    Because the class is present in a different folder, append its dir to the system path.
+    Also, shorten the import name and make it a global so the test functions can access it.
+    :return:
+    """
+    sys.path.append(file_path)
+    global alert
+    import alert_metrics_deviation as alert
+    global configs
+    configs = {
+      '{{hdfs-site/dfs.namenode.https-address}}': 'c6401.ambari.apache.org:50470',
+      '{{hdfs-site/dfs.http.policy}}': 'HTTP_ONLY',
+      '{{ams-site/timeline.metrics.service.webapp.address}}': 'c6401.ambari.apache.org:6188',
+      '{{hdfs-site/dfs.namenode.http-address}}': 'c6401.ambari.apache.org:50070',
+      '{{cluster-env/security_enabled}}': 'false',
+      '{{cluster-env/smokeuser}}': 'ambari-qa',
+      '{{hdfs-site}}': {
+        'dfs.datanode.address': '0.0.0.0:50010',
+        'dfs.namenode.rpc-address': 'c6401.ambari.apache.org:8020',
+        'dfs.namenode.https-address': 'c6401.ambari.apache.org:50470',
+        'dfs.namenode.http-address': 'c6401.ambari.apache.org:50070',
+        'dfs.datanode.https.address': '0.0.0.0:50475',
+        'dfs.namenode.secondary.http-address': 'c6401.ambari.apache.org:50090',
+        'dfs.datanode.http.address': '0.0.0.0:50075',
+        'dfs.http.policy': 'HTTP_ONLY',
+        'dfs.journalnode.https-address': '0.0.0.0:8481',
+        'dfs.journalnode.http-address': '0.0.0.0:8480'
+      }
+    }
+    global parameters
+    parameters = {
+      'metric.deviation.warning.threshold': 100.0,
+      'mergeHaMetrics': 'false',
+      'interval': 60.0,
+      'metric.deviation.critical.threshold': 200.0,
+      'appId': 'NAMENODE',
+      'minimumValue': 30.0,
+      'kerberos.kinit.timer': 14400000L,
+      'metricName': 'metric1'
+    }
+  
+  def test_missing_configs(self):
+    """
+    Check that the status is UNKNOWN when configs are missing.
+    """
+    configs = {}
+    [status, messages] = alert.execute(configurations=configs)
+    self.assertEqual(status, RESULT_STATE_UNKNOWN)
+    self.assertTrue(messages is not None and len(messages) == 1)
+    self.assertTrue('is a required parameter for the script' in messages[0])
+
+  @patch("httplib.HTTPConnection")
+  def test_alert(self, conn_mock):
+    ca_connection = MagicMock()
+    response = MagicMock()
+    response.status = 200
+    ca_connection.getresponse.return_value = response
+    conn_mock.return_value = ca_connection
+    response.read.return_value = '{"metrics":[{"metricname":"metric1","metrics":{"1459966360838":1,"1459966370838":3}}]}'
+
+    # OK, but no datapoints above the minimum threshold
+    [status, messages] = alert.execute(configurations=configs, parameters=parameters)
+    self.assertEqual(status, RESULT_STATE_OK)
+    self.assertTrue(messages is not None and len(messages) == 1)
+    self.assertEquals('No datapoints found above the minimum threshold of 30 seconds',messages[0])
+
+    # Unable to calculate the standard deviation for 1 data point
+    response.read.return_value = '{"metrics":[{"metricname":"metric1","metrics":{"1459966360838":40000}}]}'
+    [status, messages] = alert.execute(configurations=configs, parameters=parameters)
+    self.assertEqual(status, RESULT_STATE_SKIPPED)
+    self.assertTrue(messages is not None and len(messages) == 1)
+    self.assertEquals('Unable to calculate the standard deviation for 1 datapoints', messages[0])
+
+    # OK
+    response.read.return_value = '{"metrics":[{"metricname":"metric1","metrics":{"1459966360838":40000,"1459966370838":50000}}]}'
+    [status, messages] = alert.execute(configurations=configs, parameters=parameters)
+    self.assertEqual(status, RESULT_STATE_OK)
+    self.assertTrue(messages is not None and len(messages) == 1)
+    self.assertTrue('OK. Percentage standard deviation value is' in messages[0])
+
+    # Warning
+    response.read.return_value = '{"metrics":[{"metricname":"metric1","metrics":{"1459966360838":40000,"1459966370838":1000000}}]}'
+    [status, messages] = alert.execute(configurations=configs, parameters=parameters)
+    self.assertEqual(status, RESULT_STATE_WARNING)
+    self.assertTrue(messages is not None and len(messages) == 1)
+    self.assertTrue('WARNING. Percentage standard deviation' in messages[0])
+
+    # HTTP request to AMS failed
+    response.read.return_value = ''
+    response.status = 501
+    [status, messages] = alert.execute(configurations=configs, parameters=parameters)
+    self.assertEqual(status, RESULT_STATE_UNKNOWN)
+    self.assertTrue(messages is not None and len(messages) == 1)
+    self.assertEquals('Unable to retrieve metrics from AMS.', messages[0])


Mime
View raw message