<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>I didn't read whole thread on this: Having a JPA event store
would be bad performance? Isn't there more than one even per
login? That means multiple DB inserts per login just to gather
stats. Stats that would be looked at rarely (once a day? once a
week? once a month?) Just something to think about.<br>
</p>
<br>
<div class="moz-cite-prefix">On 5/29/16 4:52 PM, Thomas Darimont
wrote:<br>
</div>
<blockquote
cite="mid:CAK-7U1jeqDDaRRtfp_PpEpGveW0ntNm3FSFbdckZ3YeQFuhdZg@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>Hello group,</div>
<div><br>
</div>
<div>a few months ago I raised the feature request "Activity
dashboard" in the Keycloak JIRA.</div>
<div><a moz-do-not-send="true"
href="https://issues.jboss.org/browse/KEYCLOAK-1840">https://issues.jboss.org/browse/KEYCLOAK-1840</a></div>
<div><br>
</div>
<div>This weekend I gave this a spin and I think I got pretty
far with it,</div>
<div>see attached annotated screenshot.</div>
<div><br>
</div>
<div>The idea was to leverage the information from the stored
event data</div>
<div>to compute some Keycloak usage statistics over time.</div>
<div>My current prototype supports JPA (user / event) storage
provider</div>
<div>and works with postgresql but could be adapted to other
databases including MongoDB.</div>
<div><br>
</div>
<div>Since I need to compute the usage statistics based on the
event data,</div>
<div>events need to be stored and some views (3) need to be
defined to</div>
<div>make the data accessible from JPA in a generic fashion.</div>
<div><br>
</div>
<div>Since the queries are quite complex I wanted to keep them
out</div>
<div>of the code and therefore used named native queries via
orm.xml.</div>
<div>The actual queries use some database specific date/time
functions</div>
<div>that I wanted to keep out of the code - thus I created
views </div>
<div>that could be adapted for each database and provisioned via
liquibase.</div>
<div><br>
</div>
<div>The view definitions can be found here:</div>
<div><a moz-do-not-send="true"
href="https://gist.github.com/thomasdarimont/24e11be101c6ed8773f22e1defc5d66e">https://gist.github.com/thomasdarimont/24e11be101c6ed8773f22e1defc5d66e</a></div>
<div><br>
</div>
<div>For MongoDB one could define appropriate aggregation
framework pipelines</div>
<div>to express the same query logic.</div>
<div><br>
</div>
<div>I basically exposed the data from those views per realm via
a newly </div>
<div>introduced AnalyticsProvider interface that is accessible
via KeycloakSession.</div>
<div><br>
</div>
<div>Data from this AnalyticsProvider is then exposed as a REST
resource called "DashboardResource".</div>
<div>Data from this REST endpoint is then consumed by the admin
frontend in a new section</div>
<div>called "dashboard".</div>
<div><br>
</div>
<div>In the frontend I used basic patternfly components, e.g.:
cards & tables:</div>
<div><a moz-do-not-send="true"
href="https://rawgit.com/patternfly/patternfly/master/tests/cards.html">https://rawgit.com/patternfly/patternfly/master/tests/cards.html</a></div>
<div><br>
</div>
<div>For the heatmap I used <a moz-do-not-send="true"
href="http://cal-heatmap.com/#start">http://cal-heatmap.com/#start</a>
which is based on d3js.</div>
<div>There is also an angularjs directive that could be used as
well.</div>
<div><a moz-do-not-send="true"
href="https://github.com/shekhargulati/angular-cal-heatmap-directive">https://github.com/shekhargulati/angular-cal-heatmap-directive</a></div>
<div><br>
</div>
<div>The current hacky code can be found here.:</div>
<div><a moz-do-not-send="true"
href="https://github.com/thomasdarimont/keycloak/commits/poc/KEYCLOAK-1840-dashboard">https://github.com/thomasdarimont/keycloak/commits/poc/KEYCLOAK-1840-dashboard</a></div>
<div><br>
</div>
<div>The relevant commit is:</div>
<div><a moz-do-not-send="true"
href="https://github.com/thomasdarimont/keycloak/commit/40a7956f8e547edc148d2ddbaf27961f2a852203">https://github.com/thomasdarimont/keycloak/commit/40a7956f8e547edc148d2ddbaf27961f2a852203</a></div>
<div><br>
</div>
<div>The code still needs a decent amount of polishing but I
wanted to share this with</div>
<div>you guys first to see if this could make it into Keycloak
at some point.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Thomas</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
keycloak-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-dev">https://lists.jboss.org/mailman/listinfo/keycloak-dev</a></pre>
</blockquote>
<br>
</body>
</html>