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-6013][metrics] Add Datadog HTTP metrics reporter
This closes apache#3736.
- Loading branch information
Showing
15 changed files
with
970 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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:https://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. | ||
--> | ||
<project xmlns="http:https://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-metrics</artifactId> | ||
<version>1.4-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>flink-metrics-datadog</artifactId> | ||
<name>flink-metrics-datadog</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-metrics-core</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.squareup.okhttp3</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<version>3.7.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.squareup.okio</groupId> | ||
<artifactId>okio</artifactId> | ||
<version>1.12.0</version> | ||
</dependency> | ||
|
||
|
||
<!-- test dependencies --> | ||
|
||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-runtime_2.10</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-test-utils-junit</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<shadedArtifactAttached>true</shadedArtifactAttached> | ||
<relocations combine.children="append"> | ||
<relocation> | ||
<pattern>okhttp3</pattern> | ||
<shadedPattern>org.apache.flink.shaded.okhttp3</shadedPattern> | ||
</relocation> | ||
<relocation> | ||
<pattern>okio</pattern> | ||
<shadedPattern>org.apache.flink.shaded.okio</shadedPattern> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
...etrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DCounter.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,44 @@ | ||
/* | ||
* 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:https://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.Counter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Mapping of counter between Flink and Datadog | ||
* */ | ||
public class DCounter extends DMetric { | ||
private final Counter counter; | ||
|
||
public DCounter(Counter c, String metricName, String host, List<String> tags) { | ||
super(MetricType.counter, metricName, host, tags); | ||
counter = c; | ||
} | ||
|
||
/** | ||
* Visibility of this method must not be changed | ||
* since we deliberately not map it to json object in a Datadog-defined format | ||
* */ | ||
@Override | ||
public Number getMetricValue() { | ||
return counter.getCount(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...-metrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DGauge.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,45 @@ | ||
/* | ||
* 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:https://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.Gauge; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Mapping of gauge between Flink and Datadog | ||
* */ | ||
public class DGauge extends DMetric { | ||
private final Gauge<Number> gauge; | ||
|
||
public DGauge(Gauge<Number> g, String metricName, String host, List<String> tags) { | ||
super(MetricType.gauge, metricName, host, tags); | ||
gauge = g; | ||
} | ||
|
||
/** | ||
* Visibility of this method must not be changed | ||
* since we deliberately not map it to json object in a Datadog-defined format | ||
* */ | ||
@Override | ||
public Number getMetricValue() { | ||
return gauge.getValue(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...-metrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DMeter.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,42 @@ | ||
/* | ||
* 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:https://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.Meter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Mapping of meter between Flink and Datadog | ||
* | ||
* Only consider rate of the meter, due to Datadog HTTP API's limited support of meter | ||
* */ | ||
public class DMeter extends DMetric { | ||
private final Meter meter; | ||
|
||
public DMeter(Meter m, String metricName, String host, List<String> tags) { | ||
super(MetricType.gauge, metricName, host, tags); | ||
meter = m; | ||
} | ||
|
||
@Override | ||
public Number getMetricValue() { | ||
return meter.getRate(); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...metrics/flink-metrics-datadog/src/main/java/org/apache/flink/metrics/datadog/DMetric.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,84 @@ | ||
/* | ||
* 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:https://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 com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Abstract metric of Datadog for serialization | ||
* */ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public abstract class DMetric { | ||
private static final long MILLIS_TO_SEC = 1000L; | ||
|
||
/** | ||
* Names of metric/type/tags field and their getters must not be changed | ||
* since they are mapped to json objects in a Datadog-defined format | ||
* */ | ||
private final String metric; // Metric name | ||
private final MetricType type; | ||
private final String host; | ||
private final List<String> tags; | ||
|
||
public DMetric(MetricType metricType, String metric, String host, List<String> tags) { | ||
this.type = metricType; | ||
this.metric = metric; | ||
this.host = host; | ||
this.tags = tags; | ||
} | ||
|
||
public MetricType getType() { | ||
return type; | ||
} | ||
|
||
public String getMetric() { | ||
return metric; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public List<String> getTags() { | ||
return tags; | ||
} | ||
|
||
public List<List<Number>> getPoints() { | ||
// One single data point | ||
List<Number> point = new ArrayList<>(); | ||
point.add(getUnixEpochTimestamp()); | ||
point.add(getMetricValue()); | ||
|
||
List<List<Number>> points = new ArrayList<>(); | ||
points.add(point); | ||
|
||
return points; | ||
} | ||
|
||
@JsonIgnore | ||
public abstract Number getMetricValue(); | ||
|
||
public static long getUnixEpochTimestamp() { | ||
return (System.currentTimeMillis() / MILLIS_TO_SEC); | ||
} | ||
} |
Oops, something went wrong.