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

:fix: add publish counter for internal messages #4007

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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 @@ -258,6 +258,13 @@
break;
}
} else {
switch (checkType) {
case SEND:
publishMetric.getAllowedMessagesInternal().inc();
break;

Check warning on line 264 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/SecurityPlugin.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/SecurityPlugin.java#L263-L264

Added lines #L263 - L264 were not covered by tests
default:
break;
}
allowed = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,16 @@
logger.info("Published message size over threshold. size: {} - destination: {} - account id: {} - username: {} - clientId: {}",
messageSize, address, sessionContext.getAccountName(), sessionContext.getUsername(), sessionContext.getClientId());
}
publishMetric.getMessageSizeAllowed().update(messageSize);

Check warning on line 245 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ServerPlugin.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ServerPlugin.java#L245

Added line #L245 was not covered by tests
} else {
if (publishInfoMessageSizeLimit < messageSize) {
logger.info("Published message size over threshold. size: {} - destination: {}",
messageSize, address);
}
message.putBooleanProperty(MessageConstants.HEADER_KAPUA_BROKER_CONTEXT, true);
publishMetric.getMessageSizeAllowedInternal().update(messageSize);

Check warning on line 252 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ServerPlugin.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/ServerPlugin.java#L252

Added line #L252 was not covered by tests
}
message.putStringProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC, address);
publishMetric.getMessageSizeAllowed().update(messageSize);
serverContext.getAddressAccessTracker().update(address);
logger.debug("Published message on address {} from clientId: {} - clientIp: {}", address, sessionContext.getClientId(), sessionContext.getClientIp());
ActiveMQServerPlugin.super.beforeSend(session, tx, message, direct, noAutoCreateQueue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,33 @@
public static final String PUBLISH = "publish";

public static final String ALLOWED = "allowed";
public static final String INTERNAL = "internal";
public static final String NOT_ALLOWED = "not_allowed";

private final Counter allowedMessages;
private final Counter allowedMessagesInternal;
private final Counter notAllowedMessages;
private final Timer time;
// message size
private final Histogram messageSizeAllowed;
private final Histogram messageSizeAllowedInternal;

@Inject
private PublishMetric(MetricsService metricsService,
@Named("metricModuleName")
String metricModuleName) {
// publish/subscribe
allowedMessages = metricsService.getCounter(metricModuleName, PUBLISH, ALLOWED);
allowedMessagesInternal = metricsService.getCounter(metricModuleName, PUBLISH, INTERNAL, ALLOWED);

Check warning on line 48 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java#L48

Added line #L48 was not covered by tests
notAllowedMessages = metricsService.getCounter(metricModuleName, PUBLISH, NOT_ALLOWED);
time = metricsService.getTimer(metricModuleName, PUBLISH, MetricsLabel.TIME, MetricsLabel.SECONDS);
// message size
messageSizeAllowed = metricsService.getHistogram(metricModuleName, PUBLISH, ALLOWED, MetricsLabel.SIZE, MetricsLabel.BYTES);
messageSizeAllowedInternal = metricsService.getHistogram(metricModuleName, PUBLISH, INTERNAL, ALLOWED, MetricsLabel.SIZE, MetricsLabel.BYTES);
}

Check warning on line 54 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java#L53-L54

Added lines #L53 - L54 were not covered by tests

public Counter getAllowedMessagesInternal() {
return allowedMessagesInternal;

Check warning on line 57 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java#L57

Added line #L57 was not covered by tests
}

public Counter getAllowedMessages() {
Expand All @@ -60,8 +69,11 @@
return time;
}

public Histogram getMessageSizeAllowedInternal() {
return messageSizeAllowedInternal;

Check warning on line 73 in broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java

View check run for this annotation

Codecov / codecov/patch

broker/artemis/plugin/src/main/java/org/eclipse/kapua/broker/artemis/plugin/security/metric/PublishMetric.java#L73

Added line #L73 was not covered by tests
}

public Histogram getMessageSizeAllowed() {
return messageSizeAllowed;
}

}
Loading