-
Notifications
You must be signed in to change notification settings - Fork 7
Allow admins to fetch misuse stats summaries for a given user #506
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
Conversation
And allow admins to reset misuse event counters even if the event isn't yet "misused"
Codecov ReportBase: 25.75% // Head: 26.80% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #506 +/- ##
==========================================
+ Coverage 25.75% 26.80% +1.04%
==========================================
Files 481 482 +1
Lines 21932 21973 +41
Branches 2723 2722 -1
==========================================
+ Hits 5649 5889 +240
+ Misses 15791 15564 -227
- Partials 492 520 +28
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@Produces(MediaType.APPLICATION_JSON) | ||
@Operation(summary = "Reset a misuse monitor counter to zero.") | ||
public Response resetMisuseMonitor(@Context final HttpServletRequest request, | ||
@PathParam("event_label") final String eventLabel, | ||
final String agentIdentifier) { | ||
@PathParam("agent_identifier") final String agentIdentifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these agent identifiers are not URL-safe values and probably shouldn't be path parameters, since they could reasonably contain slashes. I suppose they could be query parameters, and URL-encoded.
This feels no less hacky than the previous plain-text-body-as-identifier. Really a Map<String, String> detailsObject
as the body is the right way to do it, and then detailsObject.get("agentIdentifier")
. Then it can @Consumes(MediaType.APPLICATION_JSON)
like it ought to!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure what the agent identifier was, so assumed user id - I've taken a look at everywhere that uses notifyEvent
and can see that there is a fair spread of things now so yeah I'll fix that.
eventLabel, agentIdentifier)); | ||
return Response.ok(ImmutableMap.of("status", "Reset successfully!")).build(); | ||
} else { | ||
return Response.ok(ImmutableMap.of("status", "Nothing to reset.")).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Knowing whether it reset something is really very useful. Was this removed for any reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed because I removed the misuseMonitor.hasMisused(...)
condition, since it makes sense for admins to be able to reset the misuse count at any point, not just after is becomes misused. Because of this, the only response would be "Reset successfully!" which IMO is just as good as a 200.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I need to know I have actually reset the thing I was intending to reset? If I can't find it in the new UI, I need to know that I have got the right (encoding of the) agent identifier and without this there's no way an admin can tell any longer!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it's nice to be able to reset it before it crosses the threshold, though. Maybe it's fine like this. I certainly don't want any more time spent on this.
|
||
|
||
@Override | ||
public List<MisuseStatisticDTO> getMisuseStatistics(final String agentIdentifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above, I am unsure this is that useful given how varied the agent identifiers are.
By returning a sensible placeholder. This previously crashed the client-side admin tools page
@@ -90,7 +91,7 @@ public InfoFacade(final PropertiesLoader properties, final GitContentManager con | |||
@Operation(summary = "Get the currently running API build version.") | |||
public final Response getSegueAppVersion() { | |||
ImmutableMap<String, String> result = new ImmutableMap.Builder<String, String>().put("segueVersion", | |||
SegueGuiceConfigurationModule.getSegueVersion()).build(); | |||
Objects.requireNonNullElse(SegueGuiceConfigurationModule.getSegueVersion(), "unknown")).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this doing here? It's not at all related to the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On adding the misuse UI to admin tools, it kept crashing because this endpoint would always return 500. I decided to add this as it seems sensible and allowed me to actually use admin tools on a local dev build. I understand that it is a bit out of place, but I don't think it should be removed?
|
||
|
||
@Override | ||
public Map<String, List<MisuseStatisticDTO>> getMisuseStatistics(final long n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should really take an @Nullable final Long n
and here is the place for the default value to live. But it's not worth changing now.
And allow admins to reset misuse event counters even if the event isn't yet "misused"
Pull Request Check List