You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by xx...@apache.org on 2020/06/15 14:40:58 UTC
[kylin] branch master updated: KYLIN-4571 Add config
kylin.metrics.event-time-zone for indicating RecordEventTimeDetail time
zone
This is an automated email from the ASF dual-hosted git repository.
xxyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push:
new 53aeb70 KYLIN-4571 Add config kylin.metrics.event-time-zone for indicating RecordEventTimeDetail time zone
53aeb70 is described below
commit 53aeb7044e0a7c157458476e344c50d6413657c7
Author: Zhong, Yanghong <nj...@apache.org>
AuthorDate: Mon Jun 15 16:01:08 2020 +0800
KYLIN-4571 Add config kylin.metrics.event-time-zone for indicating RecordEventTimeDetail time zone
---
.../org/apache/kylin/common/KylinConfigBase.java | 4 ++
.../metrics/lib/impl/RecordEventTimeDetail.java | 8 +--
.../lib/impl/RecordEventTimeDetailTest.java | 60 ++++++++++++++++++++++
3 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
index 041f545..a5af5e3 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfigBase.java
@@ -2316,6 +2316,10 @@ public abstract class KylinConfigBase implements Serializable {
return Boolean.parseBoolean(getOptional("kylin.htrace.trace-every-query", FALSE));
}
+ public String getKylinMetricsEventTimeZone() {
+ return getOptional("kylin.metrics.event-time-zone", getTimeZone()).toUpperCase(Locale.ROOT);
+ }
+
public boolean isKylinMetricsMonitorEnabled() {
return Boolean.parseBoolean(getOptional("kylin.metrics.monitor-enabled", FALSE));
}
diff --git a/core-metrics/src/main/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetail.java b/core-metrics/src/main/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetail.java
index 4c549bc..fc4d86d 100644
--- a/core-metrics/src/main/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetail.java
+++ b/core-metrics/src/main/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetail.java
@@ -18,22 +18,22 @@
package org.apache.kylin.metrics.lib.impl;
+import org.apache.kylin.common.KylinConfig;
+
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
-import org.apache.kylin.common.KylinConfig;
-
public class RecordEventTimeDetail {
private static final TimeZone timeZone;
private static final ThreadLocal<SimpleDateFormat> dateFormatThreadLocal = new ThreadLocal<>();
private static final ThreadLocal<SimpleDateFormat> timeFormatThreadLocal = new ThreadLocal<>();
static {
- timeZone = TimeZone.getTimeZone(KylinConfig.getInstanceFromEnv().getTimeZone());
+ timeZone = TimeZone.getTimeZone(KylinConfig.getInstanceFromEnv().getKylinMetricsEventTimeZone());
}
-
+
public final String year_begin_date;
public final String month_begin_date;
public final String date;
diff --git a/core-metrics/src/test/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetailTest.java b/core-metrics/src/test/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetailTest.java
new file mode 100644
index 0000000..a8e286b
--- /dev/null
+++ b/core-metrics/src/test/java/org/apache/kylin/metrics/lib/impl/RecordEventTimeDetailTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package org.apache.kylin.metrics.lib.impl;
+
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.apache.kylin.common.util.StringUtil;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class RecordEventTimeDetailTest extends LocalFileMetadataTestCase {
+
+ private static String eventTimeZone;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ staticCreateTestMetadata();
+ eventTimeZone = System.getProperty("kylin.metrics.event-time-zone");
+ System.setProperty("kylin.metrics.event-time-zone", "GMT");
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ staticCleanupTestMetadata();
+ if (!StringUtil.isEmpty(eventTimeZone)) {
+ System.setProperty("kylin.metrics.event-time-zone", eventTimeZone);
+ }
+ }
+
+ @Test
+ public void testFormatted() {
+ RecordEventTimeDetail timeDetail = new RecordEventTimeDetail(200000000000L);
+
+ Assert.assertEquals("1976-01-01", timeDetail.year_begin_date);
+ Assert.assertEquals("1976-05-01", timeDetail.month_begin_date);
+ Assert.assertEquals("1976-05-02", timeDetail.week_begin_date);
+ Assert.assertEquals("1976-05-03", timeDetail.date);
+ Assert.assertEquals("19:33:20", timeDetail.time);
+ Assert.assertEquals(19, timeDetail.hour);
+ Assert.assertEquals(33, timeDetail.minute);
+ Assert.assertEquals(20, timeDetail.second);
+ }
+}