shaofengshi commented on a change in pull request #1152: KYLIN-4413: add canary 
tool
URL: https://github.com/apache/kylin/pull/1152#discussion_r390772293
 
 

 ##########
 File path: tool/src/main/java/org/apache/kylin/tool/KylinCanary.java
 ##########
 @@ -0,0 +1,215 @@
+/*
+ * 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.tool;
+
+
+import org.apache.commons.cli.Options;
+import org.apache.commons.configuration.SubsetConfiguration;
+import org.apache.hadoop.metrics2.MetricsRecord;
+import org.apache.hadoop.metrics2.MetricsSink;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.annotation.Metric;
+import org.apache.hadoop.metrics2.annotation.Metrics;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.util.EntityUtils;
+import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.AbstractApplication;
+import org.apache.kylin.common.util.OptionsHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class KylinCanary extends AbstractApplication {
+    private static final Logger logger = 
LoggerFactory.getLogger(KylinCanary.class);
+
+    private static final int HTTP_CONNECTION_TIMEOUT = 3000;
+    private static final int HTTP_READ_TIMEOUT = 30000;
+
+    private MetricsSink sink;
+    private KylinConfig config;
+    private long interval;
+    private String token;
+    private CanaryMetrics canaryMetrics;
+    private MetricsSystem metricsSystem;
+
+    @Metrics(name = "canary", about = "Canary metrics", context = "kylin")
+    public static class CanaryMetrics {
+        @Metric
+        MutableGaugeLong queryAvailability;
+
+        public CanaryMetrics() {
+        }
+
+        public void setQueryAvailability(long value) {
+            queryAvailability.set(value);
+        }
+    }
+
+    public KylinCanary() {
+        config = KylinConfig.getInstanceFromEnv();
+        token = config.getCanaryToken();
+
+        if (config.isCanaryDaemon()) {
+            interval = config.getCanaryInterval();
+        } else {
+            interval = -1;
+        }
+
+        canaryMetrics = new CanaryMetrics();
+        String sinkClassName = config.getCanarySinkClass();
+        try {
+            sink = (MetricsSink) 
Class.forName(sinkClassName).getConstructor().newInstance();
+        } catch (Exception e) {
+            logger.warn("new class: " + sinkClassName + " error.", e);
+            sink = new StdOutSink();
+        }
+        sink.init(null);
+
+        metricsSystem = DefaultMetricsSystem.instance();
+
+        metricsSystem.init("kylin-canary");
+        metricsSystem.register("kylin-canary", "Kylin Canary", canaryMetrics);
+        metricsSystem.register("falcon", "Falcon sink for xiaomi", sink);
 
 Review comment:
   Change a general name?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to