Skip to content

Commit

Permalink
Allow suppressing all metrics (#2490)
Browse files Browse the repository at this point in the history
* Allow suppressing all metrics

* Remove stream
  • Loading branch information
trask authored and heyams committed Sep 16, 2022
1 parent f073ce0 commit 4d10e1a
Showing 1 changed file with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

package com.microsoft.applicationinsights.agent.internal.telemetry;

import static java.util.Arrays.asList;

import com.microsoft.applicationinsights.agent.internal.configuration.Configuration;
import com.microsoft.applicationinsights.agent.internal.perfcounter.MetricNames;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -16,16 +13,6 @@

public class MetricFilter {

private static final Set<String> NON_FILTERABLE_METRIC_NAMES =
new HashSet<>(
asList(
MetricNames.TOTAL_CPU_PERCENTAGE,
MetricNames.PROCESS_CPU_PERCENTAGE,
MetricNames.PROCESS_CPU_PERCENTAGE_NORMALIZED,
MetricNames.PROCESS_MEMORY,
MetricNames.TOTAL_MEMORY,
MetricNames.PROCESS_IO));

// OpenTelemetry Collector also supports include
// but we aren't adding this support, at least not yet, since it implicitly excludes everything
// else
Expand All @@ -38,8 +25,8 @@ public MetricFilter(Configuration.ProcessorConfig metricFilterConfiguration) {
this.exclude = new IncludeExclude(metricFilterConfiguration.exclude);
}

boolean matches(String metricName) {
return !exclude.matches(metricName);
boolean exclude(String metricName) {
return exclude.matches(metricName);
}

public static class IncludeExclude {
Expand Down Expand Up @@ -85,12 +72,9 @@ boolean matches(String metricName) {
}

public static boolean shouldSkip(String metricName, List<MetricFilter> metricFilters) {
if (!MetricFilter.NON_FILTERABLE_METRIC_NAMES.contains(metricName)) {
for (MetricFilter metricFilter : metricFilters) {
if (!metricFilter.matches(metricName)) {
// user configuration filtered out this metric name
return true;
}
for (MetricFilter metricFilter : metricFilters) {
if (metricFilter.exclude(metricName)) {
return true;
}
}
return false;
Expand Down

0 comments on commit 4d10e1a

Please sign in to comment.