Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3833#discussion_r116377143
  
    --- Diff: 
flink-metrics/flink-metrics-prometheus/src/main/java/org/apache/flink/metrics/prometheus/PrometheusReporter.java
 ---
    @@ -133,61 +136,58 @@ public void notifyOfRemovedMetric(final Metric 
metric, final String metricName,
                collectorsByMetricName.remove(metricName);
        }
     
    +   @SuppressWarnings("unchecked")
    +   private static String getLogicalScope(MetricGroup group) {
    +           return ((FrontMetricGroup<AbstractMetricGroup<?>>) 
group).getLogicalScope(CHARACTER_FILTER, SCOPE_SEPARATOR);
    +   }
    +
        private Collector createGauge(final Gauge gauge, final String name, 
final String identifier, final List<String> labelNames, final List<String> 
labelValues) {
    -           return io.prometheus.client.Gauge
    -                   .build()
    -                   .name(name)
    -                   .help(identifier)
    -                   .labelNames(toArray(labelNames, String.class))
    -                   .create()
    -                   .setChild(new io.prometheus.client.Gauge.Child() {
    -                           @Override
    -                           public double get() {
    -                                   final Object value = gauge.getValue();
    -                                   if (value instanceof Double) {
    -                                           return (double) value;
    -                                   }
    -                                   if (value instanceof Number) {
    -                                           return ((Number) 
value).doubleValue();
    -                                   } else if (value instanceof Boolean) {
    -                                           return ((Boolean) value) ? 1 : 
0;
    -                                   } else {
    -                                           log.debug("Invalid type for 
Gauge {}: {}, only number types and booleans are supported by this reporter.",
    -                                                   gauge, 
value.getClass().getName());
    -                                           return 0;
    -                                   }
    +           return newGauge(name, identifier, labelNames, labelValues, new 
io.prometheus.client.Gauge.Child() {
    +                   @Override
    +                   public double get() {
    +                           final Object value = gauge.getValue();
    +                           if (value instanceof Double) {
    +                                   return (double) value;
    +                           }
    +                           if (value instanceof Number) {
    +                                   return ((Number) value).doubleValue();
    +                           } else if (value instanceof Boolean) {
    +                                   return ((Boolean) value) ? 1 : 0;
    +                           } else {
    +                                   LOG.debug("Invalid type for Gauge {}: 
{}, only number types and booleans are supported by this reporter.",
    +                                           gauge, 
value.getClass().getName());
    +                                   return 0;
                                }
    -                   }, toArray(labelValues, String.class));
    +                   }
    +           });
        }
     
        private static Collector createGauge(final Counter counter, final 
String name, final String identifier, final List<String> labelNames, final 
List<String> labelValues) {
    -           return io.prometheus.client.Gauge
    -                   .build()
    -                   .name(name)
    -                   .help(identifier)
    -                   .labelNames(toArray(labelNames, String.class))
    -                   .create()
    -                   .setChild(new io.prometheus.client.Gauge.Child() {
    -                           @Override
    -                           public double get() {
    -                                   return (double) counter.getCount();
    -                           }
    -                   }, toArray(labelValues, String.class));
    +           return newGauge(name, identifier, labelNames, labelValues, new 
io.prometheus.client.Gauge.Child() {
    +                   @Override
    +                   public double get() {
    +                           return (double) counter.getCount();
    +                   }
    +           });
    +   }
    +
    +   private Collector createGauge(final Meter meter, final String name, 
final String identifier, final List<String> labelNames, final List<String> 
labelValues) {
    +           return newGauge(name + "_rate", identifier, labelNames, 
labelValues, new io.prometheus.client.Gauge.Child() {
    --- End diff --
    
    Meter metrics should contain "rate" in their name already, so we don't have 
to append "_rate" here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to