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-12881 Ambari metrics shows data sparsely. (dsen)
Date Thu, 27 Aug 2015 10:23:40 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 34b4f9e26 -> a54812b44


AMBARI-12881 Ambari metrics shows data sparsely. (dsen)


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

Branch: refs/heads/trunk
Commit: a54812b44bc38ae9e96f9d7fa654abcfb8aefb34
Parents: 34b4f9e
Author: Dmytro Sen <dsen@apache.org>
Authored: Thu Aug 27 13:23:31 2015 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Thu Aug 27 13:23:31 2015 +0300

----------------------------------------------------------------------
 .../timeline/query/PhoenixTransactSQL.java      |   4 +-
 .../timeline/TestPhoenixTransactSQL.java        | 137 ++++++++++++++++++-
 2 files changed, 137 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a54812b4/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
index 1aa6204..ef0f4ce 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/PhoenixTransactSQL.java
@@ -284,7 +284,7 @@ public class PhoenixTransactSQL {
           metricsTable = METRICS_AGGREGATE_DAILY_TABLE_NAME;
           query = GET_METRIC_AGGREGATE_ONLY_SQL;
           condition.setPrecision(Precision.DAYS);
-        } else if (timeRange < 7 * DAY && timeRange > DAY) {
+        } else if (timeRange > DAY) {
           metricsTable = METRICS_AGGREGATE_HOURLY_TABLE_NAME;
           query = GET_METRIC_AGGREGATE_ONLY_SQL;
           condition.setPrecision(Precision.HOURS);
@@ -534,7 +534,7 @@ public class PhoenixTransactSQL {
         metricsAggregateTable = METRICS_CLUSTER_AGGREGATE_DAILY_TABLE_NAME;
         queryStmt = GET_CLUSTER_AGGREGATE_TIME_SQL;
         condition.setPrecision(Precision.DAYS);
-      } else if (timeRange < 7 * DAY && timeRange > DAY) {
+      } else if (timeRange > DAY) {
         metricsAggregateTable = METRICS_CLUSTER_AGGREGATE_HOURLY_TABLE_NAME;
         queryStmt = GET_CLUSTER_AGGREGATE_TIME_SQL;
         condition.setPrecision(Precision.HOURS);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a54812b4/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
index cf64e4e..8693a21 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
@@ -33,6 +33,7 @@ import java.util.Collections;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
 import static org.easymock.EasyMock.verify;
 import org.easymock.EasyMock;
 
@@ -152,9 +153,12 @@ public class TestPhoenixTransactSQL {
 
   @Test
   public void testPrepareGetAggregateNoPrecision() throws SQLException {
+    Long endTime = 1407959918L;
+    Long startTime = 1407959718L;
+    //SECONDS precision
     Condition condition = new DefaultCondition(
       Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
-      "a1", "i1", 1407959718L, 1407959918L, null, null, false);
+      "a1", "i1", startTime, endTime, null, null, false);
     Connection connection = createNiceMock(Connection.class);
     PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
     Capture<String> stmtCapture = new Capture<String>();
@@ -165,6 +169,61 @@ public class TestPhoenixTransactSQL {
     PhoenixTransactSQL.prepareGetAggregateSqlStmt(connection, condition);
     String stmt = stmtCapture.getValue();
     Assert.assertTrue(stmt.contains("FROM METRIC_AGGREGATE"));
+    Assert.assertEquals(Precision.SECONDS, condition.getPrecision());
+    verify(connection, preparedStatement);
+
+    // SECONDS precision
+    startTime = endTime-PhoenixTransactSQL.DAY/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+        .andReturn(preparedStatement);
+
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetAggregateSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_AGGREGATE"));
+    Assert.assertEquals(Precision.SECONDS, condition.getPrecision());
+    verify(connection, preparedStatement);
+
+    // HOURS precision
+    startTime = endTime-PhoenixTransactSQL.DAY*7/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+        .andReturn(preparedStatement);
+
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetAggregateSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_AGGREGATE_HOURLY"));
+    Assert.assertEquals(Precision.HOURS, condition.getPrecision());
+    verify(connection, preparedStatement);
+
+    // DAYS precision
+    startTime = endTime-PhoenixTransactSQL.DAY*7*2/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+        .andReturn(preparedStatement);
+
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetAggregateSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_AGGREGATE_DAILY"));
+    Assert.assertEquals(Precision.DAYS, condition.getPrecision());
     verify(connection, preparedStatement);
   }
 
@@ -206,9 +265,12 @@ public class TestPhoenixTransactSQL {
 
   @Test
   public void testPrepareGetMetricsNoPrecision() throws SQLException {
+    Long endTime = 1407959918L;
+    Long startTime = endTime - 200;
+    // SECONDS precision
     Condition condition = new DefaultCondition(
       Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
-      "a1", "i1", 1407959718L, 1407959918L, null, null, false);
+      "a1", "i1", startTime, endTime, null, null, false);
     Connection connection = createNiceMock(Connection.class);
     PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
     Capture<String> stmtCapture = new Capture<String>();
@@ -219,7 +281,78 @@ public class TestPhoenixTransactSQL {
     PhoenixTransactSQL.prepareGetMetricsSqlStmt(connection, condition);
     String stmt = stmtCapture.getValue();
     Assert.assertTrue(stmt.contains("FROM METRIC_RECORD"));
+    Assert.assertEquals(Precision.SECONDS, condition.getPrecision());
     verify(connection, preparedStatement);
+    reset(connection, preparedStatement);
+
+    // SECONDS precision
+    startTime = endTime-PhoenixTransactSQL.HOUR*10/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+      .andReturn(preparedStatement);
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetMetricsSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_RECORD"));
+    Assert.assertEquals(Precision.SECONDS, condition.getPrecision());
+    verify(connection, preparedStatement);
+
+    // MINUTES precision
+    startTime = endTime-PhoenixTransactSQL.DAY/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+      .andReturn(preparedStatement);
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetMetricsSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_RECORD_MINUTE"));
+    Assert.assertEquals(Precision.MINUTES, condition.getPrecision());
+    verify(connection, preparedStatement);
+
+    // HOURS precision
+    startTime = endTime-PhoenixTransactSQL.DAY*7/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+      .andReturn(preparedStatement);
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetMetricsSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_RECORD_HOURLY"));
+    Assert.assertEquals(Precision.HOURS, condition.getPrecision());
+    verify(connection, preparedStatement);
+
+    // DAYS precision
+    startTime = endTime-PhoenixTransactSQL.DAY*7*2/1000;
+    condition = new DefaultCondition(
+      Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+      "a1", "i1", startTime, endTime, null, null, false);
+    connection = createNiceMock(Connection.class);
+    preparedStatement = createNiceMock(PreparedStatement.class);
+    stmtCapture = new Capture<String>();
+    expect(connection.prepareStatement(EasyMock.and(EasyMock.anyString(), EasyMock.capture(stmtCapture))))
+      .andReturn(preparedStatement);
+    replay(connection, preparedStatement);
+    PhoenixTransactSQL.prepareGetMetricsSqlStmt(connection, condition);
+    stmt = stmtCapture.getValue();
+    Assert.assertTrue(stmt.contains("FROM METRIC_RECORD_DAILY"));
+    Assert.assertEquals(Precision.DAYS, condition.getPrecision());
+    verify(connection, preparedStatement);
+
   }
 
   @Test


Mime
View raw message