Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
package io.opentelemetry.ibm.mq.config;

import io.opentelemetry.ibm.mq.metricscollector.FilterType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/** A jackson databind class used for config. */
public final class ExcludeFilters {

private String type = "UNKNOWN";
private Set<String> values = new HashSet<>();
private List<String> values = new ArrayList<>();

public String getType() {
return type;
Expand All @@ -25,12 +26,12 @@ public void setType(String type) {
this.type = type;
}

public Set<String> getValues() {
return Collections.unmodifiableSet(values);
public List<String> getValues() {
return Collections.unmodifiableList(values);
}

public void setValues(Set<String> values) {
this.values = new HashSet<>(values);
this.values = new ArrayList<>(values);
}

public static boolean isExcluded(String resourceName, Collection<ExcludeFilters> excludeFilters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

package io.opentelemetry.ibm.mq.config;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/** Include and exclude filters for IBM MQ resource names. */
public final class ResourceFilters {

private Set<String> include = new HashSet<>();
private Set<ExcludeFilters> exclude = new HashSet<>();
private List<ExcludeFilters> exclude = new ArrayList<>();

public Set<String> getInclude() {
return include;
Expand All @@ -22,11 +24,11 @@ public void setInclude(Set<String> include) {
this.include = include;
}

public Set<ExcludeFilters> getExclude() {
public List<ExcludeFilters> getExclude() {
return exclude;
}

public void setExclude(Set<ExcludeFilters> exclude) {
public void setExclude(List<ExcludeFilters> exclude) {
this.exclude = exclude;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.CMQCFC;
import com.ibm.mq.headers.pcf.PCFMessage;
import io.opentelemetry.ibm.mq.config.ExcludeFilters;
import java.util.Arrays;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -55,6 +56,44 @@ public void accept(MetricsCollectorContext context) {
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);
request.addParameter(CMQC.MQCA_Q_NAME, queueGenericName);
request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_ALL);

// take the first filter, and apply it, as we can only apply one filter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems goofy -- why can we only apply one? The addFilterParameter() method is where the rubber meets the road, and that name suggests you can call it once. Then again, who knows how IBM designed this madness.

Is there a reference somewhere that indicates only one filter?

if (!context.getQueueExcludeFilters().isEmpty()) {
ExcludeFilters filter = context.getQueueExcludeFilters().iterator().next();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since you have changed this to a list and area already checking non-empty, you shouldn't be using an iterator here. You can just do context.getQueueExcludeFilters().get(0).

if ((!filter.getValues().isEmpty())
&& (FilterType.valueOf(filter.getType()) != FilterType.NONE)) {

String value = filter.getValues().get(0);
int op = 0;
switch (FilterType.valueOf(filter.getType())) {
case STARTSWITH:
op = CMQCFC.MQCFOP_NOT_LIKE;
break;
case EQUALS:
op = CMQCFC.MQCFOP_NOT_EQUAL;
break;
case ENDSWITH:
op = CMQCFC.MQCFOP_NOT_LIKE;
if (!value.startsWith("*")) {
value = "*" + value;
}
break;
case CONTAINS:
op = CMQCFC.MQCFOP_NOT_LIKE;
if (!value.startsWith("*")) {
value = "*" + value;
}
if (!value.endsWith("*")) {
value += "*";
}
break;
case NONE:
logger.warn("Invalid type of filter {}", filter.getType());
continue;
}
request.addFilterParameter(CMQC.MQCA_Q_NAME, op, value);
}
}
request.addParameter(CMQCFC.MQIACF_Q_ATTRS, ATTRIBUTES);

queueBuddy.processPcfRequestAndPublishQMetrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import io.opentelemetry.ibm.mq.config.ExcludeFilters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -53,15 +51,15 @@ public List<PCFMessage> filter(List<PCFMessage> messages) throws PCFException {
static class MessageFilterBuilder {

private final String kind;
private Set<ExcludeFilters> filters = new HashSet<>();
private List<ExcludeFilters> filters = new ArrayList<>();

public MessageFilterBuilder(String kind) {
this.kind = kind;
}

@CanIgnoreReturnValue
public MessageFilterBuilder excluding(Set<ExcludeFilters> filters) {
this.filters = new HashSet<>(filters);
public MessageFilterBuilder excluding(List<ExcludeFilters> filters) {
this.filters = new ArrayList<>(filters);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,31 @@ Set<String> getChannelIncludeFilterNames() {
return queueManager.getChannelFilters().getInclude();
}

Set<ExcludeFilters> getChannelExcludeFilters() {
List<ExcludeFilters> getChannelExcludeFilters() {
return queueManager.getChannelFilters().getExclude();
}

Set<String> getListenerIncludeFilterNames() {
return queueManager.getListenerFilters().getInclude();
}

Set<ExcludeFilters> getListenerExcludeFilters() {
List<ExcludeFilters> getListenerExcludeFilters() {
return queueManager.getListenerFilters().getExclude();
}

Set<String> getTopicIncludeFilterNames() {
return queueManager.getTopicFilters().getInclude();
}

Set<ExcludeFilters> getTopicExcludeFilters() {
List<ExcludeFilters> getTopicExcludeFilters() {
return queueManager.getTopicFilters().getExclude();
}

Set<String> getQueueIncludeFilterNames() {
return queueManager.getQueueFilters().getInclude();
}

Set<ExcludeFilters> getQueueExcludeFilters() {
List<ExcludeFilters> getQueueExcludeFilters() {
return queueManager.getQueueFilters().getExclude();
}

Expand Down
Loading