Skip to content

Commit

Permalink
chore(oxauth): added more logs to stat service
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyz committed Jul 25, 2024
1 parent ef56593 commit 0792f37
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Server/src/main/java/org/gluu/oxauth/service/stat/StatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public boolean init() {

final Date now = new Date();
prepareMonthlyBranch(now);
log.trace("Monthly branch created: " + monthlyDn);
log.info("Monthly branch created: {}", monthlyDn);

setupCurrentEntry(now);
log.info("Initialized Stat Service");
initialized = true;
log.info("Initialized Stat Service");
return true;
} catch (Exception e) {
log.error("Failed to initialize Stat Service.", e);
Expand All @@ -89,6 +89,8 @@ public boolean init() {
}

public void updateStat() {
log.trace("updateStat ... (initialized: {})", initialized);

if (!initialized) {
return;
}
Expand All @@ -107,6 +109,8 @@ public void updateStat() {
synchronized (hll) {
currentEntry.setUserHllData(Base64.getEncoder().encodeToString(hll.toBytes()));
}

log.trace("Updating entry dn {}", currentEntry.getDn());
entryManager.merge(currentEntry);

log.trace("Finished updateStat.");
Expand All @@ -119,6 +123,7 @@ private void setupCurrentEntry() {
private void setupCurrentEntry(Date now) {
final String month = PERIOD_DATE_FORMAT.format(now);
String dn = String.format("jansId=%s,%s", nodeId, monthlyDn); // jansId=<id>,ou=yyyyMM,ou=stat,o=gluu
log.trace("Stat entry dn: {}", dn);

if (currentEntry != null && month.equals(currentEntry.getStat().getMonth())) {
return;
Expand All @@ -130,13 +135,17 @@ private void setupCurrentEntry(Date now) {
hll = HLL.fromBytes(Base64.getDecoder().decode(entryFromPersistence.getUserHllData()));
tokenCounters = new ConcurrentHashMap<>(entryFromPersistence.getStat().getTokenCountPerGrantType());
currentEntry = entryFromPersistence;
log.trace("Stat entry loaded.");
log.trace("Stat entry {} loaded.", dn);
return;
} else {
log.trace("Month does not match. Current month {}, entry month {}, entry dn: {}", month, entryFromPersistence != null ? entryFromPersistence.getStat().getMonth() : "", dn);
}
} catch (EntryPersistenceException e) {
log.trace("Stat entry is not found in persistence.");
log.trace("Stat entry is not found in persistence. dn: " + dn, e);
}

log.trace("Current entry before nullity check, dn {}", currentEntry != null ? currentEntry.getDn() : "null");

if (currentEntry == null) {
log.trace("Creating stat entry ...");
hll = newHll();
Expand All @@ -150,6 +159,8 @@ private void setupCurrentEntry(Date now) {
entryManager.persist(currentEntry);
log.trace("Created stat entry. nodeId:" + nodeId);
}

log.trace("Current entry dn {}", currentEntry != null ? currentEntry.getDn() : "null");
}

public HLL newHll() {
Expand All @@ -162,7 +173,7 @@ private void initNodeId() {
}

try {
nodeId = InetAddressUtility.getMACAddressOrNull();
nodeId = InetAddressUtility.getMACAddressOrNull() + "_" + monthString();
if (StringUtils.isNotBlank(nodeId)) {
log.trace("NodeId created: " + nodeId);
return;
Expand All @@ -173,9 +184,14 @@ private void initNodeId() {
} catch (Exception e) {
log.error("Failed to identify nodeId.", e);
nodeId = UUID.randomUUID().toString();
log.trace("NodeId created: " + nodeId);
}
}

public String monthString() {
return PERIOD_DATE_FORMAT.format(new Date()); // yyyyMM
}

public String getNodeId() {
return nodeId;
}
Expand Down

0 comments on commit 0792f37

Please sign in to comment.