Skip to content

Commit

Permalink
Merge pull request #5 from philterd/4-philter-metrics
Browse files Browse the repository at this point in the history
Adding metrics from Phileas
  • Loading branch information
jzonthemtn authored Sep 10, 2024
2 parents 12b8f89 + e86d924 commit f2cb5c7
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void spansJson() {

final String[] window = new String[]{};

final Span span1 = Span.make(1, 6, FilterType.PERSON, "context", "document", 1.0, "test", "***", "", false, window);
final Span span2 = Span.make(8, 12, FilterType.PERSON, "context", "document", 1.0, "test", "***", "", false, window);
final Span span3 = Span.make(14, 20, FilterType.PERSON, "context", "document", 1.0, "test", "***", "", false, window);
final Span span1 = Span.make(1, 6, FilterType.PERSON, "context", "document", 1.0, "test", "***", "", false, true, window);
final Span span2 = Span.make(8, 12, FilterType.PERSON, "context", "document", 1.0, "test", "***", "", false, true, window);
final Span span3 = Span.make(14, 20, FilterType.PERSON, "context", "document", 1.0, "test", "***", "", false, true, window);

final List<Span> spans = Arrays.asList(span1, span2, span3);

Expand Down
29 changes: 29 additions & 0 deletions philter-configuration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>philter</artifactId>
<groupId>ai.philterd</groupId>
<version>2.6.0-SNAPSHOT</version>
</parent>
<artifactId>philter-configuration</artifactId>
<name>philter-configuration</name>
<dependencies>
<dependency>
<groupId>ai.philterd</groupId>
<artifactId>phileas-model</artifactId>
<version>${phileas.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package ai.philterd.philter;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;

public class PhilterConfiguration {

private final Properties properties;
private final String applicationName;

public PhilterConfiguration(String propertyFileName, String applicationName) throws IOException {
FileReader fileReader = new FileReader(propertyFileName);
this.properties = new Properties();
this.properties.load(fileReader);
this.applicationName = applicationName;
}

public PhilterConfiguration(Properties properties, String applicationName) throws IOException {
this.properties = properties;
this.applicationName = applicationName;
}

// Metrics

public String metricsPrefix() {
return getProperty("metrics.prefix", applicationName);
}

// See: https://github.com/micrometer-metrics/micrometer/blob/master/implementations/micrometer-registry-prometheus/src/main/java/io/micrometer/prometheus/PrometheusConfig.java
// The step size to use in computing windowed statistics like max. The default is 1 minute.
// To get the most out of these statistics, align the step interval to be close to your scrape interval.
public int metricsStep() {
return Integer.parseInt(getProperty("metrics.step", "60"));
}

public boolean metricsJmxEnabled() {
return Boolean.parseBoolean(getProperty("metrics.jmx.enabled", "false"));
}

public boolean metricsPrometheusEnabled() {
return Boolean.parseBoolean(getProperty("metrics.prometheus.enabled", "false"));
}

public int metricsPrometheusPort() {
return Integer.parseInt(getProperty("metrics.prometheus.port", "9100"));
}

public String metricsPrometheusContext() {
return getProperty("metrics.prometheus.context", "metrics");
}

public boolean metricsDataDogEnabled() {
return Boolean.parseBoolean(getProperty("metrics.datadog.enabled", "false"));
}

public String metricsDataDogApiKey() {
return getProperty("metrics.datadog.apikey", "metrics");
}

public boolean metricsCloudWatchEnabled() {
return Boolean.parseBoolean(getProperty("metrics.cloudwatch.enabled", "false"));
}

public String metricsCloudWatchRegion() {
return String.valueOf(getProperty("metrics.cloudwatch.region", "us-east-1"));
}

public String metricsCloudWatchNamespace() {
return String.valueOf(getProperty("metrics.cloudwatch.namespace", applicationName));
}

public String metricsHostname() {
return String.valueOf(getProperty("metrics.hostname", ""));
}

private String getProperty(final String property, final String defaultValue) {

final String environmentVariableValue = getEnvironmentVariable(property);

if(!StringUtils.isEmpty(environmentVariableValue)) {
return environmentVariableValue;
}

final String systemPropertyValue = getSystemProperty(property);

if(!StringUtils.isEmpty(systemPropertyValue)) {
return systemPropertyValue;
}

final String propertyFileValue = getFileProperty(property);

if(!StringUtils.isEmpty(propertyFileValue)) {
return propertyFileValue;
}

return defaultValue;

}

private String getEnvironmentVariable(final String environmentVariable) {
return System.getenv(environmentVariable);
}

private String getSystemProperty(final String property) {
return System.getProperty(property);
}

private String getFileProperty(final String property) {
return properties.getProperty(property);
}

}
49 changes: 49 additions & 0 deletions philter-metrics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>philter</artifactId>
<groupId>ai.philterd</groupId>
<version>2.6.0-SNAPSHOT</version>
</parent>
<artifactId>philter-metrics</artifactId>
<name>philter-metrics</name>
<dependencies>
<dependency>
<groupId>ai.philterd</groupId>
<artifactId>philter-configuration</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${dropwizard-metrics-prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-datadog</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-cloudwatch</artifactId>
<version>${dropwizard-metrics-cloudwatch.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit f2cb5c7

Please sign in to comment.