You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/05/05 09:28:21 UTC

[GitHub] [flink-kubernetes-operator] morhidi commented on a diff in pull request #194: [FLINK-26953] Introduce Operator Specific Metrics

morhidi commented on code in PR #194:
URL: https://github.com/apache/flink-kubernetes-operator/pull/194#discussion_r865718858


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetrics.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.kubernetes.operator.crd.FlinkDeployment;
+import org.apache.flink.kubernetes.operator.crd.status.JobManagerDeploymentStatus;
+import org.apache.flink.metrics.MetricGroup;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/** FlinkDeployment metrics. */
+public class FlinkDeploymentMetrics {
+
+    private final Map<JobManagerDeploymentStatus, Set<String>> statuses = new HashMap<>();
+    public static final String NS_SCOPE_KEY = "ns";
+    public static final String METRIC_GROUP_NAME = "FlinkDeployment";
+
+    public FlinkDeploymentMetrics(MetricGroup parentMetricGroup) {
+        MetricGroup flinkDeploymentMetrics = parentMetricGroup.addGroup(METRIC_GROUP_NAME);
+        for (JobManagerDeploymentStatus status : JobManagerDeploymentStatus.values()) {
+            statuses.put(status, ConcurrentHashMap.newKeySet());
+        }
+        for (JobManagerDeploymentStatus status : JobManagerDeploymentStatus.values()) {
+            statuses.put(status, new HashSet<>());
+            MetricGroup metricGroup = flinkDeploymentMetrics.addGroup(status.toString());
+            metricGroup.gauge("Count", () -> statuses.get(status).size());
+        }
+        flinkDeploymentMetrics.gauge(
+                "Count", () -> statuses.values().stream().mapToInt(Set::size).sum());
+    }
+
+    public void update(FlinkDeployment flinkApp) {
+        remove(flinkApp);
+        statuses.get(flinkApp.getStatus().getJobManagerDeploymentStatus())
+                .add(flinkApp.getMetadata().getName());
+    }
+
+    public void remove(FlinkDeployment flinkApp) {
+        statuses.values()
+                .forEach(
+                        deployments -> {
+                            deployments.remove(flinkApp.getMetadata().getName());
+                        });
+    }
+
+    public boolean isEmpty() {
+        return statuses.values().stream().mapToInt(Set::size).sum() == 0;

Review Comment:
   That's a leftover, will clean it up.



-- 
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: issues-unsubscribe@flink.apache.org

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