rmetzger commented on a change in pull request #14340: URL: https://github.com/apache/flink/pull/14340#discussion_r540898612
########## File path: flink-metrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DHistogram.java ########## @@ -0,0 +1,61 @@ +/* + * 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.metrics.datadog; + +import org.apache.flink.metrics.Histogram; +import org.apache.flink.metrics.HistogramStatistics; + +import java.util.List; + +/** + * Maps histograms to datadog gauges. + * + * <p>Note: We cannot map them to datadog histograms because the HTTP API does not support them. + */ +public class DHistogram { + private final Histogram histogram; + private final MetricMetaData metaData; + + public DHistogram(Histogram histogram, String metricName, String host, List<String> tags, Clock clock) { + this.histogram = histogram; + this.metaData = new MetricMetaData(MetricType.gauge, metricName, host, tags, clock); + } + + public void addTo(DSeries series) { + final HistogramStatistics statistics = histogram.getStatistics(); + + // this selection is based on https://docs.datadoghq.com/developers/metrics/types/?tab=histogram + // we only exclude 'sum' (which is optional), because we cannot compute it + // the semantics for count are also slightly different, because we don't reset it after a report + series.add(new StaticDMetric(statistics.getMean(), withMetricNameSuffix(metaData, "avg"))); + series.add(new StaticDMetric(histogram.getCount(), withMetricNameSuffix(metaData, "count"))); + series.add(new StaticDMetric(statistics.getQuantile(.5), withMetricNameSuffix(metaData, "median"))); + series.add(new StaticDMetric(statistics.getQuantile(.95), withMetricNameSuffix(metaData, "95percentile"))); + series.add(new StaticDMetric(statistics.getMin(), withMetricNameSuffix(metaData, "min"))); + series.add(new StaticDMetric(statistics.getMax(), withMetricNameSuffix(metaData, "max"))); Review comment: This runs in a separate thread, but seems quite expensive with the string concat and the MetricsMetaData allocation each time we send the metric. Does it make sense to initialize the MetaData with the different name suffixes in the constructor? ########## File path: flink-metrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DatadogHttpClient.java ########## @@ -113,8 +113,8 @@ public void send(DSeries request) throws Exception { client.newCall(r).enqueue(EmptyCallback.getEmptyCallback()); } - public static String serialize(Object obj) throws JsonProcessingException { - return MAPPER.writeValueAsString(obj); + public static String serialize(Object obj, ObjectMapper mapper) throws JsonProcessingException { + return mapper.writeValueAsString(obj); Review comment: I understand you changed this for the tests, but it's a bit ugly. Maybe add a comment? ########## File path: flink-metrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DatadogHttpClient.java ########## @@ -113,8 +113,8 @@ public void send(DSeries request) throws Exception { client.newCall(r).enqueue(EmptyCallback.getEmptyCallback()); } - public static String serialize(Object obj) throws JsonProcessingException { - return MAPPER.writeValueAsString(obj); + public static String serialize(Object obj, ObjectMapper mapper) throws JsonProcessingException { + return mapper.writeValueAsString(obj); Review comment: Strictly speaking this mapper is only necessary for having deterministic test results. The proper solution would probably be parsing the JSON response and compare the results not as a string. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org