Github user unsleepy22 commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1324#discussion_r60715825
  
    --- Diff: 
storm-core/src/jvm/org/apache/storm/metric/filter/FilterByMetricName.java ---
    @@ -0,0 +1,93 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.storm.metric.filter;
    +
    +import com.google.common.base.Function;
    +import com.google.common.collect.Iterators;
    +import com.google.common.collect.Lists;
    +import org.apache.storm.metric.api.IMetricsConsumer;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.regex.Pattern;
    +
    +public class FilterByMetricName implements MetricsFilter {
    +
    +    private List<Pattern> whitelistPattern;
    +    private List<Pattern> blacklistPattern;
    +    private boolean noneSpecified = false;
    +
    +    public FilterByMetricName(List<String> whitelistPattern, List<String> 
blacklistPattern) {
    +        // guard NPE
    +        if (whitelistPattern == null) {
    +            this.whitelistPattern = Collections.emptyList();
    +        } else {
    +            this.whitelistPattern = 
convertPatternStringsToPatternInstances(whitelistPattern);
    +        }
    +
    +        // guard NPE
    +        if (blacklistPattern == null) {
    +            this.blacklistPattern = Collections.emptyList();
    +        } else {
    +            this.blacklistPattern = 
convertPatternStringsToPatternInstances(blacklistPattern);
    +        }
    +
    +        if (this.whitelistPattern.isEmpty() && 
this.blacklistPattern.isEmpty()) {
    +            noneSpecified = true;
    +        } else if (!this.whitelistPattern.isEmpty() && 
!this.blacklistPattern.isEmpty()) {
    +            throw new IllegalArgumentException("You have to specify either 
includes or excludes, or none.");
    +        }
    +    }
    +
    +    private ArrayList<Pattern> 
convertPatternStringsToPatternInstances(List<String> patterns) {
    +        return Lists.newArrayList(Iterators.transform(patterns.iterator(), 
new Function<String, Pattern>() {
    +            @Override
    +            public Pattern apply(String s) {
    +                return Pattern.compile(s);
    +            }
    +        }));
    +    }
    +
    +    @Override
    +    public boolean apply(IMetricsConsumer.DataPoint dataPoint) {
    +        if (noneSpecified) {
    +            return true;
    +        }
    +
    +        String metricName = dataPoint.name;
    +
    +        if (!whitelistPattern.isEmpty()) {
    --- End diff --
    
    My concern about pattern match is, regular expression matching is pretty 
CPU-intensive, if possible, I would prefer a simple "String.contains" match, 
which may be much faster and less CPU-intensive.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to