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

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


The following commit(s) were added to refs/heads/main by this push:
     new 94bcfa3e [SPARK-59935] Fix Prometheus `_sum` and quantiles of 
histograms and timers
94bcfa3e is described below

commit 94bcfa3ea261061b1644554df7bd7c9c9014cf10
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Fri Oct 2 01:39:37 2026 -0700

    [SPARK-59935] Fix Prometheus `_sum` and quantiles of histograms and timers
    
    ### What changes were proposed in this pull request?
    
    This PR fixes the Prometheus summaries of Dropwizard histograms and timers 
in `PrometheusPullModelHandler`.
    
    - Track the sum of all recorded values in the new `SummingHistogram` and 
`SummingTimer`, which the operator now uses, and export `_sum` only for them.
    - Export the median and the 99.9th percentile as the `0.5` and `0.999` 
quantiles of non-`nanos` histograms, instead of the mean and the 99th 
percentile.
    
    ### Why are the changes needed?
    
    `_sum` was the mean of the reservoir multiplied by the count. Since the 
mean covers only roughly the last 5 minutes, `_sum` could decrease between 
scrapes, which breaks `rate()`. This becomes visible once 
[#918](https://github.com/apache/spark-kubernetes-operator/pull/918) records 
real latencies.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. The values of `_sum` and of the quantiles above change compared to 
[1.0.0](https://github.com/apache/spark-kubernetes-operator/releases/tag/1.0.0) 
(2026-07-26), while metric names and types are unchanged. The migration guide 
is updated.
    
    ### How was this patch tested?
    
    Pass the CIs with the newly added test cases.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    Closes #922 from dongjoon-hyun/SPARK-59935.
    
    Authored-by: Dongjoon Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 docs/migration_guide.md                            |  7 +++
 .../k8s/operator/metrics/BaseOperatorSource.java   |  4 +-
 .../metrics/PrometheusPullModelHandler.java        | 39 ++++++------
 .../k8s/operator/metrics/SummingHistogram.java     | 71 ++++++++++++++++++++++
 .../spark/k8s/operator/metrics/SummingTimer.java   | 53 ++++++++++++++++
 .../source/KubernetesMetricsInterceptor.java       |  4 +-
 .../metrics/PrometheusPullModelHandlerTest.java    | 64 +++++++++++++++++--
 .../metrics/SparkAppStatusRecorderSourceTest.java  |  3 +-
 .../source/KubernetesMetricsInterceptorTest.java   |  3 +
 .../metrics/source/OperatorJosdkMetricsTest.java   |  5 +-
 10 files changed, 227 insertions(+), 26 deletions(-)

diff --git a/docs/migration_guide.md b/docs/migration_guide.md
index 465f01f3..54b834ce 100644
--- a/docs/migration_guide.md
+++ b/docs/migration_guide.md
@@ -83,6 +83,13 @@ affect building the project, CI, tests or examples.
   documented. 1.0 capped it at about 15 seconds, so with the other defaults, 
the retries now span
   about 49 minutes instead of about 3 minutes. To restore the behavior before 
1.1.0, set it to
   `15` ([SPARK-59892](https://issues.apache.org/jira/browse/SPARK-59892)).
+- Since 1.1.0, the `_sum` of the Prometheus summaries of the operator 
histograms and timers, e.g.
+  `kubernetes_client_http_response_latency_seconds_sum`, is the sum of all 
recorded values. 1.0
+  exported the mean of roughly the last 5 minutes multiplied by the count 
instead, which can
+  decrease between scrapes, so `rate()` of it and the average derived from it 
were wrong. Also, the
+  `0.5` and `0.999` quantiles of the `operator_sdk_*` histograms are the 
median and the 99.9th
+  percentile instead of the mean and the 99th percentile. A histogram or timer 
of a custom metrics
+  source has no `_sum` unless it is a `SummingHistogram` or a `SummingTimer` 
([SPARK-59935](https://issues.apache.org/jira/browse/SPARK-59935)).
 
 ### SparkApplication
 
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/BaseOperatorSource.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/BaseOperatorSource.java
index 35401312..f79d2bcb 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/BaseOperatorSource.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/BaseOperatorSource.java
@@ -51,7 +51,7 @@ public class BaseOperatorSource {
     if (histograms.containsKey(metricName)) {
       histogram = histograms.get(metricName);
     } else {
-      histogram = metricRegistry.histogram(metricName);
+      histogram = metricRegistry.histogram(metricName, SummingHistogram::new);
       histograms.put(metricName, histogram);
     }
     return histogram;
@@ -109,7 +109,7 @@ public class BaseOperatorSource {
     if (timers.containsKey(metricName)) {
       timer = timers.get(metricName);
     } else {
-      timer = metricRegistry.timer(metricName);
+      timer = metricRegistry.timer(metricName, SummingTimer::new);
       timers.put(metricName, timer);
     }
     return timer;
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandler.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandler.java
index 5ae9f670..06e980d1 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandler.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandler.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.function.DoubleUnaryOperator;
 
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Gauge;
@@ -246,8 +247,13 @@ public class PrometheusPullModelHandler extends 
PrometheusServlet implements Htt
       if (isNanosHistogram) {
         baseName = nanosMetricsNameToSeconds(baseName);
       }
-      double sum =
-          isNanosHistogram ? nanosToSeconds(snap.getMean() * count) : 
snap.getMean() * count;
+      DoubleUnaryOperator toUnit =
+          isNanosHistogram ? this::nanosToSeconds : 
DoubleUnaryOperator.identity();
+      // The sum is exported only if it is tracked, see SummingHistogram.
+      String sum = "";
+      if (histogram instanceof SummingHistogram summingHistogram) {
+        sum = baseName + "_sum " + 
toUnit.applyAsDouble(summingHistogram.getSum()) + "\n";
+      }
       return "# HELP "
           + baseName
           + " Histogram metric\n# TYPE "
@@ -255,38 +261,34 @@ public class PrometheusPullModelHandler extends 
PrometheusServlet implements Htt
           + " summary\n"
           + baseName
           + "{quantile=\"0.5\"} "
-          + (isNanosHistogram ? nanosToSeconds(snap.getMedian()) : 
snap.getMean())
+          + toUnit.applyAsDouble(snap.getMedian())
           + "\n"
           + baseName
           + "{quantile=\"0.75\"} "
-          + (isNanosHistogram ? nanosToSeconds(snap.get75thPercentile()) : 
snap.get75thPercentile())
+          + toUnit.applyAsDouble(snap.get75thPercentile())
           + "\n"
           + baseName
           + "{quantile=\"0.95\"} "
-          + (isNanosHistogram ? nanosToSeconds(snap.get95thPercentile()) : 
snap.get95thPercentile())
+          + toUnit.applyAsDouble(snap.get95thPercentile())
           + "\n"
           + baseName
           + "{quantile=\"0.98\"} "
-          + (isNanosHistogram ? nanosToSeconds(snap.get98thPercentile()) : 
snap.get98thPercentile())
+          + toUnit.applyAsDouble(snap.get98thPercentile())
           + "\n"
           + baseName
           + "{quantile=\"0.99\"} "
-          + (isNanosHistogram ? nanosToSeconds(snap.get99thPercentile()) : 
snap.get99thPercentile())
+          + toUnit.applyAsDouble(snap.get99thPercentile())
           + "\n"
           + baseName
           + "{quantile=\"0.999\"} "
-          + (isNanosHistogram
-              ? nanosToSeconds(snap.get999thPercentile())
-              : snap.get99thPercentile())
+          + toUnit.applyAsDouble(snap.get999thPercentile())
           + "\n"
           + baseName
           + "_count "
           + count
           + "\n"
-          + baseName
-          + "_sum "
           + sum
-          + "\n\n";
+          + "\n";
     }
     return null;
   }
@@ -340,6 +342,11 @@ public class PrometheusPullModelHandler extends 
PrometheusServlet implements Htt
       String baseName = sanitize(name);
       Snapshot snap = timer.getSnapshot();
       long count = timer.getCount();
+      // The sum is exported only if it is tracked, see SummingHistogram.
+      String sum = "";
+      if (timer instanceof SummingTimer summingTimer) {
+        sum = baseName + "_duration_seconds_sum " + 
nanosToSeconds(summingTimer.getSum()) + "\n";
+      }
       return "# HELP "
           + baseName
           + "_duration_seconds Timer summary\n# TYPE "
@@ -380,10 +387,8 @@ public class PrometheusPullModelHandler extends 
PrometheusServlet implements Htt
           + "_duration_seconds_count "
           + count
           + "\n"
-          + baseName
-          + "_duration_seconds_sum "
-          + nanosToSeconds(snap.getMean() * count)
-          + "\n\n# TYPE "
+          + sum
+          + "\n# TYPE "
           + baseName
           + " gauge\n"
           + baseName
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/SummingHistogram.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/SummingHistogram.java
new file mode 100644
index 00000000..f0b2ff83
--- /dev/null
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/SummingHistogram.java
@@ -0,0 +1,71 @@
+/*
+ * 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.spark.k8s.operator.metrics;
+
+import java.util.concurrent.atomic.LongAdder;
+
+import com.codahale.metrics.ExponentiallyDecayingReservoir;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Reservoir;
+
+/**
+ * A Histogram which also tracks the sum of all recorded values.
+ *
+ * <p>The snapshot of the default reservoir represents roughly the last 5 
minutes, so its mean
+ * multiplied by the count is not the sum of all values, and can even 
decrease. {@link
+ * PrometheusPullModelHandler} exports this sum as the {@code _sum} of a 
summary.
+ */
+public class SummingHistogram extends Histogram {
+  private final LongAdder sum = new LongAdder();
+
+  /** Constructs a new SummingHistogram with an exponentially decaying 
reservoir, the default. */
+  public SummingHistogram() {
+    this(new ExponentiallyDecayingReservoir());
+  }
+
+  /**
+   * Constructs a histogram sampling the values into the given reservoir, for 
tests.
+   *
+   * @param reservoir The reservoir to sample the recorded values.
+   */
+  SummingHistogram(Reservoir reservoir) {
+    super(reservoir);
+  }
+
+  /**
+   * Records a value and adds it to the sum.
+   *
+   * @param value The value to record.
+   */
+  @Override
+  public void update(long value) {
+    super.update(value);
+    sum.add(value);
+  }
+
+  /**
+   * Returns the sum of all recorded values.
+   *
+   * @return The sum of all recorded values.
+   */
+  public long getSum() {
+    return sum.sum();
+  }
+}
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/SummingTimer.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/SummingTimer.java
new file mode 100644
index 00000000..88b15704
--- /dev/null
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/SummingTimer.java
@@ -0,0 +1,53 @@
+/*
+ * 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.spark.k8s.operator.metrics;
+
+import com.codahale.metrics.Clock;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Timer;
+
+/** A Timer which also tracks the sum of all recorded durations, see {@link 
SummingHistogram}. */
+public class SummingTimer extends Timer {
+  private final SummingHistogram histogram;
+
+  /** Constructs a new SummingTimer with an exponentially decaying reservoir, 
the default. */
+  public SummingTimer() {
+    this(new SummingHistogram());
+  }
+
+  /**
+   * Constructs a timer recording the durations into the given histogram, for 
tests.
+   *
+   * @param histogram The histogram to record the durations in nanoseconds.
+   */
+  SummingTimer(SummingHistogram histogram) {
+    super(new Meter(), histogram, Clock.defaultClock());
+    this.histogram = histogram;
+  }
+
+  /**
+   * Returns the sum of all recorded durations.
+   *
+   * @return The sum of all recorded durations in nanoseconds.
+   */
+  public long getSum() {
+    return histogram.getSum();
+  }
+}
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptor.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptor.java
index 35f2fd70..dff97e92 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptor.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptor.java
@@ -36,6 +36,7 @@ import com.codahale.metrics.MetricRegistry;
 import io.fabric8.kubernetes.client.http.*;
 import lombok.extern.slf4j.Slf4j;
 
+import org.apache.spark.k8s.operator.metrics.SummingHistogram;
 import org.apache.spark.metrics.source.Source;
 import org.apache.spark.util.Pair;
 
@@ -67,7 +68,8 @@ public class KubernetesMetricsInterceptor implements 
Interceptor, Source {
 
     responseLatency =
         metricRegistry.histogram(
-            MetricRegistry.name(HTTP_RESPONSE_GROUP, "latency", 
"nanos").toLowerCase());
+            MetricRegistry.name(HTTP_RESPONSE_GROUP, "latency", 
"nanos").toLowerCase(),
+            SummingHistogram::new);
     requestFailedRateMeter =
         
metricRegistry.meter(MetricRegistry.name(HTTP_REQUEST_FAILED_GROUP).toLowerCase());
     requestRateMeter = 
metricRegistry.meter(MetricRegistry.name(HTTP_REQUEST_GROUP).toLowerCase());
diff --git 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandlerTest.java
 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandlerTest.java
index 7efdc23f..9240b724 100644
--- 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandlerTest.java
+++ 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/PrometheusPullModelHandlerTest.java
@@ -31,6 +31,8 @@ import com.codahale.metrics.Gauge;
 import com.codahale.metrics.Histogram;
 import com.codahale.metrics.Meter;
 import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.SlidingWindowReservoir;
+import com.codahale.metrics.Snapshot;
 import com.codahale.metrics.Timer;
 import org.junit.jupiter.api.Test;
 
@@ -64,7 +66,7 @@ class PrometheusPullModelHandlerTest {
   @Test
   void testFormatMetricsSnapshotIncludesHistogram() throws Exception {
     MetricRegistry registry = new MetricRegistry();
-    Histogram histogram = registry.histogram("foo_histogram");
+    Histogram histogram = registry.histogram("foo_histogram", 
SummingHistogram::new);
     histogram.update(100);
     histogram.update(200);
 
@@ -74,13 +76,13 @@ class PrometheusPullModelHandlerTest {
 
     assertTrue(output.contains("# TYPE foo_histogram summary"));
     assertTrue(output.contains("foo_histogram_count 2"));
-    assertTrue(output.contains("foo_histogram_sum"));
+    assertTrue(output.contains("foo_histogram_sum 300.0"));
   }
 
   @Test
   void testFormatMetricsSnapshotIncludesHistogramWithNanos() throws Exception {
     MetricRegistry registry = new MetricRegistry();
-    Histogram histogram = registry.histogram("foo_nanos_histogram");
+    Histogram histogram = registry.histogram("foo_nanos_histogram", 
SummingHistogram::new);
     histogram.update(563682);
     histogram.update(716252);
     histogram.update(292098);
@@ -111,7 +113,7 @@ class PrometheusPullModelHandlerTest {
   @Test
   void testFormatMetricsSnapshotIncludesTimer() throws Exception {
     MetricRegistry registry = new MetricRegistry();
-    Timer timer = registry.timer("foo_timer");
+    Timer timer = registry.timer("foo_timer", SummingTimer::new);
 
     timer.update(Duration.of(500, ChronoUnit.MILLIS));
     timer.update(Duration.of(1000, ChronoUnit.MILLIS));
@@ -124,6 +126,60 @@ class PrometheusPullModelHandlerTest {
     assertTrue(output.contains("foo_timer_m1_rate"));
   }
 
+  @Test
+  void testFormatHistogramQuantiles() {
+    MetricRegistry registry = new MetricRegistry();
+    Histogram histogram = registry.histogram("foo_histogram");
+    for (int i = 1; i <= 1000; i++) {
+      histogram.update(i);
+    }
+    Snapshot snapshot = histogram.getSnapshot();
+    PrometheusPullModelHandler handler = new PrometheusPullModelHandler(new 
Properties(), registry);
+
+    String output = handler.formatMetricsSnapshot();
+    assertTrue(
+        output.contains("foo_histogram{quantile=\"0.5\"} " + 
snapshot.getMedian() + "\n"), output);
+    assertTrue(
+        output.contains(
+            "foo_histogram{quantile=\"0.999\"} " + 
snapshot.get999thPercentile() + "\n"),
+        output);
+  }
+
+  @Test
+  void testFormatMetricsSnapshotIncludesSumOfAllValues() {
+    MetricRegistry registry = new MetricRegistry();
+    // Each reservoir keeps only the last value, so its mean times the count 
is not the sum.
+    Histogram histogram =
+        registry.register("foo_nanos", new SummingHistogram(new 
SlidingWindowReservoir(1)));
+    Timer timer =
+        registry.register(
+            "foo_timer", new SummingTimer(new SummingHistogram(new 
SlidingWindowReservoir(1))));
+    PrometheusPullModelHandler handler = new PrometheusPullModelHandler(new 
Properties(), registry);
+
+    histogram.update(Duration.ofMillis(45).toNanos());
+    histogram.update(Duration.ofMillis(15).toNanos());
+    timer.update(Duration.ofMillis(45));
+    timer.update(Duration.ofMillis(15));
+
+    String output = handler.formatMetricsSnapshot();
+    assertTrue(output.contains("foo_seconds_sum 0.06\n"), output);
+    assertTrue(output.contains("foo_timer_duration_seconds_sum 0.06\n"), 
output);
+  }
+
+  @Test
+  void testFormatMetricsSnapshotExcludesSumOfPlainHistogramAndTimer() {
+    MetricRegistry registry = new MetricRegistry();
+    registry.histogram("foo_histogram").update(100);
+    registry.timer("foo_timer").update(Duration.ofMillis(500));
+    PrometheusPullModelHandler handler = new PrometheusPullModelHandler(new 
Properties(), registry);
+
+    String output = handler.formatMetricsSnapshot();
+    assertTrue(output.contains("foo_histogram_count 1\n"));
+    assertFalse(output.contains("foo_histogram_sum"));
+    assertTrue(output.contains("foo_timer_duration_seconds_count 1\n"));
+    assertFalse(output.contains("foo_timer_duration_seconds_sum"));
+  }
+
   @Test
   void testFormatMetricsSnapshotIncludesEmpty() throws Exception {
     MetricRegistry registry = new MetricRegistry();
diff --git 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/SparkAppStatusRecorderSourceTest.java
 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/SparkAppStatusRecorderSourceTest.java
index 5f153285..230d9837 100644
--- 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/SparkAppStatusRecorderSourceTest.java
+++ 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/SparkAppStatusRecorderSourceTest.java
@@ -20,6 +20,7 @@
 package org.apache.spark.k8s.operator.metrics;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.time.Instant;
@@ -76,7 +77,7 @@ class SparkAppStatusRecorderSourceTest {
     source.recordStatusUpdateLatency(app.getMetadata(), app.getStatus(), new 
ApplicationState());
     Map<String, Timer> timers = source.metricRegistry().getTimers();
     assertEquals(1, timers.size());
-    assertTrue(timers.containsKey("sparkapp.latency.discover"));
+    assertInstanceOf(SummingTimer.class, 
timers.get("sparkapp.latency.discover"));
     assertTrue(timers.get("sparkapp.latency.discover").getSnapshot().getMin() 
> 0);
   }
 
diff --git 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptorTest.java
 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptorTest.java
index 24c2e1cc..36e16018 100644
--- 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptorTest.java
+++ 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/KubernetesMetricsInterceptorTest.java
@@ -43,6 +43,7 @@ import org.junit.jupiter.api.TestMethodOrder;
 
 import org.apache.spark.k8s.operator.SparkApplication;
 import org.apache.spark.k8s.operator.client.KubernetesClientFactory;
+import org.apache.spark.k8s.operator.metrics.SummingHistogram;
 import org.apache.spark.k8s.operator.spec.ApplicationSpec;
 
 @EnableKubernetesMockClient(crud = true)
@@ -70,6 +71,8 @@ class KubernetesMetricsInterceptorTest {
 
       Map<String, Metric> metrics = new 
HashMap<>(metricsInterceptor.metricRegistry().getMetrics());
       Assertions.assertEquals(9, metrics.size());
+      Assertions.assertInstanceOf(
+          SummingHistogram.class, metrics.get("http.response.latency.nanos"));
       client.resource(sparkApplication).create();
       client.resource(configMap).get();
       Map<String, Metric> metrics2 =
diff --git 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/OperatorJosdkMetricsTest.java
 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/OperatorJosdkMetricsTest.java
index d91e42fb..fb6d79d6 100644
--- 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/OperatorJosdkMetricsTest.java
+++ 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/metrics/source/OperatorJosdkMetricsTest.java
@@ -20,6 +20,7 @@
 package org.apache.spark.k8s.operator.metrics.source;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.Map;
@@ -39,6 +40,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import org.apache.spark.k8s.operator.SparkApplication;
+import org.apache.spark.k8s.operator.metrics.SummingHistogram;
 
 class OperatorJosdkMetricsTest {
   private static final String DEFAULT_NAMESPACE = "default";
@@ -66,7 +68,8 @@ class OperatorJosdkMetricsTest {
     operatorMetrics.timeControllerExecution(successExecution);
     Map<String, Metric> metrics = 
operatorMetrics.metricRegistry().getMetrics();
     assertEquals(4, metrics.size());
-    
assertTrue(metrics.containsKey("sparkapplication.test-controller.reconcile.both"));
+    assertInstanceOf(
+        SummingHistogram.class, 
metrics.get("sparkapplication.test-controller.reconcile.both"));
     
assertTrue(metrics.containsKey("sparkapplication.testns.test-controller.reconcile.both"));
     
assertTrue(metrics.containsKey("sparkapplication.test-controller.reconcile.success.both"));
     assertTrue(


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to