Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow suppressing all metrics #2490

Merged
merged 3 commits into from
Sep 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,14 +72,6 @@ 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;
}
}
}
return false;
return metricFilters.stream().anyMatch(metricFilter -> metricFilter.exclude(metricName));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed that this method is called from a loop in the AgentMetricExporter class. If the number of iterations could be high, I would prefer to avoid creating a stream at each iteration, to limit heap allocation.

}
}