From 0792f37c0d7a65b8fd3bbff88d19faf8f379f2e9 Mon Sep 17 00:00:00 2001 From: YuriyZ Date: Thu, 25 Jul 2024 13:53:01 +0300 Subject: [PATCH] chore(oxauth): added more logs to stat service --- .../gluu/oxauth/service/stat/StatService.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/org/gluu/oxauth/service/stat/StatService.java b/Server/src/main/java/org/gluu/oxauth/service/stat/StatService.java index 5da75465af..4649e37441 100644 --- a/Server/src/main/java/org/gluu/oxauth/service/stat/StatService.java +++ b/Server/src/main/java/org/gluu/oxauth/service/stat/StatService.java @@ -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); @@ -89,6 +89,8 @@ public boolean init() { } public void updateStat() { + log.trace("updateStat ... (initialized: {})", initialized); + if (!initialized) { return; } @@ -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."); @@ -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=,ou=yyyyMM,ou=stat,o=gluu + log.trace("Stat entry dn: {}", dn); if (currentEntry != null && month.equals(currentEntry.getStat().getMonth())) { return; @@ -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(); @@ -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() { @@ -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; @@ -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; }