You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by GitBox <gi...@apache.org> on 2022/02/17 12:15:04 UTC

[GitHub] [flink-kubernetes-operator] wangyang0918 commented on a change in pull request #6: [FLINK-26183] Support metrics using the Flink metric system

wangyang0918 commented on a change in pull request #6:
URL: https://github.com/apache/flink-kubernetes-operator/pull/6#discussion_r808984951



##########
File path: helm/flink-operator/templates/flink-operator.yaml
##########
@@ -118,6 +124,9 @@ metadata:
   labels:
     {{- include "flink-operator.labels" . | nindent 4 }}
 data:
+  flink-conf.yaml: |+

Review comment:
       I am suggesting to use the `PrometheusReporter` as default. And maybe we also need to add the prometheus related annotations so that it could integrate with the metrics system easily.
   
   https://stackoverflow.com/questions/53365191/monitor-custom-kubernetes-pod-metrics-using-prometheus

##########
File path: flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/metrics/OperatorMetricUtils.java
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.flink.kubernetes.operator.metrics;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.plugin.PluginManager;
+import org.apache.flink.core.plugin.PluginUtils;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.metrics.MetricRegistry;
+import org.apache.flink.runtime.metrics.MetricRegistryConfiguration;
+import org.apache.flink.runtime.metrics.MetricRegistryImpl;
+import org.apache.flink.runtime.metrics.ReporterSetup;
+import org.apache.flink.runtime.metrics.util.MetricUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/** Utility class for flink based operator metrics. */
+public class OperatorMetricUtils {
+
+    private static final Logger LOG = LoggerFactory.getLogger(OperatorMetricUtils.class);
+
+    public static void initOperatorMetrics(Configuration configuration) {
+        PluginManager pluginManager = PluginUtils.createPluginManagerFromRootFolder(configuration);
+        MetricRegistry metricRegistry = createMetricRegistry(configuration, pluginManager);
+        KubernetesOperatorMetricGroup operatorMetricGroup =
+                KubernetesOperatorMetricGroup.create(metricRegistry, getHostname());
+        MetricGroup statusGroup = operatorMetricGroup.addGroup("Status");
+        MetricUtils.instantiateStatusMetrics(statusGroup);
+    }
+
+    private static String getHostname() {
+        String hostname = "localhost";

Review comment:
       Maybe the default value could derive from the `HOSTNAME` environment if defined. It seems that all the K8s pods have such an environment.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org