Compare commits

..
Author SHA1 Message Date
Darin Kelkhoff 0e556e09e4 chore: update version (0.1.3-SNAPSHOT) and otherwise make work
also:
- downgrade qbit-build-parent - 1.4.0 doesn't seem to exist
- update qqq to build for this feature dev
- add sonatype repo for qqq snapshots
- remove rdbms (not used in here)
2025-11-04 16:57:39 -06:00
Darin Kelkhoff 5a44c5d1a8 test: Add some tests (ya, this qbit had none...) 2025-11-04 16:56:08 -06:00
Darin Kelkhoff 6d283a2ca4 refactor: update this qbit config and producer to follow current interfaces from qqq
also add config for includeBackendActivityStats
2025-11-04 16:55:44 -06:00
Darin Kelkhoff 77d8d90ebb feat(backendActivities): Update standard process traces to optionally also store backend activity stats
That is: number of queries, inserts, etc, per table, used within a process.

This feature does depend on the application server having the QueryStatManager started, and adding this package's StandardProcessTraceQueryStatConsumer to QueryStatManager's queryStatConsumers list, and this qbit being configured with includeBackendActivityStats = true
2025-11-04 16:55:07 -06:00
CircleCI 212fc98365 Bump version to 0.1.2 [skip ci] 2025-09-29 20:33:46 +00:00
james.maes 77328af459 ci(circleci): updated to latest production qqq orb - 0.3.8 2025-09-29 15:32:50 -05:00
james.maes 6dc7c12613 build(pom): updated snapshot version to 0.2.0 - looks like an admin error skipping 2025-09-29 08:44:18 -05:00
james.maes d29af04c03 chore(deps): Updated parent pom and qqq-orb to latest published versions 2025-09-18 12:14:29 -05:00
james.maes c50afb87ab chore: bump snapshot version after release 2025-09-16 16:35:33 -05:00
james.maes f9aef2f395 Merge of release 0.1.1 2025-09-16 16:30:59 -05:00
CircleCI 8e4df57800 Bump version to 0.1.0-RC.1 [skip ci] 2025-09-16 21:21:59 +00:00
james.maes e1df9c6b31 Merge of feature circleci branch 2025-09-16 16:20:15 -05:00
james.maes c880fa30e1 fix(circleci): replace config with standard org config 2025-09-16 16:17:29 -05:00
james.maes 5a1779a73f chore: Updated to meet requirements for maven central and qqq-orb 2025-09-16 16:12:53 -05:00
Darin Kelkhoff 7a4265ddc4 Release 0.1.4 2025-04-29 08:47:18 -05:00
Darin Kelkhoff cd99d328ba Update to do a to-record-from-table-dynamic style link on the recordId in ProcessTraceSummaryLineRecordInt 2025-04-21 11:45:24 -05:00
Darin Kelkhoff 14d28c311a Update qqq version (wrong build of sprint-61 was pulled in) 2025-02-24 12:08:20 -06:00
Darin Kelkhoff cbdc041e20 Update pom version and qqq dep 2025-02-24 11:56:52 -06:00
Darin Kelkhoff f16f557bfd UI enhancements:
- join ProcessTrace with QQQProcess and QQQTable (for key record)
- expose those joins (mostly so we can punch-in to a query-screen filtered by table name, from record-list widget)
- add RecentProcessTracesWidgetBuilder for dropping a recent-processes widget on a table view screen;
- make keyRecordId be linked to the key-record.
2025-02-24 11:17:40 -06:00
Darin Kelkhoff 46a390c869 Make use of .circleci/mvn-settings.xml 2025-02-20 14:52:36 -06:00
Darin Kelkhoff 43151a9886 Initial checkin 2025-02-20 14:51:41 -06:00
Darin Kelkhoff aafdebb7a8 Update image name 2025-02-20 14:50:12 -06:00
Darin Kelkhoff 5c81de06bf Update image name 2025-02-20 14:49:07 -06:00
Darin Kelkhoff 81d3abcd48 Update version to 0.1.2 2025-02-20 14:31:48 -06:00
Darin Kelkhoff d8be4aad1d Switch to use ProcessTracerKeyRecordMessage from backend-core; add try-catch when building record ints 2025-02-20 14:31:14 -06:00
Darin Kelkhoff 4eba1fb039 Deprecate this class - as it moved into qqq-backend-core (this class now extends the one from there (with an extra 'r' in its name) 2025-02-20 14:30:28 -06:00
Darin Kelkhoff f55bb484fa fix marking java version 17; update qqq dep (sprint-61) 2025-02-20 14:30:03 -06:00
32 changed files with 2648 additions and 221 deletions

No files matched your search

+48 -102
View File
@@ -1,111 +1,57 @@
#version: 2.1
#
#commands:
#
# mvn_jar_deploy:
# steps:
# - checkout
# - run:
# name: Adjust pom version
# command: |
# .circleci/adjust-pom-version.sh
# - restore_cache:
# keys:
# - v1-dependencies-{{ checksum "pom.xml" }}
# - run:
# name: Run Maven Jar Deploy
# command: |
# mvn -s .circleci/mvn-settings.xml -T4 flatten:flatten jar:jar deploy:deploy
# - save_cache:
# paths:
# - ~/.m2
# key: v1-dependencies-{{ checksum "pom.xml" }}
#
#jobs:
# mvn_test:
# executor: cimg/openjdk:17.0.14
# steps:
# - mvn_verify
#
# mvn_deploy:
# executor: cimg/openjdk:17.0.14
# steps:
# - mvn_jar_deploy
#
#workflows:
# test_only:
# jobs:
# - mvn_test:
# context: qqq-maven-registry-credentials
# filters:
# branches:
# ignore: /(dev|integration.*)/
# tags:
# ignore: /(version|snapshot)-.*/
#
# deploy:
# jobs:
# - mvn_deploy:
# context: qqq-maven-registry-credentials
# filters:
# branches:
# only: /(dev|integration.*)/
# tags:
# only: /(version|snapshot)-.*/
version: 2.1
executors:
java-executor:
docker:
- image: circleci/openjdk:17-jdk
jobs:
verify:
executor: java-executor
steps:
- checkout
- restore_cache:
keys:
- v1-maven-cache-{{ checksum "pom.xml" }}
- run:
name: Verify with Maven
command: mvn verify
- store_test_results:
path: target/surefire-reports
- save_cache:
paths:
- ~/.m2/repository
key: v1-maven-cache-{{ checksum "pom.xml" }}
deploy:
executor: java-executor
steps:
- checkout
- restore_cache:
keys:
- v1-maven-cache-{{ checksum "pom.xml" }}
- run:
name: Deploy with Maven
command: mvn deploy
- store_test_results:
path: target/surefire-reports
- save_cache:
paths:
- ~/.m2/repository
key: v1-maven-cache-{{ checksum "pom.xml" }}
orbs:
qqq-orb: kingsrook/qqq-orb@0.3.8
workflows:
version: 2
build_and_deploy:
test_only:
jobs:
- verify:
context: qqq-maven-registry-credentials
- qqq-orb/mvn_test_only:
context: [ qqq-maven-registry-credentials ]
filters:
branches:
ignore: main
- deploy:
context: qqq-maven-registry-credentials
ignore: /(develop|main|release/.*|hotfix/.*|integration.*)/
tags:
only: []
publish_snapshot:
jobs:
- qqq-orb/mvn_publish:
context: [ qqq-maven-registry-credentials ]
branch_type: snapshot
filters:
branches:
only: main
only:
- develop
publish_release_candidate:
jobs:
- qqq-orb/mvn_publish:
context: [ qqq-maven-registry-credentials ]
branch_type: release_candidate
filters:
branches:
only:
- /release\/.*/
publish_release:
jobs:
- qqq-orb/mvn_publish:
context: [ qqq-maven-registry-credentials ]
branch_type: release
filters:
branches:
only: [ main ]
tags:
only: [ /v.*/ ]
publish_hotfix_release:
jobs:
- qqq-orb/mvn_publish:
context: [ qqq-maven-registry-credentials ]
branch_type: hotfix
filters:
branches:
only:
- /hotfix\/.*/
+9
View File
@@ -0,0 +1,9 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github-qqq-maven-registry</id>
<username>${env.QQQ_MAVEN_REGISTRY_USERNAME}</username>
<password>${env.QQQ_MAVEN_REGISTRY_PASSWORD}</password>
</server>
</servers>
</settings>
+58
View File
@@ -0,0 +1,58 @@
# Changelog
All notable changes to QBit User Role Permissions will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Comprehensive README documentation following QQQ sub repo standards
- Standard GitHub files (LICENSE, CHANGELOG, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT)
- Proper project structure and documentation
### Changed
- Updated README to follow QQQ framework standards
- Improved project documentation and structure
- Enhanced GitHub repository setup
## [0.30.0-SNAPSHOT] - 2024-01-XX
### Added
- Initial QBit implementation for user role permissions
- Database schema for users, roles, and permissions
- Java classes for User, Role, Permission, UserRole, and RolePermission
- Integration with QQQ Backend Core framework
- H2 database support for testing
- JUnit 5 test framework integration
- AssertJ assertions for testing
- Checkstyle configuration for code quality
### Changed
- Initial public release of QBit User Role Permissions
- Established QBit development standards
- Created modular architecture for permission management
---
## 📚 For Detailed Information
**📖 [Complete Documentation Wiki](https://github.com/Kingsrook/qqq/wiki)** - Start here for comprehensive guides
- **[🏠 Home](https://github.com/Kingsrook/qqq/wiki/Home)** - Project overview and quick start
- **[🚀 Release Flow](https://github.com/Kingsrook/qqq/wiki/Release-Flow)** - Detailed release process
- **[🏷️ Changelog & Tagging](https://github.com/Kingsrook/qqq/wiki/Changelog-and-Tagging)** - Commit conventions and release notes
- **[🔧 Developer Onboarding](https://github.com/Kingsrook/qqq/wiki/Developer-Onboarding)** - Setup and contribution guide
## 🔄 Version Compatibility
QBit User Role Permissions follows semantic versioning:
- **MAJOR** versions may contain breaking changes
- **MINOR** versions add new functionality (backward compatible)
- **PATCH** versions contain bug fixes (backward compatible)
For detailed compatibility information, see [QQQ Compatibility Matrix](https://github.com/Kingsrook/qqq/wiki/Compatibility-Matrix).
---
**Thank you for using QBit User Role Permissions!** 🚀
+4
View File
@@ -0,0 +1,4 @@
# Code of Conduct
See Project level [Code of Conduct](https://github.com/Kingsrook/qqq/blob/develop/CODE_OF_CONDUCT.md)
+3
View File
@@ -0,0 +1,3 @@
# Code Style Guide
* See Project [Code Style Guide](https://github.com/Kingsrook/qqq/blob/develop/CODE_STYLE.md)
+4
View File
@@ -0,0 +1,4 @@
# Contributing to QBit User Role Permissions
* See Project [Contributing](https://github.com/Kingsrook/qqq/blob/develop/CONTRIBUTING.md)
+87 -1
View File
@@ -1,4 +1,8 @@
## QBit: Standard Process Trace
# QBit: Standard Process Trace
[![Version](https://img.shields.io/badge/version-0.1.1--SNAPSHOT-blue.svg)](https://github.com/Kingsrook/qbit-standard-process-trace)
[![License](https://img.shields.io/badge/license-GNU%20Affero%20GPL%20v3-green.svg)](https://www.gnu.org/licenses/agpl-3.0.en.html)
[![Java](https://img.shields.io/badge/java-17+-blue.svg)](https://adoptium.net/)
### Overview
*Note: This is one of the original QBit implementations - so, some of the mechanics of how
@@ -116,3 +120,85 @@ the provided tables.
need these tables in your QQQ Instance and backend data store.
* Use `QQQProcessesMetaDataProvider` and `QQQTablesMetaDataProvider` to define these tables.
## 📚 Documentation
**📖 [Complete Documentation Wiki](https://github.com/Kingsrook/qqq/wiki)** - Start here for comprehensive guides
- **[🏠 Home](https://github.com/Kingsrook/qqq/wiki/Home)** - Project overview and quick start
- **[🏗️ Architecture](https://github.com/Kingsrook/qqq/wiki/High-Level-Architecture)** - System design and principles
- **[🔧 Development](https://github.com/Kingsrook/qqq/wiki/Developer-Onboarding)** - Setup and contribution guide
- **[📦 QBits](https://github.com/Kingsrook/qqq/wiki/QBit-Development)** - QBit development guide
- **[🚀 Building](https://github.com/Kingsrook/qqq/wiki/Building-Locally)** - Local development workflow
## 🤝 Contributing
**Important**: This repository is a component of the QQQ framework. All contributions, issues, and discussions should go through the main QQQ repository.
### Development Workflow
1. **Fork the main QQQ repository**: https://github.com/Kingsrook/qqq
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Make your changes** (including QBit changes if applicable)
4. **Run tests**: `mvn test`
5. **Commit your changes**: `git commit -m 'Add amazing feature'`
6. **Push to the branch**: `git push origin feature/amazing-feature`
7. **Open a Pull Request** to the main QQQ repository
### Code Standards
- **Java**: Follow Java best practices and QQQ coding standards
- **Documentation**: Update relevant documentation
- **Versioning**: Follow semantic versioning
- **Testing**: Maintain comprehensive test coverage
## 🏢 About Kingsrook
QQQ is built by **[Kingsrook](https://qrun.io)** - making engineers more productive through intelligent automation and developer tools.
- **Website**: [https://qrun.io](https://qrun.io)
- **Contact**: [contact@kingsrook.com](mailto:contact@kingsrook.com)
- **GitHub**: [https://github.com/Kingsrook](https://github.com/Kingsrook)
## 📄 License
This project is licensed under the **GNU Affero General Public License v3.0** - see the [LICENSE.txt](LICENSE.txt) file for details.
```
QBit Standard Process Trace
Copyright (C) 2021-2024 Kingsrook, LLC
651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
contact@kingsrook.com | https://github.com/Kingsrook/
```
**Note**: This is a component of the QQQ framework. For the complete license and more information, see the main QQQ repository: https://github.com/Kingsrook/qqq
## 🆘 Support & Community
### ⚠️ Important: Use Main QQQ Repository
**All support, issues, discussions, and community interactions should go through the main QQQ repository:**
- **Main Repository**: https://github.com/Kingsrook/qqq
- **Issues**: https://github.com/Kingsrook/qqq/issues
- **Discussions**: https://github.com/Kingsrook/qqq/discussions
- **Wiki**: https://github.com/Kingsrook/qqq/wiki
### Getting Help
- **Documentation**: Check the [QQQ Wiki](https://github.com/Kingsrook/qqq/wiki)
- **Issues**: Report bugs and feature requests on [Main QQQ Issues](https://github.com/Kingsrook/qqq/issues)
- **Discussions**: Join community discussions on [Main QQQ Discussions](https://github.com/Kingsrook/qqq/discussions)
- **Questions**: Ask questions in the main QQQ repository
## 🙏 Acknowledgments
- **QQQ Framework Team**: For the underlying low-code platform
- **Process Monitoring Community**: For process tracing best practices
- **Open Source Community**: For the tools and libraries that make this possible
---
**Built with ❤️ by the Kingsrook Team**
**This is a QBit component of the QQQ framework. For complete information, support, and community, visit: https://github.com/Kingsrook/qqq**
+3
View File
@@ -0,0 +1,3 @@
# Security Policy
* See Project [Security Policy](https://github.com/Kingsrook/qqq/blob/develop/SECURITY.md)
+64 -19
View File
@@ -21,24 +21,66 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<revision>0.1.3-SNAPSHOT</revision>
</properties>
<parent>
<groupId>com.kingsrook</groupId>
<artifactId>qbit-build-parent</artifactId>
<version>1.1.0</version>
</parent>
<groupId>com.kingsrook.qbits</groupId>
<artifactId>qbit-standard-process-trace</artifactId>
<version>0.1.1-SNAPSHOT</version>
<version>${revision}</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<name>QBit Standard Process Trace</name>
<description>Standard process tracing module for the QBit framework, providing process trace tables and StandardProcessTracer implementation</description>
<url>https://github.com/Kingsrook/qbit-standard-process-trace</url>
<modelVersion>4.0.0</modelVersion>
<licenses>
<license>
<name>GNU Affero General Public License v3.0</name>
<url>https://www.gnu.org/licenses/agpl-3.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>kingsrook</id>
<name>Kingsrook Team</name>
<email>contact@kingsrook.com</email>
<organization>Kingsrook, LLC</organization>
<organizationUrl>https://kingsrook.com</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/Kingsrook/qbit-standard-process-trace.git</connection>
<developerConnection>scm:git:ssh://github.com:Kingsrook/qbit-standard-process-trace.git</developerConnection>
<url>https://github.com/Kingsrook/qbit-standard-process-trace</url>
<tag>HEAD</tag>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.kingsrook.qqq</groupId>
<artifactId>qqq-bom-pom</artifactId>
<version>0.24.0-integration-sprint-59-20250210-161628</version>
<version>0.31.0-expand-query-stats-8b0b96781-20251104.222953-1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -50,22 +92,25 @@
<groupId>com.kingsrook.qqq</groupId>
<artifactId>qqq-backend-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.27.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>github-qqq-maven-registry</id>
<name>GitHub QQQ Maven Registry</name>
<url>https://maven.pkg.github.com/Kingsrook/qqq-maven-registry</url>
<id>sonatype-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>github-qqq-maven-registry</id>
<name>GitHub QQQ Maven Registry</name>
<url>https://maven.pkg.github.com/Kingsrook/qqq-maven-registry</url>
</repository>
</distributionManagement>
</project>
@@ -22,16 +22,25 @@
package com.kingsrook.qbits.standardprocesstrace;
import com.kingsrook.qqq.backend.core.model.metadata.producers.MetaDataCustomizerInterface;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitConfig;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
/*******************************************************************************
** ad-hoc Configuration data for this qbit.
** TODO - when qbit configs become formalized in qqq, adapt this qbit to that interface.
* Configuration data for this qbit.
*
*******************************************************************************/
public class StandardProcessTraceQBitConfig
public class StandardProcessTraceQBitConfig implements QBitConfig
{
private MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer;
private String userIdPossibleValueSourceName;
private String userTableName;
private String userIdReferenceFieldName;
private boolean includeBackendActivityStats = false;
/*******************************************************************************
@@ -125,4 +134,82 @@ public class StandardProcessTraceQBitConfig
}
/*******************************************************************************
* Getter for includeBackendActivityStats
* @see #withIncludeBackendActivityStats(boolean)
*******************************************************************************/
public boolean getIncludeBackendActivityStats()
{
return (this.includeBackendActivityStats);
}
/*******************************************************************************
* Setter for includeBackendActivityStats
* @see #withIncludeBackendActivityStats(boolean)
*******************************************************************************/
public void setIncludeBackendActivityStats(boolean includeBackendActivityStats)
{
this.includeBackendActivityStats = includeBackendActivityStats;
}
/*******************************************************************************
* Fluent setter for includeBackendActivityStats
*
* @param includeBackendActivityStats
* indicate whether or not the ProcessTraceBackendActivityStats table should be
* included in the QInstance (and records should be built in that table under
* processTrace records).
* <p>Note that using this feature requires the QQQ QueryStatManager to be active
* in the application server.</p>
* @return this
*******************************************************************************/
public StandardProcessTraceQBitConfig withIncludeBackendActivityStats(boolean includeBackendActivityStats)
{
this.includeBackendActivityStats = includeBackendActivityStats;
return (this);
}
/*******************************************************************************
* Getter for tableMetaDataCustomizer
* @see #withTableMetaDataCustomizer(MetaDataCustomizerInterface)
*******************************************************************************/
public MetaDataCustomizerInterface<QTableMetaData> getTableMetaDataCustomizer()
{
return (this.tableMetaDataCustomizer);
}
/*******************************************************************************
* Setter for tableMetaDataCustomizer
* @see #withTableMetaDataCustomizer(MetaDataCustomizerInterface)
*******************************************************************************/
public void setTableMetaDataCustomizer(MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer)
{
this.tableMetaDataCustomizer = tableMetaDataCustomizer;
}
/*******************************************************************************
* Fluent setter for tableMetaDataCustomizer
*
* @param tableMetaDataCustomizer
* table meta data customizer to be applied to all tables produced by this qbit.
* @return this
*******************************************************************************/
public StandardProcessTraceQBitConfig withTableMetaDataCustomizer(MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer)
{
this.tableMetaDataCustomizer = tableMetaDataCustomizer;
return (this);
}
}
@@ -23,15 +23,15 @@ package com.kingsrook.qbits.standardprocesstrace;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryLine;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryLineRecordInt;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerHelper;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerInterface;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerMultiOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppSection;
import com.kingsrook.qqq.backend.core.model.metadata.producers.MetaDataCustomizerInterface;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitMetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
@@ -39,10 +39,9 @@ import com.kingsrook.qqq.backend.core.utils.StringUtils;
/*******************************************************************************
**
*******************************************************************************/
public class StandardProcessTraceQBitProducer implements MetaDataProducerInterface<MetaDataProducerMultiOutput>
public class StandardProcessTraceQBitProducer implements QBitMetaDataProducer<StandardProcessTraceQBitConfig>
{
private StandardProcessTraceQBitConfig standardProcessTraceQBitConfig;
private MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer;
private StandardProcessTraceQBitConfig standardProcessTraceQBitConfig;
@@ -51,34 +50,71 @@ public class StandardProcessTraceQBitProducer implements MetaDataProducerInterfa
***************************************************************************/
public static QAppSection getAppSection(QInstance qInstance)
{
return (new QAppSection().withName("processTrace")
QBitMetaData qBitMetaData = qInstance.getQBits().get(new StandardProcessTraceQBitProducer().getQBitMetaData().getName());
QAppSection section = new QAppSection().withName("processTrace")
.withTable(ProcessTrace.TABLE_NAME)
.withTable(ProcessTraceSummaryLine.TABLE_NAME)
.withTable(ProcessTraceSummaryLineRecordInt.TABLE_NAME));
.withTable(ProcessTraceSummaryLineRecordInt.TABLE_NAME);
if(qBitMetaData != null && qBitMetaData.getConfig() instanceof StandardProcessTraceQBitConfig config)
{
if(config.getIncludeBackendActivityStats())
{
section.withTable(ProcessTraceBackendActivityStats.TABLE_NAME);
}
}
return (section);
}
/***************************************************************************
**
*
***************************************************************************/
@Override
public MetaDataProducerMultiOutput produce(QInstance qInstance) throws QException
public StandardProcessTraceQBitConfig getQBitConfig()
{
MetaDataProducerHelper.processAllMetaDataProducersInPackage(qInstance, ProcessTrace.class.getPackageName(), tableMetaDataCustomizer);
return (standardProcessTraceQBitConfig);
}
//////////////////////////////////////////////////////////////////////////////////////
// set the possible value source on the processTrace.userId field, if so configured //
//////////////////////////////////////////////////////////////////////////////////////
if(standardProcessTraceQBitConfig != null && StringUtils.hasContent(standardProcessTraceQBitConfig.getUserIdPossibleValueSourceName()))
/***************************************************************************
*
***************************************************************************/
@Override
public QBitMetaData getQBitMetaData()
{
QBitMetaData qBitMetaData = new QBitMetaData()
.withGroupId("com.kingsrook.qbits")
.withArtifactId("standard-process-trace")
.withVersion("0.1.3")
.withNamespace(getNamespace())
.withConfig(getQBitConfig());
return qBitMetaData;
}
/***************************************************************************
*
***************************************************************************/
@Override
public void postProduceActions(MetaDataProducerMultiOutput metaDataProducerMultiOutput, QInstance qInstance) throws QException
{
if(standardProcessTraceQBitConfig != null)
{
qInstance.getTable(ProcessTrace.TABLE_NAME).getField("userId").setPossibleValueSourceName(standardProcessTraceQBitConfig.getUserIdPossibleValueSourceName());
//////////////////////////////////////////////////////////////////////////////////////
// set the possible value source on the processTrace.userId field, if so configured //
//////////////////////////////////////////////////////////////////////////////////////
if(StringUtils.hasContent(standardProcessTraceQBitConfig.getUserIdPossibleValueSourceName()))
{
metaDataProducerMultiOutput.get(QTableMetaData.class, ProcessTrace.TABLE_NAME).getField("userId").setPossibleValueSourceName(standardProcessTraceQBitConfig.getUserIdPossibleValueSourceName());
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// we actually called MetaDataProducerHelper ourselves, so, don't have anything to return here... //
////////////////////////////////////////////////////////////////////////////////////////////////////
return new MetaDataProducerMultiOutput();
}
@@ -112,35 +148,4 @@ public class StandardProcessTraceQBitProducer implements MetaDataProducerInterfa
return (this);
}
/*******************************************************************************
** Getter for tableMetaDataCustomizer
*******************************************************************************/
public MetaDataCustomizerInterface<QTableMetaData> getTableMetaDataCustomizer()
{
return (this.tableMetaDataCustomizer);
}
/*******************************************************************************
** Setter for tableMetaDataCustomizer
*******************************************************************************/
public void setTableMetaDataCustomizer(MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer)
{
this.tableMetaDataCustomizer = tableMetaDataCustomizer;
}
/*******************************************************************************
** Fluent setter for tableMetaDataCustomizer
*******************************************************************************/
public StandardProcessTraceQBitProducer withTableMetaDataCustomizer(MetaDataCustomizerInterface<QTableMetaData> tableMetaDataCustomizer)
{
this.tableMetaDataCustomizer = tableMetaDataCustomizer;
return (this);
}
}
@@ -0,0 +1,62 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.metadata;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStatsAction;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
/*******************************************************************************
* Meta Data Producer for ProcessTraceBackendActivityStatsAction
* Note: not done via annotations, so it can be disabled via config
*******************************************************************************/
public class ProcessTraceBackendActivityStatsActionMetaDataProducer extends MetaDataProducer<QPossibleValueSource>
{
public static final String NAME = ProcessTraceBackendActivityStatsAction.NAME;
/***************************************************************************
*
***************************************************************************/
@Override
public boolean isEnabled()
{
return (new ProcessTraceBackendActivityStatsMetaDataProducer().isEnabled());
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public QPossibleValueSource produce(QInstance qInstance) throws QException
{
return (QPossibleValueSource.newForEnum(NAME, ProcessTraceBackendActivityStatsAction.values()));
}
}
@@ -0,0 +1,93 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.metadata;
import java.util.List;
import com.kingsrook.qbits.standardprocesstrace.StandardProcessTraceQBitConfig;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.instances.QInstanceEnricher;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitConfig;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitProductionContext;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
import com.kingsrook.qqq.backend.core.model.metadata.tables.ExposedJoin;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.SectionFactory;
/*******************************************************************************
* Meta Data Producer for ProcessTraceBackendActivityStats
* Note: not done via annotations, so it can be disabled via config
*******************************************************************************/
public class ProcessTraceBackendActivityStatsMetaDataProducer extends MetaDataProducer<QTableMetaData>
{
/***************************************************************************
*
***************************************************************************/
@Override
public boolean isEnabled()
{
QBitConfig qBitConfig = QBitProductionContext.peekQBitConfig();
if(qBitConfig instanceof StandardProcessTraceQBitConfig config)
{
if(!config.getIncludeBackendActivityStats())
{
return (false);
}
}
return (true);
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public QTableMetaData produce(QInstance qInstance) throws QException
{
QTableMetaData table = new QTableMetaData()
.withName(ProcessTraceBackendActivityStats.TABLE_NAME)
.withIcon(new QIcon().withName("query_stats"))
.withRecordLabelFormat("%s %s %s %s")
.withRecordLabelFields("processTraceId", "qqqBackendId", "qqqTableId", "actionName")
.withPrimaryKeyField("id")
.withFieldsFromEntity(ProcessTraceBackendActivityStats.class)
.withSection(SectionFactory.defaultT1("id", "processTraceId", "qqqBackendId", "qqqTableId", "actionName"))
.withSection(SectionFactory.defaultT2("callCount", "recordCount", "runtimeMillis"))
.withExposedJoin(new ExposedJoin().withLabel("Process Trace").withJoinPath(List.of(ProcessTraceJoinBackendActivityStatsMetaDataProducer.NAME)).withJoinTable(ProcessTrace.TABLE_NAME));
table.withoutCapabilities(Capability.allWriteCapabilities());
QInstanceEnricher.setInferredFieldBackendNames(table);
return (table);
}
}
@@ -0,0 +1,71 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.metadata;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinType;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
/*******************************************************************************
* Meta Data Producer for ProcessTraceJoinBackendActivityStats
* Note: not done via annotations, so it can be disabled via config
*******************************************************************************/
public class ProcessTraceJoinBackendActivityStatsMetaDataProducer extends MetaDataProducer<QJoinMetaData>
{
public static final String NAME = "ProcessTraceJoinBackendActivityStats";
/***************************************************************************
*
***************************************************************************/
@Override
public boolean isEnabled()
{
return (new ProcessTraceBackendActivityStatsMetaDataProducer().isEnabled());
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public QJoinMetaData produce(QInstance qInstance) throws QException
{
return (new QJoinMetaData()
.withName(NAME)
.withLeftTable(ProcessTrace.TABLE_NAME)
.withRightTable(ProcessTraceBackendActivityStats.TABLE_NAME)
.withType(JoinType.ONE_TO_MANY)
.withJoinOn(new JoinOn("id", "processTraceId"))
);
}
}
@@ -0,0 +1,72 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.metadata;
import com.kingsrook.qqq.backend.core.actions.dashboard.widgets.ChildRecordListRenderer;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerMultiOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitProductionContext;
/*******************************************************************************
* Meta Data Producer for ProcessTraceJoinBackendActivityStats
* Note: not done via annotations, so it can be disabled via config
*******************************************************************************/
public class ProcessTraceJoinBackendActivityStatsWidgetMetaDataProducer extends MetaDataProducer<QWidgetMetaData>
{
public static final String NAME = "ProcessTraceJoinBackendActivityStatsWidget";
/***************************************************************************
*
***************************************************************************/
@Override
public boolean isEnabled()
{
return (new ProcessTraceBackendActivityStatsMetaDataProducer().isEnabled());
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public QWidgetMetaData produce(QInstance qInstance) throws QException
{
MetaDataProducerMultiOutput metaDataProducerMultiOutput = QBitProductionContext.peekMetaDataProducerMultiOutput();
QJoinMetaData joinMetaData = metaDataProducerMultiOutput.get(QJoinMetaData.class, ProcessTraceJoinBackendActivityStatsMetaDataProducer.NAME);
return ChildRecordListRenderer.widgetMetaDataBuilder(joinMetaData)
.withName(NAME)
.withLabel("Backend Activity Stats")
.withMaxRows(250)
.getWidgetMetaData();
}
}
@@ -0,0 +1,59 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.metadata;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinType;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.tables.QQQTable;
/*******************************************************************************
** Meta Data Producer for ProcessTraceJoinKeyRecordQQQTable
*******************************************************************************/
public class ProcessTraceJoinKeyRecordQQQTableMetaDataProducer extends MetaDataProducer<QJoinMetaData>
{
public static final String NAME = "ProcessTraceJoinKeyRecordQQQTable";
/*******************************************************************************
**
*******************************************************************************/
@Override
public QJoinMetaData produce(QInstance qInstance) throws QException
{
return (new QJoinMetaData()
.withLeftTable(ProcessTrace.TABLE_NAME)
.withRightTable(QQQTable.TABLE_NAME)
.withType(JoinType.MANY_TO_ONE)
.withJoinOn(new JoinOn("keyRecordQqqTableId", "id"))
.withName(NAME)
);
}
}
@@ -0,0 +1,59 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.metadata;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducer;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinType;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.processes.QQQProcess;
/*******************************************************************************
** Meta Data Producer for ProcessTraceJoinQQQProcess
*******************************************************************************/
public class ProcessTraceJoinQQQProcessMetaDataProducer extends MetaDataProducer<QJoinMetaData>
{
public static final String NAME = "ProcessTraceJoinQQQProcess";
/*******************************************************************************
**
*******************************************************************************/
@Override
public QJoinMetaData produce(QInstance qInstance) throws QException
{
return (new QJoinMetaData()
.withLeftTable(ProcessTrace.TABLE_NAME)
.withRightTable(QQQProcess.TABLE_NAME)
.withType(JoinType.MANY_TO_ONE)
.withJoinOn(new JoinOn("qqqProcessId", "id"))
.withName(NAME)
);
}
}
@@ -24,12 +24,22 @@ package com.kingsrook.qbits.standardprocesstrace.model;
import java.time.Instant;
import java.util.List;
import com.kingsrook.qbits.standardprocesstrace.metadata.ProcessTraceBackendActivityStatsMetaDataProducer;
import com.kingsrook.qbits.standardprocesstrace.metadata.ProcessTraceJoinBackendActivityStatsMetaDataProducer;
import com.kingsrook.qbits.standardprocesstrace.metadata.ProcessTraceJoinBackendActivityStatsWidgetMetaDataProducer;
import com.kingsrook.qbits.standardprocesstrace.metadata.ProcessTraceJoinKeyRecordQQQTableMetaDataProducer;
import com.kingsrook.qbits.standardprocesstrace.metadata.ProcessTraceJoinQQQProcessMetaDataProducer;
import com.kingsrook.qbits.standardprocesstrace.utils.ProcessTraceTableCustomizer;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizers;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
import com.kingsrook.qqq.backend.core.model.metadata.fields.ValueTooLongBehavior;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
@@ -59,7 +69,7 @@ import com.kingsrook.qqq.backend.core.model.tables.QQQTable;
childTableEntityClass = ProcessTraceSummaryLine.class,
joinFieldName = "processTraceSummaryLineId",
childJoin = @ChildJoin(enabled = true),
childRecordListWidget = @ChildRecordListWidget(label = "Summary Lines", enabled = true, maxRows = 250))
childRecordListWidget = @ChildRecordListWidget(label = "Summary Lines", enabled = true, maxRows = 250)),
}
)
public class ProcessTrace extends QRecordEntity
@@ -80,7 +90,7 @@ public class ProcessTrace extends QRecordEntity
@Override
public QTableMetaData customizeMetaData(QInstance qInstance, QTableMetaData table) throws QException
{
String childJoinName = QJoinMetaData.makeInferredJoinName(TABLE_NAME, ProcessTraceSummaryLine.TABLE_NAME);
String summaryLinesChildJoinName = QJoinMetaData.makeInferredJoinName(TABLE_NAME, ProcessTraceSummaryLine.TABLE_NAME);
table
.withUniqueKey(new UniqueKey("processUUID"))
@@ -89,8 +99,24 @@ public class ProcessTrace extends QRecordEntity
.withRecordLabelFields("qqqProcessId", "processUUID")
.withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id", "qqqProcessId", "processUUID", "userId")))
.withSection(new QFieldSection("data", new QIcon().withName("text_snippet"), Tier.T2, List.of("startTimestamp", "endTimestamp", "runtimeMillis", "keyRecordQqqTableId", "keyRecordId", "recordCount", "exceptionMessage")))
.withSection(new QFieldSection("summaryLines", new QIcon().withName("horizontal_rule"), Tier.T2).withWidgetName(childJoinName))
.withExposedJoin(new ExposedJoin().withLabel("Summary Lines").withJoinPath(List.of(childJoinName)).withJoinTable(ProcessTraceSummaryLine.TABLE_NAME));
.withSection(new QFieldSection("summaryLines", new QIcon().withName("horizontal_rule"), Tier.T2).withWidgetName(summaryLinesChildJoinName))
.withExposedJoin(new ExposedJoin().withLabel("Summary Lines").withJoinPath(List.of(summaryLinesChildJoinName)).withJoinTable(ProcessTraceSummaryLine.TABLE_NAME))
.withExposedJoin(new ExposedJoin().withLabel("Key Record Table").withJoinPath(List.of(ProcessTraceJoinKeyRecordQQQTableMetaDataProducer.NAME)).withJoinTable(QQQTable.TABLE_NAME))
.withExposedJoin(new ExposedJoin().withLabel("Process").withJoinPath(List.of(ProcessTraceJoinQQQProcessMetaDataProducer.NAME)).withJoinTable(QQQProcess.TABLE_NAME));
table.withCustomizer(TableCustomizers.POST_QUERY_RECORD, new QCodeReference(ProcessTraceTableCustomizer.class));
table.getField("keyRecordId").withFieldAdornment(new FieldAdornment(AdornmentType.LINK).withValue(AdornmentType.LinkValues.TO_RECORD_FROM_TABLE_DYNAMIC, true));
if(new ProcessTraceBackendActivityStatsMetaDataProducer().isEnabled())
{
table.getSections().add(new QFieldSection("backendActivityStats", new QIcon().withName("query_stats"), Tier.T2)
.withWidgetName(ProcessTraceJoinBackendActivityStatsWidgetMetaDataProducer.NAME));
table.withExposedJoin(new ExposedJoin()
.withLabel("Backend Activity Stats")
.withJoinPath(List.of(ProcessTraceJoinBackendActivityStatsMetaDataProducer.NAME))
.withJoinTable(ProcessTraceBackendActivityStats.TABLE_NAME));
}
return (table);
}
@@ -0,0 +1,349 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.model;
import com.kingsrook.qqq.backend.core.model.backends.QQQBackend;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
import com.kingsrook.qqq.backend.core.model.tables.QQQTable;
/*******************************************************************************
* QRecord Entity for ProcessTraceBackendActivityStats table
* Note: not using meta-data producing annotations, so it can be disabled via config
*******************************************************************************/
public class ProcessTraceBackendActivityStats extends QRecordEntity
{
public static final String TABLE_NAME = "processTraceBackendActivityStats";
@QField(isEditable = false, isPrimaryKey = true)
private Long id;
@QField(possibleValueSourceName = ProcessTrace.TABLE_NAME)
private Long processTraceId;
@QField(label = "Backend", possibleValueSourceName = QQQBackend.TABLE_NAME)
private Integer qqqBackendId;
@QField(label = "Table", possibleValueSourceName = QQQTable.TABLE_NAME)
private Integer qqqTableId;
@QField(label = "Action", possibleValueSourceName = ProcessTraceBackendActivityStatsAction.NAME)
private String actionName;
@QField(displayFormat = DisplayFormat.COMMAS)
private Integer callCount;
@QField(displayFormat = DisplayFormat.COMMAS)
private Integer recordCount;
@QField(displayFormat = DisplayFormat.COMMAS)
private Integer runtimeMillis;
/*******************************************************************************
** Default constructor
*******************************************************************************/
public ProcessTraceBackendActivityStats()
{
}
/*******************************************************************************
** Constructor that takes a QRecord
*******************************************************************************/
public ProcessTraceBackendActivityStats(QRecord record)
{
populateFromQRecord(record);
}
/*******************************************************************************
* Getter for id
* @see #withId(Long)
*******************************************************************************/
public Long getId()
{
return (this.id);
}
/*******************************************************************************
* Setter for id
* @see #withId(Long)
*******************************************************************************/
public void setId(Long id)
{
this.id = id;
}
/*******************************************************************************
* Fluent setter for id
*******************************************************************************/
public ProcessTraceBackendActivityStats withId(Long id)
{
this.id = id;
return (this);
}
/*******************************************************************************
* Getter for processTraceId
* @see #withProcessTraceId(Long)
*******************************************************************************/
public Long getProcessTraceId()
{
return (this.processTraceId);
}
/*******************************************************************************
* Setter for processTraceId
* @see #withProcessTraceId(Long)
*******************************************************************************/
public void setProcessTraceId(Long processTraceId)
{
this.processTraceId = processTraceId;
}
/*******************************************************************************
* Fluent setter for processTraceId
*******************************************************************************/
public ProcessTraceBackendActivityStats withProcessTraceId(Long processTraceId)
{
this.processTraceId = processTraceId;
return (this);
}
/*******************************************************************************
* Getter for actionName
* @see #withActionName(String)
*******************************************************************************/
public String getActionName()
{
return (this.actionName);
}
/*******************************************************************************
* Setter for actionName
* @see #withActionName(String)
*******************************************************************************/
public void setActionName(String actionName)
{
this.actionName = actionName;
}
/*******************************************************************************
* Fluent setter for actionName
*******************************************************************************/
public ProcessTraceBackendActivityStats withActionName(String actionName)
{
this.actionName = actionName;
return (this);
}
/*******************************************************************************
* Getter for callCount
* @see #withCallCount(Integer)
*******************************************************************************/
public Integer getCallCount()
{
return (this.callCount);
}
/*******************************************************************************
* Setter for callCount
* @see #withCallCount(Integer)
*******************************************************************************/
public void setCallCount(Integer callCount)
{
this.callCount = callCount;
}
/*******************************************************************************
* Fluent setter for callCount
*******************************************************************************/
public ProcessTraceBackendActivityStats withCallCount(Integer callCount)
{
this.callCount = callCount;
return (this);
}
/*******************************************************************************
* Getter for recordCount
* @see #withRecordCount(Integer)
*******************************************************************************/
public Integer getRecordCount()
{
return (this.recordCount);
}
/*******************************************************************************
* Setter for recordCount
* @see #withRecordCount(Integer)
*******************************************************************************/
public void setRecordCount(Integer recordCount)
{
this.recordCount = recordCount;
}
/*******************************************************************************
* Fluent setter for recordCount
*******************************************************************************/
public ProcessTraceBackendActivityStats withRecordCount(Integer recordCount)
{
this.recordCount = recordCount;
return (this);
}
/*******************************************************************************
* Getter for runtimeMillis
* @see #withRuntimeMillis(Integer)
*******************************************************************************/
public Integer getRuntimeMillis()
{
return (this.runtimeMillis);
}
/*******************************************************************************
* Setter for runtimeMillis
* @see #withRuntimeMillis(Integer)
*******************************************************************************/
public void setRuntimeMillis(Integer runtimeMillis)
{
this.runtimeMillis = runtimeMillis;
}
/*******************************************************************************
* Fluent setter for runtimeMillis
*******************************************************************************/
public ProcessTraceBackendActivityStats withRuntimeMillis(Integer runtimeMillis)
{
this.runtimeMillis = runtimeMillis;
return (this);
}
/*******************************************************************************
* Getter for qqqBackendId
* @see #withQqqBackendId(Integer)
*******************************************************************************/
public Integer getQqqBackendId()
{
return (this.qqqBackendId);
}
/*******************************************************************************
* Setter for qqqBackendId
* @see #withQqqBackendId(Integer)
*******************************************************************************/
public void setQqqBackendId(Integer qqqBackendId)
{
this.qqqBackendId = qqqBackendId;
}
/*******************************************************************************
* Fluent setter for qqqBackendId
*******************************************************************************/
public ProcessTraceBackendActivityStats withQqqBackendId(Integer qqqBackendId)
{
this.qqqBackendId = qqqBackendId;
return (this);
}
/*******************************************************************************
* Getter for qqqTableId
* @see #withQqqTableId(Integer)
*******************************************************************************/
public Integer getQqqTableId()
{
return (this.qqqTableId);
}
/*******************************************************************************
* Setter for qqqTableId
* @see #withQqqTableId(Integer)
*******************************************************************************/
public void setQqqTableId(Integer qqqTableId)
{
this.qqqTableId = qqqTableId;
}
/*******************************************************************************
* Fluent setter for qqqTableId
*******************************************************************************/
public ProcessTraceBackendActivityStats withQqqTableId(Integer qqqTableId)
{
this.qqqTableId = qqqTableId;
return (this);
}
}
@@ -0,0 +1,132 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.model;
import java.util.Objects;
import com.kingsrook.qqq.backend.core.actions.tables.CountAction;
import com.kingsrook.qqq.backend.core.actions.tables.DeleteAction;
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
import com.kingsrook.qqq.backend.core.model.actions.audits.AuditDetailAccumulator;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.PossibleValueEnum;
/*******************************************************************************
** ProcessTraceBackendActivityStatsAction - possible value enum
*******************************************************************************/
public enum ProcessTraceBackendActivityStatsAction implements PossibleValueEnum<String>
{
INSERT(InsertAction.class.getSimpleName(), "Insert"),
UPDATE(UpdateAction.class.getSimpleName(), "Update"),
DELETE(DeleteAction.class.getSimpleName(), "Delete"),
QUERY(QueryAction.class.getSimpleName(), "Query"),
GET(GetAction.class.getSimpleName(), "Get"),
COUNT(CountAction.class.getSimpleName(), "Count"),
AGGREGATE(AuditDetailAccumulator.class.getSimpleName(), "Aggregate");
private final String id;
private final String label;
public static final String NAME = "ProcessTraceBackendActivityStatsAction";
/*******************************************************************************
**
*******************************************************************************/
ProcessTraceBackendActivityStatsAction(String id, String label)
{
this.id = id;
this.label = label;
}
/*******************************************************************************
** Get instance by id
**
*******************************************************************************/
public static ProcessTraceBackendActivityStatsAction getById(String id)
{
if(id == null)
{
return (null);
}
for(ProcessTraceBackendActivityStatsAction value : ProcessTraceBackendActivityStatsAction.values())
{
if(Objects.equals(value.id, id))
{
return (value);
}
}
return (null);
}
/*******************************************************************************
** Getter for id
**
*******************************************************************************/
public String getId()
{
return id;
}
/*******************************************************************************
** Getter for label
**
*******************************************************************************/
public String getLabel()
{
return label;
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public String getPossibleValueId()
{
return (getId());
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public String getPossibleValueLabel()
{
return (getLabel());
}
}
@@ -22,48 +22,22 @@
package com.kingsrook.qbits.standardprocesstrace.model;
import com.kingsrook.qqq.backend.core.processes.tracing.ProcessTracerMessage;
import com.kingsrook.qqq.backend.core.processes.tracing.ProcessTracerKeyRecordMessage;
/*******************************************************************************
**
*******************************************************************************/
public class ProcessTraceKeyRecordMessage extends ProcessTracerMessage
@Deprecated(since = "Moved to ProcessTracerKeyRecordMessage in qqq-backend-core")
public class ProcessTraceKeyRecordMessage extends ProcessTracerKeyRecordMessage
{
private final String tableName;
private final Integer recordId;
/***************************************************************************
**
***************************************************************************/
public ProcessTraceKeyRecordMessage(String tableName, Integer recordId)
{
super("Process Key Record is " + tableName + " " + recordId);
this.tableName = tableName;
this.recordId = recordId;
super(tableName, recordId);
}
/*******************************************************************************
** Getter for tableName
**
*******************************************************************************/
public String getTableName()
{
return (tableName);
}
/*******************************************************************************
** Getter for id
**
*******************************************************************************/
public Integer getRecordId()
{
return (recordId);
}
}
@@ -24,11 +24,16 @@ package com.kingsrook.qbits.standardprocesstrace.model;
import java.util.List;
import com.kingsrook.qbits.standardprocesstrace.utils.ProcessTraceSummaryLineRecordIntTableCustomizer;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizers;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.producers.MetaDataCustomizerInterface;
@@ -78,6 +83,9 @@ public class ProcessTraceSummaryLineRecordInt extends QRecordEntity
.withExposedJoin(new ExposedJoin().withLabel("Summary Line").withJoinPath(List.of(parentJoinName)).withJoinTable(ProcessTraceSummaryLine.TABLE_NAME))
.withExposedJoin(new ExposedJoin().withLabel("Process Trace").withJoinPath(List.of(parentJoinName, grandparentJoinName)).withJoinTable(ProcessTrace.TABLE_NAME));
table.withCustomizer(TableCustomizers.POST_QUERY_RECORD, new QCodeReference(ProcessTraceSummaryLineRecordIntTableCustomizer.class));
table.getField("recordId").withFieldAdornment(new FieldAdornment(AdornmentType.LINK).withValue(AdornmentType.LinkValues.TO_RECORD_FROM_TABLE_DYNAMIC, true));
return (table);
}
}
@@ -0,0 +1,298 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.backends.QQQBackendTableManager;
import com.kingsrook.qqq.backend.core.model.tables.QQQTableTableManager;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.PrefixedDefaultThreadFactory;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
/*******************************************************************************
* Singleton that collects QueryStats, associated with a processTraceId.
*
* <p>Runs a scheduled executor thread to clean itself up - e.g., in case processes
* leak (e.g., started in a frontend but exited before final step). Configured by
* {@link #setCleanupIntervalMillis(long)} and {@link #setCleanupMaxAge(long)}</p>
*******************************************************************************/
public class ProcessTraceBackendActivityStatsManager
{
private static final QLogger LOG = QLogger.getLogger(ProcessTraceBackendActivityStatsManager.class);
private static ProcessTraceBackendActivityStatsManager processTraceBackendActivityStatsManager = null;
private Map<Long, ProcessStats> stats = Collections.synchronizedMap(new HashMap<>());
private long CLEANUP_INTERVAL_MILLIS = 60 * 60 * 1000;
private long CLEANUP_MAX_AGE = 12 * 60 * 60 * 1000;
private ScheduledExecutorService scheduledExecutorService;
/***************************************************************************
* container for all data collected for a particular process trace.
*
* stores start milliseconds (for cleanup), plus map of keys to stats.
***************************************************************************/
private record ProcessStats(long startMillis, Map<Key, Stats> stats)
{
/*******************************************************************************
** Constructor that uses default values
**
*******************************************************************************/
public ProcessStats()
{
this(System.currentTimeMillis(), new LinkedHashMap<>());
}
}
/***************************************************************************
* what backend/table/action a set of stats are associated with.
*
* e.g., memoryBackend, personTable, insertAction
***************************************************************************/
public record Key(String backendName, String tableName, String actionName) implements Serializable
{
}
/***************************************************************************
* the stats collected for individual keys.
***************************************************************************/
private record Stats(Integer calls, Integer records, Integer millis)
{
}
/*******************************************************************************
** Singleton constructor
*******************************************************************************/
private ProcessTraceBackendActivityStatsManager()
{
scheduleCleanupJob();
}
/***************************************************************************
*
***************************************************************************/
private void scheduleCleanupJob()
{
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new PrefixedDefaultThreadFactory("ProcessTraceBackendActivityStatsManager-cleanup"));
scheduledExecutorService.scheduleAtFixedRate(this::cleanup, CLEANUP_INTERVAL_MILLIS, CLEANUP_INTERVAL_MILLIS, TimeUnit.MILLISECONDS);
}
/*******************************************************************************
** Singleton accessor
*******************************************************************************/
public static ProcessTraceBackendActivityStatsManager getInstance()
{
if(processTraceBackendActivityStatsManager == null)
{
processTraceBackendActivityStatsManager = new ProcessTraceBackendActivityStatsManager();
}
return (processTraceBackendActivityStatsManager);
}
/***************************************************************************
* shutdown the scheduled job. also clear stats.
***************************************************************************/
public void shutdown()
{
scheduledExecutorService.shutdown();
stats.clear();
}
/***************************************************************************
* initialize storage for stats for a specific process trace id
***************************************************************************/
public void initProcess(Long processTraceId)
{
stats.put(processTraceId, new ProcessStats());
}
/***************************************************************************
* clean up stat entries for processes that were originally created before
* CLEANUP_MAX_AGE (per {@link #setCleanupMaxAge(long)} milliseconds ago.
***************************************************************************/
private void cleanup()
{
long limitStartMillis = System.currentTimeMillis() - CLEANUP_MAX_AGE;
LOG.info("Starting cleanup of ProcessTraceBackendActivityStatsManager", logPair("size", stats.size()));
stats.entrySet().removeIf(entry -> entry.getValue().startMillis < limitStartMillis);
LOG.info("Finished cleanup of ProcessTraceBackendActivityStatsManager", logPair("size", stats.size()));
}
/***************************************************************************
* when storing a processTrace (e.g., after the process has finished running),
* convert the stats stored in this object to a list of {@link ProcessTraceBackendActivityStats}
* entities. Also remove the stats from this object's internal storage.
***************************************************************************/
public List<ProcessTraceBackendActivityStats> getAndRemoveStats(Long processTraceId) throws QException
{
List<ProcessTraceBackendActivityStats> rs = new ArrayList<>();
ProcessStats processStats = stats.remove(processTraceId);
if(processStats != null)
{
for(Map.Entry<Key, Stats> entry : CollectionUtils.nonNullMap(processStats.stats()).entrySet())
{
rs.add(new ProcessTraceBackendActivityStats()
.withProcessTraceId(processTraceId)
.withQqqBackendId(getBackendId(entry.getKey().backendName()))
.withQqqTableId(getTableId(entry.getKey().tableName()))
.withActionName(entry.getKey().actionName())
.withCallCount(entry.getValue().calls())
.withRecordCount(entry.getValue().records())
.withRuntimeMillis(entry.getValue().millis())
);
}
}
return (rs);
}
/***************************************************************************
*
***************************************************************************/
private Integer getBackendId(String backendName)
{
if(!StringUtils.hasContent(backendName))
{
return (null);
}
try
{
return QQQBackendTableManager.getQQQBackendId(QContext.getQInstance(), backendName);
}
catch(Exception e)
{
return (null);
}
}
/***************************************************************************
*
***************************************************************************/
private Integer getTableId(String tableName)
{
if(!StringUtils.hasContent(tableName))
{
return (null);
}
try
{
return QQQTableTableManager.getQQQTableId(QContext.getQInstance(), tableName);
}
catch(Exception e)
{
return (null);
}
}
/***************************************************************************
* increment the stat values for a given process.
*
* @param key the backend, table, and action
* @param addCalls the number of calls to add (typically 1 at a time?)
* @param addRecords the number of records to add
* @param addMillis the number of milliseconds of runtime to add
***************************************************************************/
public void add(Long processTraceId, Key key, Integer addCalls, Integer addRecords, Integer addMillis)
{
ProcessStats processStats = stats.computeIfAbsent(processTraceId, k -> new ProcessStats());
Map<Key, Stats> countsForProcess = processStats.stats();
if(countsForProcess != null)
{
Stats statsForKey = countsForProcess.computeIfAbsent(key, (k) -> new Stats(0, 0, 0));
countsForProcess.put(key, new Stats(statsForKey.calls + addCalls, statsForKey.records + addRecords, statsForKey.millis + addMillis));
}
}
/***************************************************************************
* sets the cleanup job's scheduled interval. Also reschedules the job.
*
* @param cleanupIntervalMillis milliseconds between runs of the cleanup job
***************************************************************************/
public void setCleanupIntervalMillis(long cleanupIntervalMillis)
{
CLEANUP_INTERVAL_MILLIS = cleanupIntervalMillis;
scheduledExecutorService.shutdown();
scheduleCleanupJob();
}
/***************************************************************************
* @param cleanupMaxAge max age (in millis) that a process is allowed to be
* before it gets cleaned up when a cleanup job runs.
***************************************************************************/
public void setCleanupMaxAge(long cleanupMaxAge)
{
CLEANUP_MAX_AGE = cleanupMaxAge;
}
}
@@ -0,0 +1,78 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizerInterface;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrGetInputInterface;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
import com.kingsrook.qqq.backend.core.model.tables.QQQTable;
import com.kingsrook.qqq.backend.core.processes.utils.GeneralProcessUtils;
/*******************************************************************************
**
*******************************************************************************/
public class ProcessTraceSummaryLineRecordIntTableCustomizer implements TableCustomizerInterface
{
/***************************************************************************
**
***************************************************************************/
@Override
public List<QRecord> postQuery(QueryOrGetInputInterface queryInput, List<QRecord> records) throws QException
{
if(queryInput.getShouldGenerateDisplayValues())
{
///////////////////////////////////////////////////////////////////////////////////////
// for records with a qqqTableId - look up that table name, then set a display-value //
// for the Link type adornment, to the recordId record within that table. //
///////////////////////////////////////////////////////////////////////////////////////
Set<Serializable> tableIds = records.stream().map(r -> r.getValue("qqqTableId")).filter(Objects::nonNull).collect(Collectors.toSet());
if(!tableIds.isEmpty())
{
Map<Serializable, QRecord> tableMap = GeneralProcessUtils.loadTableToMap(QQQTable.TABLE_NAME, "id", new QQueryFilter(new QFilterCriteria("id", QCriteriaOperator.IN, tableIds)));
for(QRecord record : records)
{
QRecord qqqTableRecord = tableMap.get(record.getValue("qqqTableId"));
if(qqqTableRecord != null && record.getValue("recordId") != null)
{
record.setDisplayValue("recordId:" + AdornmentType.LinkValues.TO_RECORD_FROM_TABLE_DYNAMIC, qqqTableRecord.getValueString("name"));
}
}
}
}
return (records);
}
}
@@ -0,0 +1,78 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizerInterface;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryOrGetInputInterface;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
import com.kingsrook.qqq.backend.core.model.tables.QQQTable;
import com.kingsrook.qqq.backend.core.processes.utils.GeneralProcessUtils;
/*******************************************************************************
**
*******************************************************************************/
public class ProcessTraceTableCustomizer implements TableCustomizerInterface
{
/***************************************************************************
**
***************************************************************************/
@Override
public List<QRecord> postQuery(QueryOrGetInputInterface queryInput, List<QRecord> records) throws QException
{
if(queryInput.getShouldGenerateDisplayValues())
{
////////////////////////////////////////////////////////////////////////////////////////////////
// for records with a keyRecordQqqTableId - look up that table name, then set a display-value //
// for the Link type adornment, to the keyRecordId record within that table. //
////////////////////////////////////////////////////////////////////////////////////////////////
Set<Serializable> tableIds = records.stream().map(r -> r.getValue("keyRecordQqqTableId")).filter(Objects::nonNull).collect(Collectors.toSet());
if(!tableIds.isEmpty())
{
Map<Serializable, QRecord> tableMap = GeneralProcessUtils.loadTableToMap(QQQTable.TABLE_NAME, "id", new QQueryFilter(new QFilterCriteria("id", QCriteriaOperator.IN, tableIds)));
for(QRecord record : records)
{
QRecord qqqTableRecord = tableMap.get(record.getValue("keyRecordQqqTableId"));
if(qqqTableRecord != null && record.getValue("keyRecordId") != null)
{
record.setDisplayValue("keyRecordId:" + AdornmentType.LinkValues.TO_RECORD_FROM_TABLE_DYNAMIC, qqqTableRecord.getValueString("name"));
}
}
}
}
return (records);
}
}
@@ -0,0 +1,80 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qqq.backend.core.actions.dashboard.widgets.RecordListWidgetRenderer;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
/*******************************************************************************
** factory/builder class, to create instances of RecordListWidgetRenderer for
** specific tables and/or processes within a table.
*******************************************************************************/
public class RecentProcessTracesWidgetBuilder
{
/***************************************************************************
**
***************************************************************************/
public static QWidgetMetaData buildWidget(String tableName)
{
QWidgetMetaData widgetMetaData = RecordListWidgetRenderer.widgetMetaDataBuilder(tableName + "RecentProcessTraces")
.withTableName(ProcessTrace.TABLE_NAME)
.withMaxRows(20)
.withLabel("Recent Process Traces")
.withFilter(new QQueryFilter()
.withCriteria("qqqTable.name", QCriteriaOperator.EQUALS, tableName)
.withCriteria("keyRecordId", QCriteriaOperator.EQUALS, "${input.id}")
.withOrderBy(new QFilterOrderBy("id", false))
).getWidgetMetaData();
return (widgetMetaData);
}
/***************************************************************************
**
***************************************************************************/
public static QWidgetMetaData buildWidget(String tableName, String processName)
{
QWidgetMetaData widgetMetaData = RecordListWidgetRenderer.widgetMetaDataBuilder(tableName + StringUtils.ucFirst(processName) + "RecentProcessTraces")
.withTableName(ProcessTrace.TABLE_NAME)
.withMaxRows(20)
.withLabel("Recent Process Traces")
.withFilter(new QQueryFilter()
.withCriteria("qqqProcess.name", QCriteriaOperator.EQUALS, processName)
.withCriteria("qqqTable.name", QCriteriaOperator.EQUALS, tableName)
.withCriteria("keyRecordId", QCriteriaOperator.EQUALS, "${input.id}")
.withOrderBy(new QFilterOrderBy("id", false))
).getWidgetMetaData();
return (widgetMetaData);
}
}
@@ -0,0 +1,67 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import com.kingsrook.qqq.backend.core.actions.tables.helpers.QueryStatConsumerInterface;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.querystats.QueryStat;
/*******************************************************************************
* Standard Process Trace's implementation of a QueryStat consumer.
*
* <p>That is, to accumulate them in the {@link ProcessTraceBackendActivityStatsManager},
* associated with the processTraceId in the user's session, so they can be stored
* when the process trace is stored.</p>
*******************************************************************************/
public class StandardProcessTraceQueryStatConsumer implements QueryStatConsumerInterface
{
private static final QLogger LOG = QLogger.getLogger(StandardProcessTraceQueryStatConsumer.class);
/***************************************************************************
*
***************************************************************************/
@Override
public void accept(QueryStat queryStat)
{
try
{
String processTraceId = QContext.getQSession().getValue(StandardProcessTracer.PROCESS_TRACE_ID_SESSION_KEY);
if(processTraceId == null)
{
return;
}
String backendName = QContext.getQInstance().getBackendForTable(queryStat.getTableName()).getName();
String backendAction = queryStat.getBackendAction();
ProcessTraceBackendActivityStatsManager.Key key = new ProcessTraceBackendActivityStatsManager.Key(backendName, queryStat.getTableName(), backendAction);
ProcessTraceBackendActivityStatsManager.getInstance().add(Long.valueOf(processTraceId), key, 1, queryStat.getRecordCount(), queryStat.getFirstResultMillis());
}
catch(Exception e)
{
LOG.warn("Error accepting query stats for process trace", e);
}
}
}
@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map;
import com.kingsrook.qbits.standardprocesstrace.StandardProcessTraceQBitConfig;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceKeyRecordMessage;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryLine;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryLineRecordInt;
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
@@ -55,6 +55,7 @@ import com.kingsrook.qqq.backend.core.model.session.QUser;
import com.kingsrook.qqq.backend.core.model.tables.QQQTableTableManager;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess;
import com.kingsrook.qqq.backend.core.processes.tracing.ProcessTracerInterface;
import com.kingsrook.qqq.backend.core.processes.tracing.ProcessTracerKeyRecordMessage;
import com.kingsrook.qqq.backend.core.processes.tracing.ProcessTracerMessage;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
@@ -75,6 +76,8 @@ public class StandardProcessTracer implements ProcessTracerInterface
private static StandardProcessTraceQBitConfig standardProcessTraceQBitConfig;
public static final String PROCESS_TRACE_ID_SESSION_KEY = StandardProcessTracer.class.getName() + ".processTraceId";
private Instant startTime;
private Long processTraceId;
@@ -98,6 +101,17 @@ public class StandardProcessTracer implements ProcessTracerInterface
.withProcessUUID(runProcessInput.getProcessUUID())));
processTraceId = insertOutput.getRecords().get(0).getValueLong("id");
////////////////////////////////////////////////////////////////////////////////////
// store the processTraceId in the session. this will be used by the //
// ProcessTraceQueryStatConsumer to associated QueryStats with this process trace //
////////////////////////////////////////////////////////////////////////////////////
if(QContext.getQSession() != null)
{
QContext.getQSession().setValue(PROCESS_TRACE_ID_SESSION_KEY, String.valueOf(processTraceId));
}
ProcessTraceBackendActivityStatsManager.getInstance().initProcess(processTraceId);
}
catch(QException e)
{
@@ -113,9 +127,29 @@ public class StandardProcessTracer implements ProcessTracerInterface
@Override
public void handleProcessResume(RunProcessInput runProcessInput)
{
/////////////////////////////////
// noop in this implementation //
/////////////////////////////////
try
{
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// if a user is resuming a process, e.g., from a frontend, then we want to put that processTraceId in their session //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(processTraceId == null)
{
QRecord processTrace = GetAction.execute(ProcessTrace.TABLE_NAME, Map.of("processUUID", runProcessInput.getProcessUUID()));
if(processTrace != null)
{
processTraceId = processTrace.getValueLong("id");
}
}
if(processTraceId != null && QContext.getQSession() != null)
{
QContext.getQSession().setValue(PROCESS_TRACE_ID_SESSION_KEY, String.valueOf(processTraceId));
}
}
catch(Exception e)
{
LOG.warn("Error resuming process trace", e, logPair("processUUID", () -> runProcessInput.getProcessUUID()));
}
}
@@ -170,7 +204,7 @@ public class StandardProcessTracer implements ProcessTracerInterface
{
try
{
if(message instanceof ProcessTraceKeyRecordMessage keyRecordMessage)
if(message instanceof ProcessTracerKeyRecordMessage keyRecordMessage)
{
Integer keyTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), keyRecordMessage.getTableName());
@@ -297,12 +331,21 @@ public class StandardProcessTracer implements ProcessTracerInterface
for(Serializable primaryKey : processSummaryLine.getPrimaryKeys())
{
Integer recordId = ValueUtils.getValueAsInteger(primaryKey);
if(recordId != null)
try
{
recordIntList.add(new ProcessTraceSummaryLineRecordInt()
.withQqqTableId(qqqTableId)
.withRecordId(recordId));
Integer recordId = ValueUtils.getValueAsInteger(primaryKey);
if(recordId != null)
{
recordIntList.add(new ProcessTraceSummaryLineRecordInt()
.withQqqTableId(qqqTableId)
.withRecordId(recordId));
}
}
catch(Exception e)
{
/////////////////////////////////////////////////////////////////////
// todo log (would be loud)? or, let not be integer maybe better? //
/////////////////////////////////////////////////////////////////////
}
}
}
@@ -319,12 +362,28 @@ public class StandardProcessTracer implements ProcessTracerInterface
new InsertAction().execute(new InsertInput(ProcessTraceSummaryLine.TABLE_NAME).withRecordEntities(summaryLines));
}
//////////////////////////////////////////
// build and store backend stat records //
//////////////////////////////////////////
if(QContext.getQInstance().getTable(ProcessTraceBackendActivityStats.TABLE_NAME) != null)
{
List<ProcessTraceBackendActivityStats> stats = ProcessTraceBackendActivityStatsManager.getInstance().getAndRemoveStats(processTraceId);
new InsertAction().execute(new InsertInput(ProcessTraceBackendActivityStats.TABLE_NAME).withRecordEntities(stats));
}
}
}
catch(Exception e)
{
LOG.warn("Error completing store of processTrace records.", e);
}
finally
{
if(QContext.getQSession() != null)
{
QContext.getQSession().removeValue(PROCESS_TRACE_ID_SESSION_KEY);
}
}
}
@@ -0,0 +1,86 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace;
import java.util.List;
import com.kingsrook.qbits.standardprocesstrace.utils.StandardProcessTraceQueryStatConsumer;
import com.kingsrook.qqq.backend.core.actions.tables.helpers.QueryStatManager;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.session.QSystemUserSession;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
/*******************************************************************************
* base class for tests for this QBit.
*******************************************************************************/
public class BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@BeforeEach
void baseBeforeEach() throws Exception
{
QInstance qInstance = defineQInstance();
new QInstanceValidator().validate(qInstance);
QContext.init(qInstance, new QSystemUserSession());
QueryStatManager queryStatManager = QueryStatManager.getInstance();
queryStatManager.start(qInstance, () -> new QSystemUserSession());
queryStatManager.setQueryStatConsumers(List.of(new StandardProcessTraceQueryStatConsumer()));
MemoryRecordStore.fullReset();
}
/*******************************************************************************
**
*******************************************************************************/
@AfterEach
void afterEach()
{
MemoryRecordStore.fullReset();
QueryStatManager.getInstance().stop();
}
/***************************************************************************
**
***************************************************************************/
private QInstance defineQInstance() throws QException
{
return new StandardProcessTraceTestApplication().defineQInstance();
}
}
@@ -0,0 +1,234 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import com.kingsrook.qbits.standardprocesstrace.utils.StandardProcessTracer;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.instances.AbstractQQQApplication;
import com.kingsrook.qqq.backend.core.model.actions.processes.ProcessSummaryLine;
import com.kingsrook.qqq.backend.core.model.actions.processes.ProcessSummaryLineInterface;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
import com.kingsrook.qqq.backend.core.model.actions.processes.Status;
import com.kingsrook.qqq.backend.core.model.backends.QQQBackendsMetaDataProvider;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.MetaDataProducerMultiOutput;
import com.kingsrook.qqq.backend.core.model.metadata.QAuthenticationType;
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.audits.AuditLevel;
import com.kingsrook.qqq.backend.core.model.metadata.audits.QAuditRules;
import com.kingsrook.qqq.backend.core.model.metadata.authentication.QAuthenticationMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppSection;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.processes.QQQProcessesMetaDataProvider;
import com.kingsrook.qqq.backend.core.model.tables.QQQTablesMetaDataProvider;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryBackendModule;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.AbstractTransformStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.ExtractViaQueryStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.LoadViaInsertStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess;
/*******************************************************************************
* test application (e.g., QInstance) for this QBit's tests.
*******************************************************************************/
public class StandardProcessTraceTestApplication extends AbstractQQQApplication
{
public static final String MEMORY_BACKEND_NAME = "memory";
public static final String TABLE_NAME_PERSON = "person";
public static final String TABLE_NAME_ORDER = "order";
public static final String PROCESS_NAME_PLACE_ORDERS = "placeOrders";
/***************************************************************************
**
***************************************************************************/
@Override
public QInstance defineQInstance() throws QException
{
QInstance qInstance = new QInstance();
qInstance.setAuthentication(new QAuthenticationMetaData().withType(QAuthenticationType.FULLY_ANONYMOUS));
qInstance.addBackend(new QBackendMetaData()
.withName(MEMORY_BACKEND_NAME)
.withBackendType(MemoryBackendModule.class));
//////////////////////////////
// add tables table and PVS //
//////////////////////////////
new QQQTablesMetaDataProvider().defineAll(qInstance, MEMORY_BACKEND_NAME, MEMORY_BACKEND_NAME, null);
new QQQProcessesMetaDataProvider().defineAll(qInstance, MEMORY_BACKEND_NAME, MEMORY_BACKEND_NAME, null);
new QQQBackendsMetaDataProvider().defineAll(qInstance, MEMORY_BACKEND_NAME, MEMORY_BACKEND_NAME, null);
//////////////////////
// produce our qbit //
//////////////////////
StandardProcessTraceQBitProducer producer = new StandardProcessTraceQBitProducer()
.withStandardProcessTraceQBitConfig(new StandardProcessTraceQBitConfig()
.withTableMetaDataCustomizer((QInstance instance, QTableMetaData table) ->
{
table.setBackendName(MEMORY_BACKEND_NAME);
return (table);
})
.withIncludeBackendActivityStats(true));
MetaDataProducerMultiOutput allQBitMetaData = producer.produce(qInstance);
allQBitMetaData.addSelfToInstance(qInstance);
////////////////////////////////////////
// produce some test tables //
// note - nice to be a qbit this too? //
////////////////////////////////////////
qInstance.addTable(new QTableMetaData()
.withName(TABLE_NAME_PERSON)
.withBackendName(MEMORY_BACKEND_NAME)
.withPrimaryKeyField("id")
.withField(new QFieldMetaData("id", QFieldType.INTEGER).withIsEditable(false))
.withField(new QFieldMetaData("firstName", QFieldType.STRING).withIsEditable(true))
.withField(new QFieldMetaData("lastName", QFieldType.STRING).withIsEditable(true))
.withCapability(Capability.QUERY_STATS)
);
qInstance.addTable(new QTableMetaData()
.withName(TABLE_NAME_ORDER)
.withBackendName(MEMORY_BACKEND_NAME)
.withPrimaryKeyField("id")
.withField(new QFieldMetaData("id", QFieldType.INTEGER).withIsEditable(false))
.withField(new QFieldMetaData("orderNo", QFieldType.STRING).withIsEditable(true))
.withField(new QFieldMetaData("storeId", QFieldType.INTEGER).withIsEditable(true))
.withField(new QFieldMetaData("shipTo", QFieldType.STRING).withIsEditable(true))
.withCapability(Capability.QUERY_STATS)
);
qInstance.addProcess(StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(PROCESS_NAME_PLACE_ORDERS)
.withTableName(TABLE_NAME_PERSON)
.withSourceTable(TABLE_NAME_PERSON)
.withDestinationTable(TABLE_NAME_ORDER)
.withExtractStepClass(ExtractViaQueryStep.class)
.withTransformStepClass(PlaceOrdersProcessTransformStep.class)
.withLoadStepClass(LoadViaInsertStep.class)
.getProcessMetaData()
.withProcessTracerCodeReference(new QCodeReference(StandardProcessTracer.class))
);
///////////////////////////////////////////
// turn off audits (why on by default??) //
///////////////////////////////////////////
qInstance.getTables().values().forEach(t -> t.setAuditRules(new QAuditRules().withAuditLevel(AuditLevel.NONE)));
/////////////////
// create apps //
/////////////////
qInstance.addApp(new QAppMetaData()
.withName("logs")
.withIcon(new QIcon("history_edu"))
.withSection(StandardProcessTraceQBitProducer.getAppSection(qInstance)));
qInstance.addApp(new QAppMetaData()
.withName("testData")
.withIcon(new QIcon("dataset"))
.withSection(new QAppSection()
.withName("people")
.withTables(List.of(TABLE_NAME_PERSON))));
return qInstance;
}
/***************************************************************************
* test process transformer - for each input person, creates an output order (to insert)
***************************************************************************/
public static class PlaceOrdersProcessTransformStep extends AbstractTransformStep
{
private ProcessSummaryLine okLine = new ProcessSummaryLine(Status.OK)
.withMessageSuffix("")
.withSingularFutureMessage("will get a new order")
.withPluralFutureMessage("will get new orders")
.withSingularPastMessage("got a new order")
.withPluralPastMessage("got new orders");
private ProcessSummaryLine errorLine = new ProcessSummaryLine(Status.ERROR)
.withMessageSuffix("")
.withSingularFutureMessage("will not get a new order")
.withPluralFutureMessage("will not get new orders")
.withSingularPastMessage("did not get a new order")
.withPluralPastMessage("did not get new orders");
/***************************************************************************
*
***************************************************************************/
@Override
public ArrayList<ProcessSummaryLineInterface> getProcessSummary(RunBackendStepOutput runBackendStepOutput, boolean isForResultScreen)
{
ArrayList<ProcessSummaryLineInterface> rs = new ArrayList<>();
okLine.addSelfToListIfAnyCount(rs);
errorLine.addSelfToListIfAnyCount(rs);
return rs;
}
/***************************************************************************
*
***************************************************************************/
@Override
public void runOnePage(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
{
for(QRecord personRecord : runBackendStepInput.getRecords())
{
////////////////////////////////////////
// don't let Mr. Burns order anything //
////////////////////////////////////////
if("Burns".equals(personRecord.getValueString("lastName")))
{
errorLine.incrementCountAndAddPrimaryKey(personRecord.getValue("id"));
continue;
}
QRecord orderRecord = new QRecord()
.withValue("orderNo", UUID.randomUUID().toString())
.withValue("shipTo", personRecord.getValueString("firstName") + " " + personRecord.getValueString("lastName"));
runBackendStepOutput.addRecord(orderRecord);
okLine.incrementCountAndAddPrimaryKey(personRecord.getValue("id"));
}
}
}
}
@@ -0,0 +1,115 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import java.util.List;
import java.util.concurrent.TimeUnit;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.logging.QCollectingLogger;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.utils.SleepUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for ProcessTraceBackendActivityStatsManager
*******************************************************************************/
class ProcessTraceBackendActivityStatsManagerTest
{
ProcessTraceBackendActivityStatsManager.Key key = new ProcessTraceBackendActivityStatsManager.Key("b", "t", "a");
/*******************************************************************************
**
*******************************************************************************/
@AfterEach
void afterEach()
{
ProcessTraceBackendActivityStatsManager manager = ProcessTraceBackendActivityStatsManager.getInstance();
manager.shutdown();
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testMaxAgeLarger() throws QException
{
long processTraceId = 1L;
QCollectingLogger collectingLogger = QLogger.activateCollectingLoggerForClass(ProcessTraceBackendActivityStatsManager.class);
ProcessTraceBackendActivityStatsManager manager = ProcessTraceBackendActivityStatsManager.getInstance();
manager.initProcess(processTraceId);
manager.add(processTraceId, key, 1, 2, 3);
manager.setCleanupIntervalMillis(10);
manager.setCleanupMaxAge(100);
SleepUtils.sleep(50, TimeUnit.MILLISECONDS);
QLogger.deactivateCollectingLoggerForClass(ProcessTraceBackendActivityStatsManager.class);
assertThat(collectingLogger.getCollectedMessages()).allMatch(clm -> clm.getMessage().contains("\"size\":1"));
List<ProcessTraceBackendActivityStats> stats = manager.getAndRemoveStats(processTraceId);
assertEquals(1, stats.size());
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testMaxAgeSmaller() throws QException
{
long processTraceId = 2L;
QCollectingLogger collectingLogger = QLogger.activateCollectingLoggerForClass(ProcessTraceBackendActivityStatsManager.class);
ProcessTraceBackendActivityStatsManager manager = ProcessTraceBackendActivityStatsManager.getInstance();
manager.initProcess(processTraceId);
manager.add(processTraceId, key, 1, 2, 3);
manager.setCleanupIntervalMillis(5);
manager.setCleanupMaxAge(20);
SleepUtils.sleep(50, TimeUnit.MILLISECONDS);
QLogger.deactivateCollectingLoggerForClass(ProcessTraceBackendActivityStatsManager.class);
assertThat(collectingLogger.getCollectedMessages()).anyMatch(clm -> clm.getMessage().contains("\"size\":1"));
assertThat(collectingLogger.getCollectedMessages()).anyMatch(clm -> clm.getMessage().contains("\"size\":0"));
List<ProcessTraceBackendActivityStats> stats = manager.getAndRemoveStats(processTraceId);
assertEquals(0, stats.size());
////////////////////////////////////////////////////////////////////////////////////////////
// make sure even after a cleanup, we don't fail if we do try to add values for a process //
////////////////////////////////////////////////////////////////////////////////////////////
manager.add(processTraceId, key, 1, 2, 3);
stats = manager.getAndRemoveStats(processTraceId);
assertEquals(1, stats.size());
}
}
@@ -0,0 +1,177 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2025. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qbits.standardprocesstrace.utils;
import java.util.List;
import com.kingsrook.qbits.standardprocesstrace.BaseTest;
import com.kingsrook.qbits.standardprocesstrace.StandardProcessTraceTestApplication;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTrace;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceBackendActivityStats;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryLine;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryLineRecordInt;
import com.kingsrook.qbits.standardprocesstrace.model.ProcessTraceSummaryStatusEnum;
import com.kingsrook.qqq.backend.core.actions.processes.QProcessCallbackFactory;
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.tables.QQQTableTableManager;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/*******************************************************************************
** Unit test for StandardProcessTracer
*******************************************************************************/
class StandardProcessTracerTest extends BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
insertHomerMargeAndMrBurns();
////////////////////////////////////////
// run process skipping backend steps //
////////////////////////////////////////
RunProcessInput input = new RunProcessInput();
input.setProcessName(StandardProcessTraceTestApplication.PROCESS_NAME_PLACE_ORDERS);
input.setCallback(QProcessCallbackFactory.forFilter(new QQueryFilter()));
input.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.SKIP);
new RunProcessAction().execute(input);
baseAssertionsAfterProcess();
Integer personTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), StandardProcessTraceTestApplication.TABLE_NAME_PERSON);
Integer orderTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), StandardProcessTraceTestApplication.TABLE_NAME_ORDER);
List<QRecord> processTraceBackendActivityStatRecords = QueryAction.execute(ProcessTraceBackendActivityStats.TABLE_NAME, new QQueryFilter());
assertThat(processTraceBackendActivityStatRecords)
.hasSizeGreaterThanOrEqualTo(2)
.anyMatch(r -> r.getValue("qqqTableId").equals(personTableId) && r.getValue("actionName").equals(QueryAction.class.getSimpleName()) && r.getValueInteger("callCount").equals(1) && r.getValueInteger("recordCount").equals(3))
.anyMatch(r -> r.getValue("qqqTableId").equals(orderTableId) && r.getValue("actionName").equals(InsertAction.class.getSimpleName()) && r.getValueInteger("callCount").equals(1) && r.getValueInteger("recordCount").equals(2));
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void testResumingFrontendProcess() throws QException
{
insertHomerMargeAndMrBurns();
//////////////////////////////////////
// start process - break at preview //
//////////////////////////////////////
RunProcessInput input = new RunProcessInput();
input.setProcessName(StandardProcessTraceTestApplication.PROCESS_NAME_PLACE_ORDERS);
input.setCallback(QProcessCallbackFactory.forFilter(new QQueryFilter()));
input.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.BREAK);
RunProcessOutput output = new RunProcessAction().execute(input);
/////////////////////////////////////
// continue to execute the process //
/////////////////////////////////////
input.setProcessUUID(output.getProcessUUID());
input.setStartAfterStep(output.getProcessState().getNextStepName().get());
new RunProcessAction().execute(input);
baseAssertionsAfterProcess();
Integer personTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), StandardProcessTraceTestApplication.TABLE_NAME_PERSON);
Integer orderTableId = QQQTableTableManager.getQQQTableId(QContext.getQInstance(), StandardProcessTraceTestApplication.TABLE_NAME_ORDER);
List<QRecord> processTraceBackendActivityStatRecords = QueryAction.execute(ProcessTraceBackendActivityStats.TABLE_NAME, new QQueryFilter());
assertThat(processTraceBackendActivityStatRecords)
.hasSizeGreaterThanOrEqualTo(2)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// this time, there'll be 2 calls to the query (for preview, and execute steps), for twice as many records total //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
.anyMatch(r -> r.getValue("qqqTableId").equals(personTableId) && r.getValue("actionName").equals(QueryAction.class.getSimpleName()) && r.getValueInteger("callCount").equals(2) && r.getValueInteger("recordCount").equals(6))
.anyMatch(r -> r.getValue("qqqTableId").equals(orderTableId) && r.getValue("actionName").equals(InsertAction.class.getSimpleName()) && r.getValueInteger("callCount").equals(1) && r.getValueInteger("recordCount").equals(2));
}
/***************************************************************************
*
***************************************************************************/
private static void insertHomerMargeAndMrBurns() throws QException
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// insert 3 people to run through the process. //
// the process will insert an order for Homer & Marge, but is hard-coded to make an error for Mr. Burns. //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
new InsertAction().execute(new InsertInput(StandardProcessTraceTestApplication.TABLE_NAME_PERSON).withRecords(List.of(
new QRecord().withValue("id", 100).withValue("firstName", "Homer").withValue("lastName", "Simpson"),
new QRecord().withValue("id", 101).withValue("firstName", "Marge").withValue("lastName", "Simpson"),
new QRecord().withValue("id", 102).withValue("firstName", "Mr.").withValue("lastName", "Burns")
)));
}
/***************************************************************************
*
***************************************************************************/
private static void baseAssertionsAfterProcess() throws QException
{
List<QRecord> processTraceRecords = QueryAction.execute(ProcessTrace.TABLE_NAME, new QQueryFilter());
assertEquals(1, processTraceRecords.size());
List<QRecord> processTraceSummaryLineRecords = QueryAction.execute(ProcessTraceSummaryLine.TABLE_NAME, new QQueryFilter());
assertEquals(2, processTraceSummaryLineRecords.size());
QRecord okSummaryLineRecord = processTraceSummaryLineRecords.stream().filter(r -> r.getValueString("status").equals(ProcessTraceSummaryStatusEnum.OK.getPossibleValueId())).findFirst().get();
assertNotNull(okSummaryLineRecord);
assertEquals(2, okSummaryLineRecord.getValueInteger("recordCount"));
List<QRecord> okRecordInts = QueryAction.execute(ProcessTraceSummaryLineRecordInt.TABLE_NAME, new QQueryFilter(new QFilterCriteria("processTraceSummaryLineId", QCriteriaOperator.EQUALS, okSummaryLineRecord.getValueLong("id"))));
assertEquals(2, okRecordInts.size());
assertThat(okRecordInts).allMatch(r -> r.getValueInteger("recordId").equals(100) || r.getValueInteger("recordId").equals(101));
QRecord errorSummaryLineRecord = processTraceSummaryLineRecords.stream().filter(r -> r.getValueString("status").equals(ProcessTraceSummaryStatusEnum.ERROR.getPossibleValueId())).findFirst().get();
assertNotNull(errorSummaryLineRecord);
assertEquals(1, errorSummaryLineRecord.getValueInteger("recordCount"));
List<QRecord> errorRecordInts = QueryAction.execute(ProcessTraceSummaryLineRecordInt.TABLE_NAME, new QQueryFilter(new QFilterCriteria("processTraceSummaryLineId", QCriteriaOperator.EQUALS, errorSummaryLineRecord.getValueLong("id"))));
assertEquals(1, errorRecordInts.size());
assertEquals(102, errorRecordInts.get(0).getValueInteger("recordId"));
}
}