forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-20533][datadog] Add Histogram support
- Loading branch information
Showing
6 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...rics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DHistogram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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.annotation.VisibleForTesting; | ||
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 { | ||
@VisibleForTesting | ||
static final String SUFFIX_AVG = ".avg"; | ||
@VisibleForTesting | ||
static final String SUFFIX_COUNT = ".count"; | ||
@VisibleForTesting | ||
static final String SUFFIX_MEDIAN = ".median"; | ||
@VisibleForTesting | ||
static final String SUFFIX_95_PERCENTILE = ".95percentile"; | ||
@VisibleForTesting | ||
static final String SUFFIX_MIN = ".min"; | ||
@VisibleForTesting | ||
static final String SUFFIX_MAX = ".max"; | ||
|
||
private final Histogram histogram; | ||
|
||
private final MetricMetaData metaDataAvg; | ||
private final MetricMetaData metaDataCount; | ||
private final MetricMetaData metaDataMedian; | ||
private final MetricMetaData metaData95Percentile; | ||
private final MetricMetaData metaDataMin; | ||
private final MetricMetaData metaDataMax; | ||
|
||
public DHistogram(Histogram histogram, String metricName, String host, List<String> tags, Clock clock) { | ||
this.histogram = histogram; | ||
this.metaDataAvg = new MetricMetaData(MetricType.gauge, metricName + SUFFIX_AVG, host, tags, clock); | ||
this.metaDataCount = new MetricMetaData(MetricType.gauge, metricName + SUFFIX_COUNT, host, tags, clock); | ||
this.metaDataMedian = new MetricMetaData(MetricType.gauge, metricName + SUFFIX_MEDIAN, host, tags, clock); | ||
this.metaData95Percentile = new MetricMetaData(MetricType.gauge, metricName + SUFFIX_95_PERCENTILE, host, tags, clock); | ||
this.metaDataMin = new MetricMetaData(MetricType.gauge, metricName + SUFFIX_MIN, host, tags, clock); | ||
this.metaDataMax = new MetricMetaData(MetricType.gauge, metricName + SUFFIX_MAX, 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(), metaDataAvg)); | ||
series.add(new StaticDMetric(histogram.getCount(), metaDataCount)); | ||
series.add(new StaticDMetric(statistics.getQuantile(.5), metaDataMedian)); | ||
series.add(new StaticDMetric(statistics.getQuantile(.95), metaData95Percentile)); | ||
series.add(new StaticDMetric(statistics.getMin(), metaDataMin)); | ||
series.add(new StaticDMetric(statistics.getMax(), metaDataMax)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...s/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/StaticDMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* A {@link DMetric} that returns a fixed value. | ||
*/ | ||
public class StaticDMetric extends DMetric { | ||
private final Number value; | ||
|
||
public StaticDMetric(Number value, MetricMetaData metaData) { | ||
super(metaData); | ||
this.value = value; | ||
} | ||
|
||
public Number getMetricValue() { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters