Skip to content

Commit

Permalink
#122 Removing metrics service.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Aug 25, 2024
1 parent c2d32c0 commit 4941362
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 396 deletions.
5 changes: 0 additions & 5 deletions phileas-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<artifactId>phileas-processors-images</artifactId>
<version>${project.version}</version>
</dependency>-->
<dependency>
<groupId>ai.philterd</groupId>
<artifactId>phileas-services-metrics</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ai.philterd</groupId>
<artifactId>phileas-services-disambiguation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package ai.philterd.phileas.services;

import ai.philterd.phileas.metrics.PhileasMetricsService;
import ai.philterd.phileas.model.configuration.PhileasConfiguration;
import ai.philterd.phileas.model.domain.Domain;
import ai.philterd.phileas.model.domain.HealthDomain;
Expand All @@ -38,6 +37,7 @@
import ai.philterd.phileas.services.alerts.AlertServiceFactory;
import ai.philterd.phileas.services.anonymization.cache.AnonymizationCacheServiceFactory;
import ai.philterd.phileas.services.disambiguation.VectorBasedSpanDisambiguationService;
import ai.philterd.phileas.services.metrics.LoggingMetricsService;
import ai.philterd.phileas.services.policies.LocalPolicyService;
import ai.philterd.phileas.services.policies.S3PolicyService;
import ai.philterd.phileas.services.policies.utils.PolicyUtils;
Expand Down Expand Up @@ -76,6 +76,10 @@ public class PhileasFilterService implements FilterService {
//private final ImageProcessor imageProcessor;

public PhileasFilterService(final PhileasConfiguration phileasConfiguration) throws IOException {
this(phileasConfiguration, new LoggingMetricsService());
}

public PhileasFilterService(final PhileasConfiguration phileasConfiguration, final MetricsService metricsService) throws IOException {

LOGGER.info("Initializing Phileas engine.");

Expand All @@ -86,9 +90,6 @@ public PhileasFilterService(final PhileasConfiguration phileasConfiguration) thr
gsonBuilder.registerTypeAdapter(String.class, new PlaceholderDeserializer());
final Gson gson = gsonBuilder.create();

// Configure metrics.
MetricsService metricsService = new PhileasMetricsService(phileasConfiguration);

// Set the policy services.
this.policyService = buildPolicyService(phileasConfiguration);
this.policyUtils = new PolicyUtils(policyService, gson);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ai.philterd.phileas.services.metrics;

import ai.philterd.phileas.model.enums.FilterType;
import ai.philterd.phileas.model.filter.Filter;
import ai.philterd.phileas.model.services.MetricsService;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class LoggingMetricsService implements MetricsService {

private static final Logger LOGGER = LogManager.getLogger(LoggingMetricsService.class);

long processed = 0;
private final Map<FilterType, Long> filterTypes = new HashMap<>();
private final Map<FilterType, DescriptiveStatistics> filterTimes = new HashMap<>();

@Override
public void incrementProcessed() {
incrementProcessed(1);
}

@Override
public void incrementProcessed(long count) {
processed += count;
LOGGER.debug("Documents processed: {}", processed);
}

@Override
public void incrementFilterType(FilterType filterType) {
if(filterTypes.containsKey(filterType)) {
filterTypes.put(filterType, filterTypes.get(filterType) + 1);
} else {
filterTypes.put(filterType, 1L);
}
LOGGER.debug("Filter type: {}, Count: {}", filterType, filterTypes.get(filterType));
}

@Override
public void logFilterTime(FilterType filterType, long timeMs) {
if(filterTimes.containsKey(filterType)) {
filterTimes.get(filterType).addValue(timeMs);
} else {
final DescriptiveStatistics stats = new DescriptiveStatistics();
stats.addValue(timeMs);
filterTimes.put(filterType, stats);
}
LOGGER.debug("Filter type: {}, Average Time: {} ms", filterType, filterTimes.get(filterType).getMean());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,59 +145,6 @@ public String policiesS3Region() {
return getProperty("filter.policies.s3.region", "us-east-1");
}

// 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);
Expand Down
49 changes: 0 additions & 49 deletions phileas-services/phileas-services-metrics/pom.xml

This file was deleted.

Loading

0 comments on commit 4941362

Please sign in to comment.