[AB-xxx] fixing not showing assignable role actions in metrics

This commit is contained in:
Sheldan
2021-07-25 15:18:54 +02:00
parent ee7f9180dc
commit 5311cfcc2e
7 changed files with 63 additions and 9 deletions

View File

@@ -97,6 +97,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
.anyMatch(memberRole -> memberRole.getIdLong() == payload.getRoleId()); .anyMatch(memberRole -> memberRole.getIdLong() == payload.getRoleId());
if(!memberHasRole) { if(!memberHasRole) {
if(place.getType().equals(AssignableRolePlaceType.BOOSTER) && member.getTimeBoosted() == null) { if(place.getType().equals(AssignableRolePlaceType.BOOSTER) && member.getTimeBoosted() == null) {
assignableRoleService.assignableRoleConditionFailure();
throw new BoosterAssignableRolePlaceMemberNotBoostingException(); throw new BoosterAssignableRolePlaceMemberNotBoostingException();
} }
AssignableRole assignableRole = assignableRoleOptional.get(); AssignableRole assignableRole = assignableRoleOptional.get();
@@ -106,8 +107,9 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
AssignableRoleConditionResult conditionResult = AssignableRoleConditionResult conditionResult =
assignableRoleConditionServiceBean.evaluateConditions(assignableRole.getConditions(), aUserInAServer, roleById); assignableRoleConditionServiceBean.evaluateConditions(assignableRole.getConditions(), aUserInAServer, roleById);
if(!conditionResult.getFulfilled()) { if(!conditionResult.getFulfilled()) {
log.info("One condition failed to be fullfilled - notifying user."); log.info("One condition failed to be fulfilled - notifying user.");
self.notifyUserAboutConditionFail(model, event.getInteraction(), conditionResult.getModel()); self.notifyUserAboutConditionFail(model, event.getInteraction(), conditionResult.getModel());
assignableRoleService.assignableRoleConditionFailure();
return ButtonClickedListenerResult.ACKNOWLEDGED; return ButtonClickedListenerResult.ACKNOWLEDGED;
} }
} }
@@ -134,7 +136,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
} else { } else {
removalFuture = CompletableFuture.completedFuture(null); removalFuture = CompletableFuture.completedFuture(null);
} }
CompletableFuture<Void> roleAdditionFuture = roleService.addRoleToMemberAsync(member, roleById); CompletableFuture<Void> roleAdditionFuture = assignableRoleService.assignAssignableRoleToUser(roleById, member);
CompletableFuture.allOf(removalFuture, roleAdditionFuture).whenComplete((unused, throwable) -> { CompletableFuture.allOf(removalFuture, roleAdditionFuture).whenComplete((unused, throwable) -> {
if(throwable != null) { if(throwable != null) {
log.error("Failed to either add or remove roles for assignable role place {} in server {}.", payload.getPlaceId(), guild.getIdLong()); log.error("Failed to either add or remove roles for assignable role place {} in server {}.", payload.getPlaceId(), guild.getIdLong());
@@ -149,7 +151,7 @@ public class AssignableRoleButtonClickedListener implements ButtonClickedListene
} }
}); });
} else { } else {
roleService.removeRoleFromUserAsync(member, roleById) assignableRoleService.removeAssignableRoleFromUser(roleById, member)
.thenAccept(unused -> { .thenAccept(unused -> {
self.notifyUser(model, false, roleById, event.getInteraction(), new ArrayList<>()); self.notifyUser(model, false, roleById, event.getInteraction(), new ArrayList<>());
log.info("Removed role {} from member {} in server {} for assignable role interaction {} on component {}.", log.info("Removed role {} from member {} in server {} for assignable role interaction {} on component {}.",

View File

@@ -140,7 +140,7 @@ public class AssignableRolePlaceServiceBean implements AssignableRolePlaceServic
@Transactional @Transactional
public void persistAssignableRoleAddition(Long placeId, Role role, String description, FullEmote fakeEmote, String componentId) { public void persistAssignableRoleAddition(Long placeId, Role role, String description, FullEmote fakeEmote, String componentId) {
AssignableRolePlace place = assignableRolePlaceManagementServiceBean.findByPlaceId(placeId); AssignableRolePlace place = assignableRolePlaceManagementServiceBean.findByPlaceId(placeId);
log.info("Adding role {} to assignable role place {} with component ID {}.", role.getId(), place, componentId); log.info("Adding role {} to assignable role place {} with component ID {}.", role.getId(), place.getId(), componentId);
ComponentPayload payload = persistButtonCallback(place, componentId, role.getIdLong()); ComponentPayload payload = persistButtonCallback(place, componentId, role.getIdLong());
assignableRoleManagementServiceBean.addRoleToPlace(fakeEmote, role, description, place, payload); assignableRoleManagementServiceBean.addRoleToPlace(fakeEmote, role, description, place, payload);
} }

View File

@@ -72,14 +72,36 @@ public class AssignableRoleServiceBean implements AssignableRoleService {
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "removed"))) .tagList(Arrays.asList(MetricTag.getTag(ACTION, "removed")))
.build(); .build();
private static final CounterMetric ASSIGNABLE_ROLES_CONDITION_FAILED =
CounterMetric
.builder()
.name(ASSIGNABLE_ROLES_METRIC)
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "condition")))
.build();
@Override @Override
public CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member) { public CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member) {
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId); AssignableRole role = assignableRoleManagementServiceBean.getByAssignableRoleId(assignableRoleId);
log.info("Assigning role {} to member {} in server {}.", assignableRoleId, member.getId(), member.getGuild().getId()); log.info("Assigning role {} to member {} in server {}.", assignableRoleId, member.getId(), member.getGuild().getId());
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
return roleService.addRoleToMemberAsync(member, role.getRole()); return roleService.addRoleToMemberAsync(member, role.getRole());
} }
@Override
public CompletableFuture<Void> assignAssignableRoleToUser(Role role, Member member) {
return assignRoleToUser(role.getIdLong(), member);
}
@Override
public void assignableRoleConditionFailure() {
metricService.incrementCounter(ASSIGNABLE_ROLES_CONDITION_FAILED);
}
private CompletableFuture<Void> assignRoleToUser(Long roleId, Member member) {
metricService.incrementCounter(ASSIGNABLE_ROLES_ASSIGNED);
return roleService.addRoleToMemberAsync(member, roleId);
}
@Override @Override
public void clearAllRolesOfUserInPlace(AssignableRolePlace place, AUserInAServer userInAServer) { public void clearAllRolesOfUserInPlace(AssignableRolePlace place, AUserInAServer userInAServer) {
Optional<AssignedRoleUser> userOptional = assignedRoleUserManagementServiceBean.findByUserInServerOptional(userInAServer); Optional<AssignedRoleUser> userOptional = assignedRoleUserManagementServiceBean.findByUserInServerOptional(userInAServer);
@@ -103,8 +125,17 @@ public class AssignableRoleServiceBean implements AssignableRoleService {
@Override @Override
public CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member) { public CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member) {
log.info("Removing assignable role {} from user {} in server {}.", assignableRole.getId(), member.getId(), member.getGuild().getId()); log.info("Removing assignable role {} from user {} in server {}.", assignableRole.getId(), member.getId(), member.getGuild().getId());
return removeRoleFromUser(assignableRole.getRole().getId(), member);
}
@Override
public CompletableFuture<Void> removeAssignableRoleFromUser(Role role, Member member) {
return removeRoleFromUser(role.getIdLong(), member);
}
private CompletableFuture<Void> removeRoleFromUser(Long roleId, Member member) {
metricService.incrementCounter(ASSIGNABLE_ROLES_REMOVED); metricService.incrementCounter(ASSIGNABLE_ROLES_REMOVED);
return roleService.removeRoleFromMemberAsync(member, assignableRole.getRole()); return roleService.removeRoleFromMemberAsync(member, roleId);
} }
@Override @Override
@@ -159,5 +190,6 @@ public class AssignableRoleServiceBean implements AssignableRoleService {
public void postConstruct() { public void postConstruct() {
metricService.registerCounter(ASSIGNABLE_ROLES_ASSIGNED, "Assignable roles assigned."); metricService.registerCounter(ASSIGNABLE_ROLES_ASSIGNED, "Assignable roles assigned.");
metricService.registerCounter(ASSIGNABLE_ROLES_REMOVED, "Assignable roles removed."); metricService.registerCounter(ASSIGNABLE_ROLES_REMOVED, "Assignable roles removed.");
metricService.registerCounter(ASSIGNABLE_ROLES_CONDITION_FAILED, "Assignable roles failed to assign because of condition.");
} }
} }

View File

@@ -3,6 +3,11 @@ package dev.sheldan.abstracto.assignableroles.exception;
import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException; import dev.sheldan.abstracto.core.exception.AbstractoTemplatableException;
public class BoosterAssignableRolePlaceMemberNotBoostingException extends AbstractoTemplatableException { public class BoosterAssignableRolePlaceMemberNotBoostingException extends AbstractoTemplatableException {
public BoosterAssignableRolePlaceMemberNotBoostingException() {
super("Clicking member does not boost");
}
@Override @Override
public String getTemplateName() { public String getTemplateName() {
return "assignable_role_booster_place_member_not_boosting_exception"; return "assignable_role_booster_place_member_not_boosting_exception";

View File

@@ -24,6 +24,8 @@ public interface AssignableRoleService {
*/ */
CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member); CompletableFuture<Void> assignAssignableRoleToUser(Long assignableRoleId, Member member);
CompletableFuture<Void> assignAssignableRoleToUser(Role role, Member member);
void assignableRoleConditionFailure();
/** /**
* Clears all {@link AssignableRole assignableRoles} which are currently given to the {@link AUserInAServer user} of a certain * Clears all {@link AssignableRole assignableRoles} which are currently given to the {@link AUserInAServer user} of a certain
@@ -41,6 +43,7 @@ public interface AssignableRoleService {
* has been removed from the {@link Member member} * has been removed from the {@link Member member}
*/ */
CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member); CompletableFuture<Void> removeAssignableRoleFromUser(AssignableRole assignableRole, Member member);
CompletableFuture<Void> removeAssignableRoleFromUser(Role role, Member member);
/** /**
* Removes the {@link AssignableRole role} from the given {@link Member member} * Removes the {@link AssignableRole role} from the given {@link Member member}

View File

@@ -90,8 +90,16 @@ public class CommandReceivedHandler extends ListenerAdapter {
public static final String COMMAND_PROCESSED = "command.processed"; public static final String COMMAND_PROCESSED = "command.processed";
public static final String STATUS_TAG = "status"; public static final String STATUS_TAG = "status";
public static final CounterMetric COMMANDS_PROCESSED_COUNTER = CounterMetric.builder().name(COMMAND_PROCESSED).tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "processed"))).build(); public static final CounterMetric COMMANDS_PROCESSED_COUNTER = CounterMetric
public static final CounterMetric COMMANDS_WRONG_PARAMETER_COUNTER = CounterMetric.builder().name(COMMAND_PROCESSED).tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "parameter.wrong"))).build(); .builder()
.name(COMMAND_PROCESSED)
.tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "processed")))
.build();
public static final CounterMetric COMMANDS_WRONG_PARAMETER_COUNTER = CounterMetric
.builder()
.name(COMMAND_PROCESSED)
.tagList(Arrays.asList(MetricTag.getTag(STATUS_TAG, "parameter.wrong")))
.build();
@Override @Override
@Transactional @Transactional

View File

@@ -53,7 +53,11 @@ public class MessageReceivedListenerBean extends ListenerAdapter {
public static final String MESSAGE_METRIC = "message"; public static final String MESSAGE_METRIC = "message";
public static final String ACTION = "action"; public static final String ACTION = "action";
private static final CounterMetric MESSAGE_RECEIVED_COUNTER = CounterMetric.builder().name(MESSAGE_METRIC).tagList(Arrays.asList(MetricTag.getTag(ACTION, "received"))).build(); private static final CounterMetric MESSAGE_RECEIVED_COUNTER = CounterMetric
.builder()
.name(MESSAGE_METRIC)
.tagList(Arrays.asList(MetricTag.getTag(ACTION, "received")))
.build();
@Override @Override
@Transactional @Transactional