Skip to content

Commit

Permalink
Checkpoint (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwexler authored Jan 21, 2025
1 parent 3411036 commit eb09d62
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## 28.0-SNAPSHOT - unreleased

### 💥 Breaking Changes (upgrade difficulty: 🟢 LOW - requires Java 17 for Hazelcast)
### 💥 Breaking Changes (upgrade difficulty: 🟢 LOW - requires Java 17 and Hoist React 72.x)

### 🎁 New Features
* Added support for conditional persisting of activity tracking messages based on `TrackSeverity`.
By default all messages continue to have severity `INFO`, which is the default active level.
Make tracking more or less verbose by adding an entry to the new `levels` property in
`TrackService.xhActivityTrackingConfig`. See TrackService for more info.

### 🐞 Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion grails-app/init/io/xh/hoist/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class BootStrap implements LogSupport {
enabled: true,
logData: false,
maxDataLength: 2000,
maxRows: [default: 10000, limit: 25000, options: [1000, 5000, 10000, 25000]]
maxRows: [default: 10000, limit: 25000, options: [1000, 5000, 10000, 25000]],
levels: [[user: '*', category: '*', severity: 'INFO']]
],
clientVisible: true,
groupName: 'xh.io',
Expand Down
47 changes: 43 additions & 4 deletions grails-app/services/io/xh/hoist/track/TrackService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.xh.hoist.util.Utils
import static io.xh.hoist.browser.Utils.getBrowser
import static io.xh.hoist.browser.Utils.getDevice
import static io.xh.hoist.json.JSONSerializer.serialize
import static io.xh.hoist.track.TrackSeverity.INFO
import static io.xh.hoist.util.InstanceConfigUtils.getInstanceConfig
import static grails.async.Promises.task
import static io.xh.hoist.util.Utils.getCurrentRequest
Expand All @@ -31,7 +32,19 @@ import static java.lang.System.currentTimeMillis
* involve logging queries and tracking if / how often a given feature is actually used.
*
* The `xhActivityTrackingConfig` soft-config can be used to configure this service, including
* disabling it completely. Separately, the `disableTrackLog` *instance* config can be used to
* disabling it completely. Use the 'levels' property in this config to set the minimal severity for
* persisting any particular message. Entries in this list will be of the following form, where
* the first matching entry for a message will determine the currently active severity to persist:
* levels: [
* [
* username: ['*' or comma-delimited list of usernames],
* category: ['*' or comma-delimited list of categories],
* severity: 'DEBUG'|'INFO'|'WARN'
* ],
* ...
* ]
*
* Separately, the `disableTrackLog` *instance* config can be used to
* disable only the *persistence* of new track logs while leaving logging and the admin client UI
* active / accessible (intended for local development environments).
*/
Expand Down Expand Up @@ -66,7 +79,8 @@ class TrackService extends BaseService {
* impersonating {String} - optional, defaults to username if impersonating, null if not.
* Use this if track will be called in an asynchronous process,
* outside of a request, where impersonator info not otherwise available.
* severity {String} - optional, defaults to 'INFO'.
* severity
* {String|TrackSeverity} - optional, defaults to TrackSeverity.INFO.
* url {String} - optional, url associated with statement
* timestamp {long} - optional, time associated with start of action. Defaults to current time.
* elapsed {int} - optional, duration of action in millis
Expand Down Expand Up @@ -131,7 +145,7 @@ class TrackService extends BaseService {
correlationId : entry.correlationId,
msg : entry.msg,
elapsed : entry.elapsed,
severity : entry.severity ?: 'INFO',
severity : parseSeverity(entry.severity),
data : entry.data ? serialize(entry.data) : null,
rawData : entry.data,
url : entry.url,
Expand Down Expand Up @@ -184,7 +198,9 @@ class TrackService extends BaseService {
}

private void persistEntry(Map entry) {
if (getInstanceConfig('disableTrackLog') == 'true') return
if (getInstanceConfig('disableTrackLog') == 'true' ||
getActiveSeverity(entry) > parseSeverity(entry.severity)
) return

String data = entry.data
if (data?.size() > (conf.maxDataLength as Integer)) {
Expand All @@ -201,6 +217,29 @@ class TrackService extends BaseService {
tl.save()
}

private TrackSeverity getActiveSeverity(Map entry) {
def username = entry.username as String,
cat = entry.category as String,
levels = (conf.levels ?: []) as List<Map>

def match = levels.find {
def levUser = it.username as String,
levCat = it.category as String

(levUser == '*' || levUser.contains(username)) && (levCat == '*' || levCat.contains(cat))
}
return match ? parseSeverity(match.severity) : INFO
}

private TrackSeverity parseSeverity(Object severity) {
if (severity instanceof TrackSeverity) return severity
if (!severity) return INFO
try {
return TrackSeverity.valueOf(severity.toString().toUpperCase().trim())
} catch (IllegalArgumentException ex) {
return INFO
}
}

Map getAdminStats() {[
config: configForAdminStats('xhActivityTrackingConfig')
Expand Down
12 changes: 12 additions & 0 deletions src/main/groovy/io/xh/hoist/track/TrackSeverity.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.xh.hoist.track

/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* Copyright © 2025 Extremely Heavy Industries Inc.
*/

enum TrackSeverity {
DEBUG, INFO, WARN
}

0 comments on commit eb09d62

Please sign in to comment.