Repository: ambari
Updated Branches:
  refs/heads/branch-feature-logsearch-ui 6f1035434 -> 320b0e0c6


AMBARI-21746 Log Search UI: set interval between values for service logs 
histogram depending on time range. (ababiichuk)


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

Branch: refs/heads/branch-feature-logsearch-ui
Commit: 320b0e0c62497e46bb6b2a976d18b01636eb622b
Parents: 6f10354
Author: ababiichuk <[email protected]>
Authored: Thu Aug 17 18:34:16 2017 +0300
Committer: ababiichuk <[email protected]>
Committed: Thu Aug 17 18:34:16 2017 +0300

----------------------------------------------------------------------
 ...ce-logs-histogram-query-params.class.spec.ts | 203 +++++++++++++++++++
 ...service-logs-histogram-query-params.class.ts |  45 +++-
 2 files changed, 242 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/320b0e0c/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.spec.ts
----------------------------------------------------------------------
diff --git 
a/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.spec.ts
 
b/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.spec.ts
new file mode 100644
index 0000000..efa2459
--- /dev/null
+++ 
b/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.spec.ts
@@ -0,0 +1,203 @@
+/**
+ * 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.
+ */
+
+import {ServiceLogsHistogramQueryParams} from 
'./service-logs-histogram-query-params.class';
+
+describe('ServiceLogsHistogramQueryParams', () => {
+
+  describe('constructor', () => {
+    const cases = [
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:00:00.100Z'
+        },
+        unit: '+100MILLISECOND',
+        title: 'less than 1s'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:00:01Z'
+        },
+        unit: '+100MILLISECOND',
+        title: '1s'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:00:20Z'
+        },
+        unit: '+500MILLISECOND',
+        title: 'between 1s and 30s'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:00:20Z'
+        },
+        unit: '+500MILLISECOND',
+        title: '30s'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:00:40Z'
+        },
+        unit: '+2SECOND',
+        title: 'between 30s and 1m'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:01:00Z'
+        },
+        unit: '+2SECOND',
+        title: '1m'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:20:00Z'
+        },
+        unit: '+1MINUTE',
+        title: 'between 1m and 30m'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T00:30:00Z'
+        },
+        unit: '+2MINUTE',
+        title: '30m'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T01:00:00Z'
+        },
+        unit: '+2MINUTE',
+        title: 'between 30m and 2h'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T02:00:00Z'
+        },
+        unit: '+5MINUTE',
+        title: '2h'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T04:00:00Z'
+        },
+        unit: '+5MINUTE',
+        title: 'between 2h and 6h'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T06:00:00Z'
+        },
+        unit: '+10MINUTE',
+        title: '6h'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T08:00:00Z'
+        },
+        unit: '+10MINUTE',
+        title: 'between 6h and 10h'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T10:00:00Z'
+        },
+        unit: '+10MINUTE',
+        title: '10h'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-01T22:00:00Z'
+        },
+        unit: '+1HOUR',
+        title: 'between 10h and 1d'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-02T00:00:00Z'
+        },
+        unit: '+1HOUR',
+        title: '1d'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-10T00:00:00Z'
+        },
+        unit: '+8HOUR',
+        title: 'between 1d and 15d'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-01-16T00:00:00Z'
+        },
+        unit: '+1DAY',
+        title: '15d'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-03-31T00:00:00Z'
+        },
+        unit: '+1DAY',
+        title: 'between 15d and 3M'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-04-01T00:00:00Z'
+        },
+        unit: '+1DAY',
+        title: '3M'
+      },
+      {
+        options: {
+          from: '2017-01-01T00:00:00Z',
+          to: '2017-05-01T00:00:00Z'
+        },
+        unit: '+1MONTH',
+        title: 'over 3M'
+      }
+    ];
+
+    cases.forEach(test => {
+      it(test.title, () => {
+        const paramsObject = new ServiceLogsHistogramQueryParams(test.options);
+        expect(paramsObject.unit).toEqual(test.unit);
+      });
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/320b0e0c/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.ts
----------------------------------------------------------------------
diff --git 
a/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.ts
 
b/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.ts
index 21b7116..5402214 100644
--- 
a/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.ts
+++ 
b/ambari-logsearch/ambari-logsearch-web-new/src/app/classes/queries/service-logs-histogram-query-params.class.ts
@@ -18,14 +18,47 @@
 
 import {QueryParams} from '@app/classes/queries/query-params.class';
 
-export const defaultParams = {
-  unit: '+1HOUR'
-};
-
 export class ServiceLogsHistogramQueryParams extends QueryParams {
   constructor(options: ServiceLogsHistogramQueryParams) {
-    const finalParams = Object.assign({}, defaultParams, options);
-    super(finalParams);
+    let unit;
+    const diffTimeStamp = new Date(options.to).valueOf() - new 
Date(options.from).valueOf();
+    switch (true) {
+      case diffTimeStamp <= 1000:
+        unit = '+100MILLISECOND';
+        break;
+      case diffTimeStamp <= 30000:
+        unit = '+500MILLISECOND';
+        break;
+      case diffTimeStamp <= 60000:
+        unit = '+2SECOND';
+        break;
+      case diffTimeStamp < 1800000:
+        unit = '+1MINUTE';
+        break;
+      case diffTimeStamp < 7200000:
+        unit = '+2MINUTE';
+        break;
+      case diffTimeStamp < 21600000:
+        unit = '+5MINUTE';
+        break;
+      case diffTimeStamp <= 36000000:
+        unit = '+10MINUTE';
+        break;
+      case diffTimeStamp <= 86400000:
+        unit = '+1HOUR';
+        break;
+      case diffTimeStamp < 1296000000:
+        unit = '+8HOUR';
+        break;
+      case diffTimeStamp <= 7776000000:
+        unit = '+1DAY';
+        break;
+      default:
+        unit = '+1MONTH';
+        break;
+    }
+    options.unit = unit;
+    super(options);
   }
   from: string;
   to: string;

Reply via email to