You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by mb...@apache.org on 2024/05/09 08:53:34 UTC

(flink-kubernetes-operator) branch main updated: [FLINK-35183] MinorVersion metric for tracking applications

This is an automated email from the ASF dual-hosted git repository.

mbalassi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-kubernetes-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 84d9b745 [FLINK-35183] MinorVersion metric for tracking applications
84d9b745 is described below

commit 84d9b7459b01dab434b2ea8a43f9c9163c753273
Author: Márton Balassi <ma...@apple.com>
AuthorDate: Thu May 9 10:53:28 2024 +0200

    [FLINK-35183] MinorVersion metric for tracking applications
---
 .../operator/metrics/FlinkDeploymentMetrics.java   | 43 ++++++++++++++++--
 .../metrics/FlinkDeploymentMetricsTest.java        | 51 ++++++++++++++++------
 2 files changed, 77 insertions(+), 17 deletions(-)

diff --git a/flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetrics.java b/flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetrics.java
index a5871544..310bb75a 100644
--- a/flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetrics.java
+++ b/flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetrics.java
@@ -42,11 +42,17 @@ public class FlinkDeploymentMetrics implements CustomResourceMetrics<FlinkDeploy
     // map(namespace, map(version, set(deployment)))
     private final Map<String, Map<String, Set<String>>> deploymentFlinkVersions =
             new ConcurrentHashMap<>();
+    // map(namespace, map(version, set(deployment)))
+    private final Map<String, Map<String, Set<String>>> deploymentFlinkMinorVersions =
+            new ConcurrentHashMap<>();
     // map(namespace, map(deployment, cpu))
     private final Map<String, Map<String, Double>> deploymentCpuUsage = new ConcurrentHashMap<>();
     // map(namespace, map(deployment, memory))
     private final Map<String, Map<String, Long>> deploymentMemoryUsage = new ConcurrentHashMap<>();
     public static final String FLINK_VERSION_GROUP_NAME = "FlinkVersion";
+    public static final String FLINK_MINOR_VERSION_GROUP_NAME = "FlinkMinorVersion";
+    public static final String UNKNOWN_VERSION = "UNKNOWN";
+    public static final String MALFORMED_MINOR_VERSION = "MALFORMED";
     public static final String STATUS_GROUP_NAME = "JmDeploymentStatus";
     public static final String RESOURCE_USAGE_GROUP_NAME = "ResourceUsage";
     public static final String COUNTER_NAME = "Count";
@@ -77,12 +83,13 @@ public class FlinkDeploymentMetrics implements CustomResourceMetrics<FlinkDeploy
                 .get(flinkApp.getStatus().getJobManagerDeploymentStatus())
                 .add(deploymentName);
 
+        // Full runtime version queried from the JobManager REST API
         var flinkVersion =
                 flinkApp.getStatus()
                         .getClusterInfo()
                         .getOrDefault(DashboardConfiguration.FIELD_NAME_FLINK_VERSION, "");
         if (StringUtils.isNullOrWhitespaceOnly(flinkVersion)) {
-            flinkVersion = "UNKNOWN";
+            flinkVersion = UNKNOWN_VERSION;
         }
         deploymentFlinkVersions
                 .computeIfAbsent(namespace, ns -> new ConcurrentHashMap<>())
@@ -94,6 +101,22 @@ public class FlinkDeploymentMetrics implements CustomResourceMetrics<FlinkDeploy
                         })
                 .add(deploymentName);
 
+        // Minor version computed from the above
+        var subVersions = flinkVersion.split("\\.");
+        String minorVersion = MALFORMED_MINOR_VERSION;
+        if (subVersions.length >= 2) {
+            minorVersion = subVersions[0].concat(".").concat(subVersions[1]);
+        }
+        deploymentFlinkMinorVersions
+                .computeIfAbsent(namespace, ns -> new ConcurrentHashMap<>())
+                .computeIfAbsent(
+                        minorVersion,
+                        v -> {
+                            initFlinkMinorVersions(namespace, v);
+                            return ConcurrentHashMap.newKeySet();
+                        })
+                .add(deploymentName);
+
         var totalCpu =
                 NumberUtils.toDouble(
                         clusterInfo.getOrDefault(AbstractFlinkService.FIELD_NAME_TOTAL_CPU, "0"));
@@ -133,6 +156,12 @@ public class FlinkDeploymentMetrics implements CustomResourceMetrics<FlinkDeploy
         if (deploymentFlinkVersions.containsKey(namespace)) {
             deploymentFlinkVersions.get(namespace).values().forEach(names -> names.remove(name));
         }
+        if (deploymentFlinkMinorVersions.containsKey(namespace)) {
+            deploymentFlinkMinorVersions
+                    .get(namespace)
+                    .values()
+                    .forEach(names -> names.remove(name));
+        }
         if (deploymentCpuUsage.containsKey(namespace)) {
             deploymentCpuUsage.get(namespace).remove(name);
         }
@@ -165,13 +194,21 @@ public class FlinkDeploymentMetrics implements CustomResourceMetrics<FlinkDeploy
     private void initFlinkVersions(String ns, String flinkVersion) {
         parentMetricGroup
                 .createResourceNamespaceGroup(configuration, FlinkDeployment.class, ns)
-                .addGroup(FLINK_VERSION_GROUP_NAME)
-                .addGroup(flinkVersion)
+                .addGroup(FLINK_VERSION_GROUP_NAME, flinkVersion)
                 .gauge(
                         COUNTER_NAME,
                         () -> deploymentFlinkVersions.get(ns).get(flinkVersion).size());
     }
 
+    private void initFlinkMinorVersions(String ns, String minorVersion) {
+        parentMetricGroup
+                .createResourceNamespaceGroup(configuration, FlinkDeployment.class, ns)
+                .addGroup(FLINK_MINOR_VERSION_GROUP_NAME, minorVersion)
+                .gauge(
+                        COUNTER_NAME,
+                        () -> deploymentFlinkMinorVersions.get(ns).get(minorVersion).size());
+    }
+
     private void initNamespaceCpuUsage(String ns) {
         parentMetricGroup
                 .createResourceNamespaceGroup(configuration, FlinkDeployment.class, ns)
diff --git a/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetricsTest.java b/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetricsTest.java
index 73dd58a2..1776cad2 100644
--- a/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetricsTest.java
+++ b/flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/metrics/FlinkDeploymentMetricsTest.java
@@ -34,6 +34,7 @@ import java.util.Map;
 
 import static org.apache.flink.kubernetes.operator.metrics.FlinkDeploymentMetrics.COUNTER_NAME;
 import static org.apache.flink.kubernetes.operator.metrics.FlinkDeploymentMetrics.CPU_NAME;
+import static org.apache.flink.kubernetes.operator.metrics.FlinkDeploymentMetrics.FLINK_MINOR_VERSION_GROUP_NAME;
 import static org.apache.flink.kubernetes.operator.metrics.FlinkDeploymentMetrics.FLINK_VERSION_GROUP_NAME;
 import static org.apache.flink.kubernetes.operator.metrics.FlinkDeploymentMetrics.MEMORY_NAME;
 import static org.apache.flink.kubernetes.operator.metrics.FlinkDeploymentMetrics.RESOURCE_USAGE_GROUP_NAME;
@@ -226,13 +227,14 @@ public class FlinkDeploymentMetricsTest {
     public void testFlinkVersionMetrics() {
         Map<String, String> ns1Values = new HashMap<>();
         ns1Values.put("deployment1", "    ");
-        ns1Values.put("deployment2", "1.14");
-        ns1Values.put("deployment3", "1.14");
-        ns1Values.put("deployment4", "1.15");
-        ns1Values.put("deployment5", "1.15");
-        ns1Values.put("deployment6", "1.16");
-        ns1Values.put("deployment7", "1.17");
-        ns1Values.put("deployment8", "1.14");
+        ns1Values.put("deployment2", "1.14.0");
+        ns1Values.put("deployment3", "1.14.0");
+        ns1Values.put("deployment4", "1.15.1");
+        ns1Values.put("deployment5", "1.15.1");
+        ns1Values.put("deployment6", "1.16.0");
+        ns1Values.put("deployment7", "1.17.1");
+        ns1Values.put("deployment8", "1.14.1");
+        ns1Values.put("deployment9", "test");
 
         Map<String, String> ns2Values = new HashMap<>();
         ns2Values.put("deployment1", "");
@@ -248,20 +250,41 @@ public class FlinkDeploymentMetricsTest {
         var namespaceVersions = Map.of("ns1", ns1Values, "ns2", ns2Values);
         var expected =
                 Map.of(
-                        "ns1", Map.of("UNKNOWN", 1, "1.14", 3, "1.15", 2, "1.16", 1, "1.17", 1),
+                        "ns1",
+                                Map.of(
+                                        "UNKNOWN", 1, "1.14.0", 2, "1.14.1", 1, "1.15.1", 2,
+                                        "1.16.0", 1, "1.17.1", 1, "test", 1),
                         "ns2", Map.of("UNKNOWN", 2, "1.14", 2, "1.15", 3, "1.16", 1, "1.17", 1));
-        updateFlinkVersionsAndAssert(namespaceVersions, expected);
+        updateFlinkVersionsAndAssert(FLINK_VERSION_GROUP_NAME, namespaceVersions, expected);
 
-        // Remove invalid version and insert 1.14
-        namespaceVersions.get("ns1").put("deployment1", "1.14");
+        var expectedMinors =
+                Map.of(
+                        "ns1", Map.of("MALFORMED", 2, "1.14", 3, "1.15", 2, "1.16", 1, "1.17", 1),
+                        "ns2", Map.of("MALFORMED", 2, "1.14", 2, "1.15", 3, "1.16", 1, "1.17", 1));
+        updateFlinkVersionsAndAssert(
+                FLINK_MINOR_VERSION_GROUP_NAME, namespaceVersions, expectedMinors);
+
+        // Remove invalid version and insert 1.14.1
+        namespaceVersions.get("ns1").put("deployment1", "1.14.1");
         expected =
                 Map.of(
-                        "ns1", Map.of("UNKNOWN", 0, "1.14", 4, "1.15", 2, "1.16", 1, "1.17", 1),
+                        "ns1",
+                                Map.of(
+                                        "1.14.0", 2, "1.14.1", 2, "1.15.1", 2, "1.16.0", 1,
+                                        "1.17.1", 1, "test", 1),
                         "ns2", Map.of("UNKNOWN", 2, "1.14", 2, "1.15", 3, "1.16", 1, "1.17", 1));
-        updateFlinkVersionsAndAssert(namespaceVersions, expected);
+        updateFlinkVersionsAndAssert(FLINK_VERSION_GROUP_NAME, namespaceVersions, expected);
+
+        expectedMinors =
+                Map.of(
+                        "ns1", Map.of("MALFORMED", 1, "1.14", 4, "1.15", 2, "1.16", 1, "1.17", 1),
+                        "ns2", Map.of("MALFORMED", 2, "1.14", 2, "1.15", 3, "1.16", 1, "1.17", 1));
+        updateFlinkVersionsAndAssert(
+                FLINK_MINOR_VERSION_GROUP_NAME, namespaceVersions, expectedMinors);
     }
 
     private void updateFlinkVersionsAndAssert(
+            String metricGroup,
             Map<String, Map<String, String>> namespaceVersions,
             Map<String, Map<String, Integer>> expected) {
         for (var namespaceEntry : namespaceVersions.entrySet()) {
@@ -291,7 +314,7 @@ public class FlinkDeploymentMetricsTest {
                         listener.getNamespaceMetricId(
                                 FlinkDeployment.class,
                                 namespaceName,
-                                FLINK_VERSION_GROUP_NAME,
+                                metricGroup,
                                 version,
                                 COUNTER_NAME);