-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from DeyanZhelyazkov/master
Add dropwizard based java client for custom metrics. Excluding jackson dependency.
- Loading branch information
Showing
40 changed files
with
1,525 additions
and
92 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
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
104 changes: 53 additions & 51 deletions
104
cf-java-monitoring-custom-metrics-clients/cf-custom-metrics-clients-core/pom.xml
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 |
---|---|---|
@@ -1,54 +1,56 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.sap.hcp.cf.logging</groupId> | ||
<artifactId>cf-java-monitoring-custom-metrics-clients</artifactId> | ||
<version>3.0.1</version> | ||
</parent> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.sap.hcp.cf.logging</groupId> | ||
<artifactId>cf-java-monitoring-custom-metrics-clients</artifactId> | ||
<version>3.0.2</version> | ||
</parent> | ||
|
||
<artifactId>cf-custom-metrics-clients-core</artifactId> | ||
<packaging>jar</packaging> | ||
<name>cf-java-monitoring-custom-metrics-clients-core</name> | ||
<artifactId>cf-custom-metrics-clients-core</artifactId> | ||
<packaging>jar</packaging> | ||
<name>cf-java-monitoring-custom-metrics-clients-core</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Test dependencies--> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
48 changes: 48 additions & 0 deletions
48
...ain/java/com/sap/cloud/cf/monitoring/client/configuration/CustomMetricsConfiguration.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,48 @@ | ||
package com.sap.cloud.cf.monitoring.client.configuration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class CustomMetricsConfiguration { | ||
|
||
static final long DEFAULT_INTERVAL = TimeUnit.MINUTES.toMillis(1); | ||
private long interval = DEFAULT_INTERVAL; | ||
private boolean enabled = true; | ||
private List<String> metrics; | ||
private boolean metricQuantiles = false; | ||
|
||
public long getInterval() { | ||
return interval; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public List<String> getMetrics() { | ||
if (this.metrics == null) { | ||
return Collections.emptyList(); | ||
} | ||
return new ArrayList<>(metrics); | ||
} | ||
|
||
public boolean metricQuantiles() { | ||
return metricQuantiles; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringBuilder("CustomMetricsConfiguration[").append("interval=") | ||
.append(interval) | ||
.append(", enabled=") | ||
.append(enabled) | ||
.append(", metrics=") | ||
.append(metrics) | ||
.append("]") | ||
.append(", metricQuantiles=") | ||
.append(metricQuantiles) | ||
.toString(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...a/com/sap/cloud/cf/monitoring/client/configuration/CustomMetricsConfigurationFactory.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,25 @@ | ||
package com.sap.cloud.cf.monitoring.client.configuration; | ||
|
||
import java.util.Map; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
public class CustomMetricsConfigurationFactory { | ||
|
||
private static final String CUSTOM_METRICS_KEY = "CUSTOM_METRICS"; | ||
private static final Gson gson = | ||
new GsonBuilder().registerTypeAdapter(long.class, new LongIntervalGsonTypeAdapter()).create(); | ||
|
||
public static CustomMetricsConfiguration create() { | ||
return create(System.getenv()); | ||
} | ||
|
||
public static CustomMetricsConfiguration create(Map<String, String> env) { | ||
String customMetricsString = env.get(CUSTOM_METRICS_KEY); | ||
if (customMetricsString == null || customMetricsString.isEmpty()) { | ||
return new CustomMetricsConfiguration(); | ||
} | ||
return gson.fromJson(customMetricsString, CustomMetricsConfiguration.class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...in/java/com/sap/cloud/cf/monitoring/client/configuration/LongIntervalGsonTypeAdapter.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,30 @@ | ||
package com.sap.cloud.cf.monitoring.client.configuration; | ||
|
||
import static com.sap.cloud.cf.monitoring.client.configuration.CustomMetricsConfiguration.DEFAULT_INTERVAL; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
|
||
final class LongIntervalGsonTypeAdapter implements JsonDeserializer<Long> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(LongIntervalGsonTypeAdapter.class); | ||
private static final long MINIMAL_INTERVAL = 20000L; | ||
|
||
@Override | ||
public Long deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { | ||
long value = Long.parseLong(json.getAsString()); | ||
if (value < MINIMAL_INTERVAL) { | ||
LOGGER.warn(String.format( | ||
"The value of 'interval' property could not be less than %s. The default value %s will be used.", | ||
MINIMAL_INTERVAL, DEFAULT_INTERVAL)); | ||
return DEFAULT_INTERVAL; | ||
} | ||
return value; | ||
} | ||
} |
Oops, something went wrong.