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 2020/12/11 13:06:25 UTC

[GitHub] [flink] zentol commented on a change in pull request #14340: [FLINK-20533][datadog] Add Histogram support

zentol commented on a change in pull request #14340:
URL: https://github.com/apache/flink/pull/14340#discussion_r540933465



##########
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:
       Yes, we should do this only once in the constructor; it's a waste of resources to do this every time.




----------------------------------------------------------------
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:
users@infra.apache.org