Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
588ae52cd9
|
||
|
|
cad99545b2
|
||
|
|
13eebd9d9c | ||
|
|
4565a12cd4
|
||
|
|
dff3077f50
|
||
|
|
fb856fdb39
|
||
|
|
7ed9d0b81e
|
No files matched your search
@@ -9,6 +9,9 @@ All notable changes to this project are documented here. The format follows Keep
|
||||
- Allow manual Tested Pages inserts with a URL. Validate absolute HTTPS URLs and fill in the site, path and Manual source automatically; validate URL edits too.
|
||||
|
||||
### Added
|
||||
- Foreign keys for every reference between the QBit's tables (changesets 12-26): findings and reports cascade with their run, comparisons with their site change; optional pointers (likely cause, first and confirmation run, a run's site change) are set to NULL; tested pages and budgets with history cannot be deleted (disable them instead). Rows whose parent is already missing are recorded in `qqq_fk_quarantine`, then nulled or (NOT NULL columns, PostgreSQL) deleted, so the upgrade never fails. Foreign key columns are indexed. A PostgreSQL guardrail test fails when a new reference lacks its constraint.
|
||||
- Every `web_performance_*` table and the Performance app carry help saying what the table is for and how its rows get created (`help/web-performance.yaml`, applied by `WebPerfHelp`; host help is never overridden). A Setup card at the top of the home lists tested pages, the lab runner, budgets (reference defaults or your own) and Google field data, each with its state and next step, using the runtime's own resolution. `WebPerfTablesGuardrailTest` fails when a table is unused, unexplained or lacks that help; `WebPerfDefaultsChangelogTest` runs the shipped changelog and its seeded budgets through real Liquibase.
|
||||
- `reportRetentionDays` is now enforced: with a value above 0, Lighthouse Reports older than that many days are deleted after a result is stored, in batches, at most once an hour per process (runs, scores and findings stay). It was documented but nothing read it; the default 0 still keeps everything.
|
||||
- Record deploy and external site changes once, queue settled retests, and attribute lab runs to the observed build and CDN stage.
|
||||
- Evaluate enabled lab and URL CrUX budgets; retain breaches, confirmation evidence, automatic recovery and accurate open counts in the standard regression records.
|
||||
- Confirm statistical lab regressions with a median of three, reset baselines on Lighthouse major changes, and detect deterministic category/audit failures.
|
||||
|
||||
@@ -68,6 +68,10 @@ Tier, Scope, Source, Strategy, Metric, Comparator and Severity use dropdowns wit
|
||||
| `web_performance_change_event` (Site Changes) | probes, other QBits | read-only |
|
||||
| `web_performance_comparison` (Before and After) | the QBit | read-only |
|
||||
|
||||
### Starter defaults and empty-state help
|
||||
|
||||
The changelog's changeset 10 seeds 13 reference budgets (Google's "good" thresholds and the Lighthouse category bands); nothing else is seeded. The target table is filled by Sync pages from sitemap, and the lab, finding, report, field, regression, change and comparison tables are filled by the qbit as it runs (empty is a normal start). Every table's help (`help/web-performance.yaml`, shown on the table screen) says how its rows get created, and the Setup card on the home shows what still needs doing. Budgets with source RUM are not evaluated yet (no real-user source is wired); LAB and CRUX budgets are.
|
||||
|
||||
## Permissions
|
||||
|
||||
Tables and the app use `READ_WRITE_PERMISSIONS` with the base name `web_performance` (configurable), which gives `web_performance.read` and `web_performance.write`. Processes will add `web_performance.test`, `web_performance.manage` and `web_performance.admin` (design §8.1). No table stores a secret.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# Upgrading
|
||||
|
||||
## Table help, Setup card and `reportRetentionDays` (unreleased)
|
||||
|
||||
No DDL change, no new changeset and no host include change. The qbit now fills empty `help` slots on its app and tables (help a host set is kept) and adds a Setup widget to the Performance home. `reportRetentionDays` (default 0, keep forever) is now enforced: set it above 0 only if you want Lighthouse Reports older than that many days deleted.
|
||||
@@ -22,6 +22,8 @@
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<jacoco.version>0.8.15</jacoco.version>
|
||||
<liquibase.version>4.33.0</liquibase.version>
|
||||
<testcontainers.version>1.21.4</testcontainers.version>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
@@ -82,6 +84,13 @@
|
||||
<version>2.2.220</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- WebPerfDefaultsChangelogTest runs the shipped changelog (with its seeded budgets) through real Liquibase. -->
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<version>4.33.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
@@ -93,6 +102,31 @@
|
||||
<version>3.27.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- The foreign key guardrail runs the changelog with Liquibase on PostgreSQL (Docker). -->
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<version>${liquibase.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.7.14</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -191,6 +191,7 @@ public class WebPerfQBitProducer implements QBitMetaDataProducer<WebPerfQBitConf
|
||||
qInstance.addQBit(getQBitMetaData());
|
||||
new WebPerfRuntime(qBitConfig).addSelfToInstance(qInstance);
|
||||
new WebPerfMetaData(qBitConfig).addTo(qInstance);
|
||||
com.kingsrook.qbits.webperf.metadata.WebPerfHelp.apply(qInstance, qBitConfig);
|
||||
|
||||
LOG.info("Web performance registered", logPair("tablePrefix", qBitConfig.getTableNamePrefix()), logPair("app", qBitConfig.getAppName()),
|
||||
logPair("siteBaseUrl", qBitConfig.getSiteBaseUrl()), logPair("features", qBitConfig.getFeatures()),
|
||||
|
||||
@@ -46,7 +46,13 @@ public class WebPerfRuntime implements QSupplementalInstanceMetaData
|
||||
public static final String NAME_PREFIX = "webPerformance.";
|
||||
public static final String INSTANCE_FIELD = "webPerformanceInstance";
|
||||
|
||||
/** At most one report-retention pass an hour per process; the first one waits so restarts and deploys do not each trigger a pass. */
|
||||
public static final long REPORT_PRUNE_INTERVAL_MILLIS = 60L * 60 * 1000;
|
||||
public static final long REPORT_PRUNE_FIRST_DELAY = 5L * 60 * 1000;
|
||||
|
||||
private final WebPerfQBitConfig config;
|
||||
private final java.util.concurrent.atomic.AtomicLong lastReportPruneMillis = new java.util.concurrent.atomic.AtomicLong(
|
||||
System.currentTimeMillis() - REPORT_PRUNE_INTERVAL_MILLIS + REPORT_PRUNE_FIRST_DELAY);
|
||||
|
||||
|
||||
|
||||
@@ -133,6 +139,29 @@ public class WebPerfRuntime implements QSupplementalInstanceMetaData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Whether a report-retention pass is due; true for exactly one caller per
|
||||
** hour (shared by every worker of this process).
|
||||
*******************************************************************************/
|
||||
public boolean reportPruneDue()
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastReportPruneMillis.get();
|
||||
return (now - last >= REPORT_PRUNE_INTERVAL_MILLIS && lastReportPruneMillis.compareAndSet(last, now));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** For tests: make the next reportPruneDue() true.
|
||||
*******************************************************************************/
|
||||
public void allowReportPruneNow()
|
||||
{
|
||||
lastReportPruneMillis.set(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The lab runner: the configured one, else PageSpeed Insights with the
|
||||
** Google API key, else null (no key: lab tests are off).
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.webperf.metadata;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import com.kingsrook.qbits.webperf.WebPerfQBitConfig;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.QHelpContent;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Applies help/web-performance.yaml (the QQQ help-bundle format) to the
|
||||
** Performance app and its web_performance_* tables: what each table is for and
|
||||
** how its rows get created, shown on the table screen and when it is empty.
|
||||
** STAND-IN(core=QRun-IO/qqq#1198, removeBy=4.1.0-RC.9): replace with HelpBundles.register once the pinned QQQ
|
||||
** release includes it; the bundle file stays the same.
|
||||
*******************************************************************************/
|
||||
public final class WebPerfHelp
|
||||
{
|
||||
public static final String RESOURCE = "/help/web-performance.yaml";
|
||||
public static final String SLOT = "help";
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Utility class.
|
||||
*******************************************************************************/
|
||||
private WebPerfHelp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The bundle's entries by key, validated (fails startup if malformed).
|
||||
*******************************************************************************/
|
||||
public static Map<String, JsonNode> entries() throws QException
|
||||
{
|
||||
try(InputStream stream = WebPerfHelp.class.getResourceAsStream(RESOURCE))
|
||||
{
|
||||
if(stream == null)
|
||||
{
|
||||
throw (new IOException("missing resource"));
|
||||
}
|
||||
JsonNode bundle = new ObjectMapper(new YAMLFactory()).readTree(stream);
|
||||
if(!"web-performance".equals(bundle.path("bundle").asText()) || !"QBIT".equals(bundle.path("layer").asText()))
|
||||
{
|
||||
throw (new IOException("invalid bundle header"));
|
||||
}
|
||||
Map<String, JsonNode> entries = new LinkedHashMap<>();
|
||||
for(JsonNode entry : bundle.path("entries"))
|
||||
{
|
||||
String key = entry.path("key").asText();
|
||||
String summary = entry.path("summary").asText();
|
||||
if(key.isBlank() || summary.isBlank() || summary.length() > 120 || entry.path("content").asText().isBlank() || entries.put(key, entry) != null)
|
||||
{
|
||||
throw (new IOException("invalid or duplicate entry: " + key));
|
||||
}
|
||||
}
|
||||
return (entries);
|
||||
}
|
||||
catch(IOException | RuntimeException e)
|
||||
{
|
||||
throw (new QException("Could not load " + RESOURCE, e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Apply the help to the app and every web_performance_* table in the instance
|
||||
** (names carry the config's prefix, if any). A host's own help on a table
|
||||
** is kept (the bundle only fills the slot).
|
||||
*******************************************************************************/
|
||||
public static void apply(QInstance qInstance, WebPerfQBitConfig config) throws QException
|
||||
{
|
||||
for(Map.Entry<String, JsonNode> entry : entries().entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
String name = key.substring(key.indexOf(':') + 1, key.indexOf(';'));
|
||||
if(key.startsWith("table:"))
|
||||
{
|
||||
QTableMetaData table = qInstance.getTable(config.applyPrefix(name.startsWith(WebPerfQBitConfig.DEFAULT_TABLE_PREFIX) ? name.substring(WebPerfQBitConfig.DEFAULT_TABLE_PREFIX.length()) : name));
|
||||
if(table != null && (table.getHelpContent() == null || !table.getHelpContent().containsKey(SLOT)))
|
||||
{
|
||||
table.withHelpContent(SLOT, content(entry.getValue()));
|
||||
}
|
||||
}
|
||||
else if(key.startsWith("app:"))
|
||||
{
|
||||
QAppMetaData app = qInstance.getApp(config.getAppName());
|
||||
if(app != null && (app.getHelpContent() == null || !app.getHelpContent().containsKey(SLOT)))
|
||||
{
|
||||
app.withHelpContent(SLOT, content(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Summary as the first paragraph, then the content, as markdown.
|
||||
*******************************************************************************/
|
||||
static QHelpContent content(JsonNode entry)
|
||||
{
|
||||
return (new QHelpContent().withContentAsMarkdown(entry.path("summary").asText().strip() + "\n\n" + entry.path("content").asText().strip()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -129,6 +129,7 @@ public final class WebPerfMetaData
|
||||
{
|
||||
qInstance.addProcess(process);
|
||||
}
|
||||
addWidget(qInstance, WebPerfWidgets.SETUP, "Setup", WidgetType.HTML, WebPerfWidgets.Setup.class);
|
||||
addWidget(qInstance, WebPerfWidgets.SITE_SCORES, "Site Scores", WidgetType.HTML, WebPerfWidgets.SiteScores.class);
|
||||
addWidget(qInstance, WebPerfWidgets.TREND, "Performance Trend", WidgetType.LINE_CHART, WebPerfWidgets.Trend.class);
|
||||
addWidget(qInstance, WebPerfWidgets.SLOWEST_PAGES, "Slowest Pages", WidgetType.HTML, WebPerfWidgets.SlowestPages.class);
|
||||
|
||||
@@ -76,6 +76,9 @@ public class WebPerfService
|
||||
/** Statuses that still hold a place in the queue (a new request merges into them). */
|
||||
public static final List<String> OPEN_STATUSES = List.of("QUEUED", "RUNNING");
|
||||
|
||||
static final int REPORT_BATCH = 500;
|
||||
static final int REPORT_MAX_BATCHES = 20;
|
||||
|
||||
private final WebPerfRuntime runtime;
|
||||
private final WebPerfStore store;
|
||||
private final WebPerfQBitConfig config;
|
||||
@@ -608,6 +611,45 @@ public class WebPerfService
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Apply reportRetentionDays: delete Lighthouse Reports older than that many
|
||||
** days (0 keeps them forever). The run, its scores and findings stay; only
|
||||
** the full compressed response goes. Runs after a result is committed (a
|
||||
** failure here never loses a run's evidence), at most once an hour per
|
||||
** process (WebPerfRuntime.reportPruneDue, shared by the workers), in batches
|
||||
** of REPORT_BATCH rows, at most REPORT_MAX_BATCHES per pass. There is no
|
||||
** table for state shared across replicas, so each replica keeps its own
|
||||
** hourly limit; passes are bounded and idempotent, so overlapping replicas
|
||||
** only repeat one cheap query.
|
||||
*******************************************************************************/
|
||||
void pruneReports()
|
||||
{
|
||||
int days = runtime.getConfig().getReportRetentionDays();
|
||||
if(days <= 0 || !runtime.reportPruneDue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
java.sql.Timestamp cutoff = WebPerfStore.utc(Instant.now().minus(java.time.Duration.ofDays(days)));
|
||||
for(int batch = 0; batch < REPORT_MAX_BATCHES; batch++)
|
||||
{
|
||||
int deleted = store.update("DELETE FROM {lab_report} WHERE id IN (SELECT id FROM {lab_report} WHERE create_date < ? ORDER BY id FETCH FIRST " + REPORT_BATCH + " ROWS ONLY)", cutoff);
|
||||
if(deleted < REPORT_BATCH)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(SQLException | RuntimeException e)
|
||||
{
|
||||
LOG.warn("Could not prune old Lighthouse Reports", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Store a successful response: the run's scores and metrics, its findings,
|
||||
** the compressed report, and the page's latest results.
|
||||
@@ -619,6 +661,7 @@ public class WebPerfService
|
||||
new WebPerfService(runtime, tx).storeResult(runId, run, attempts, parsed, response);
|
||||
return (null);
|
||||
});
|
||||
pruneReports();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.webperf.widgets;
|
||||
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.webperf.WebPerfFeature;
|
||||
import com.kingsrook.qbits.webperf.WebPerfQBitConfig;
|
||||
import com.kingsrook.qbits.webperf.WebPerfRuntime;
|
||||
import com.kingsrook.qbits.webperf.WebPerfSchema;
|
||||
import com.kingsrook.qbits.webperf.store.WebPerfStore;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** What is set up on the Performance home and what is next: whether pages have
|
||||
** been synced, whether budgets exist (and whether they are only the seeded
|
||||
** defaults), and whether the lab runner and Google field data are configured.
|
||||
** The checks use the runtime's own resolution (WebPerfRuntime.labRunner() and
|
||||
** cruxClient(), the url source), so the card never says "needs setup" for
|
||||
** something the runtime would in fact run.
|
||||
*******************************************************************************/
|
||||
public final class WebPerfSetupStatus
|
||||
{
|
||||
public static final String SET_UP = "Set up";
|
||||
public static final String NEEDS_SETUP = "Needs setup";
|
||||
public static final String DEFAULTS = "Using defaults";
|
||||
public static final String OPTIONAL = "Optional";
|
||||
public static final String OFF = "Off";
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** One line of the card.
|
||||
**
|
||||
** @param name what is being set up
|
||||
** @param state one of the state constants
|
||||
** @param detail what the state is (counts, and the next step)
|
||||
** @param tableName the table to open (prefixed name), or null
|
||||
*******************************************************************************/
|
||||
public record Item(String name, String state, String detail, String tableName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Utility class.
|
||||
*******************************************************************************/
|
||||
private WebPerfSetupStatus()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The card's lines, in setup order.
|
||||
*******************************************************************************/
|
||||
public static List<Item> items(WebPerfRuntime runtime) throws SQLException
|
||||
{
|
||||
WebPerfQBitConfig config = runtime.getConfig();
|
||||
WebPerfStore store = runtime.store();
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// tested pages: synced from the url source (sitemap) or added by hand //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
long pages = count(store, "SELECT COUNT(*) AS n FROM {target}");
|
||||
String target = config.applyPrefix(WebPerfSchema.TARGET);
|
||||
if(pages > 0)
|
||||
{
|
||||
items.add(new Item("Tested pages", SET_UP, pages + " page" + (pages == 1 ? "" : "s") + " are tracked.", target));
|
||||
}
|
||||
else if(config.getUrlSource() == null)
|
||||
{
|
||||
items.add(new Item("Tested pages", NEEDS_SETUP, "No pages yet and no page source is configured. Add a page by hand, or have the host set a URL source (the sitemap) in the qbit config.", target));
|
||||
}
|
||||
else
|
||||
{
|
||||
items.add(new Item("Tested pages", NEEDS_SETUP, "No pages yet. Run “Sync pages from sitemap” on Tested Pages.", target));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// lab runner: the configured one, else PageSpeed Insights with a key //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
if(!config.isOn(WebPerfFeature.LAB))
|
||||
{
|
||||
items.add(new Item("Lab tests (Lighthouse)", OFF, "The LAB feature is turned off in the qbit config.", null));
|
||||
}
|
||||
else if(runtime.labRunner() != null)
|
||||
{
|
||||
items.add(new Item("Lab tests (Lighthouse)", SET_UP, "A lab runner is configured. Use “Run site audit” on Tested Pages, or wait for the schedule.", config.applyPrefix(WebPerfSchema.LAB_RUN)));
|
||||
}
|
||||
else
|
||||
{
|
||||
items.add(new Item("Lab tests (Lighthouse)", NEEDS_SETUP, "No Google API key is configured, so lab tests cannot run. The host sets googleApiKey in the qbit config (read from an environment variable).", null));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// budgets: the seeded reference budgets, or the admin's own //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
long budgets = count(store, "SELECT COUNT(*) AS n FROM {budget} WHERE enabled = TRUE");
|
||||
long custom = count(store, "SELECT COUNT(*) AS n FROM {budget} WHERE enabled = TRUE AND (seeded IS NULL OR seeded = FALSE)");
|
||||
String budget = config.applyPrefix(WebPerfSchema.BUDGET);
|
||||
if(budgets == 0)
|
||||
{
|
||||
items.add(new Item("Budgets", NEEDS_SETUP, "No budget is enabled, so nothing is flagged as too slow. Add one, or enable the reference budgets.", budget));
|
||||
}
|
||||
else if(custom == 0)
|
||||
{
|
||||
items.add(new Item("Budgets", DEFAULTS, budgets + " reference budgets (Google's “good” thresholds) are enabled. Edit them or add your own.", budget));
|
||||
}
|
||||
else
|
||||
{
|
||||
items.add(new Item("Budgets", SET_UP, budgets + " budgets are enabled, " + custom + " of them your own.", budget));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Google field data (CrUX) //
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
if(!config.isOn(WebPerfFeature.FIELD_CRUX))
|
||||
{
|
||||
items.add(new Item("Google field data", OFF, "The FIELD_CRUX feature is turned off in the qbit config.", null));
|
||||
}
|
||||
else if(runtime.cruxClient() != null)
|
||||
{
|
||||
items.add(new Item("Google field data", SET_UP, "Checked daily; use “Refresh Google field data” to check now.", config.applyPrefix(WebPerfSchema.FIELD_SNAPSHOT)));
|
||||
}
|
||||
else
|
||||
{
|
||||
items.add(new Item("Google field data", NEEDS_SETUP, "No Google API key is configured, so Google field data is not checked.", null));
|
||||
}
|
||||
|
||||
items.add(new Item("Regressions, changes, comparisons", OPTIONAL, "Filled in by the qbit as tests run and deploys are detected. Nothing to set up.", config.applyPrefix(WebPerfSchema.REGRESSION)));
|
||||
return (items);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The card's HTML.
|
||||
*******************************************************************************/
|
||||
public static String html(WebPerfRuntime runtime) throws SQLException
|
||||
{
|
||||
List<List<String>> rows = new ArrayList<>();
|
||||
for(Item item : items(runtime))
|
||||
{
|
||||
String color = NEEDS_SETUP.equals(item.state()) ? Html.POOR : SET_UP.equals(item.state()) ? Html.GOOD : Html.MEDIUM;
|
||||
rows.add(List.of(
|
||||
item.tableName() == null ? Html.escape(item.name()) : Html.link("/app/" + item.tableName(), item.name()),
|
||||
"<b style=\"color:" + color + "\">" + Html.escape(item.state()) + "</b>",
|
||||
Html.escape(item.detail())));
|
||||
}
|
||||
return (Html.table(List.of("Part", "State", "What is next"), rows));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static long count(WebPerfStore store, String sql) throws SQLException
|
||||
{
|
||||
Long n = WebPerfStore.asLong(store.query(sql).get(0).get("n"));
|
||||
return (n == null ? 0 : n);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,6 +58,7 @@ import com.kingsrook.qqq.backend.core.model.dashboard.widgets.RawHTML;
|
||||
*******************************************************************************/
|
||||
public final class WebPerfWidgets
|
||||
{
|
||||
public static final String SETUP = "Setup";
|
||||
public static final String SITE_SCORES = "SiteScores";
|
||||
public static final String TREND = "Trend";
|
||||
public static final String SLOWEST_PAGES = "SlowestPages";
|
||||
@@ -67,7 +68,7 @@ public final class WebPerfWidgets
|
||||
public static final String RECORD_PANEL = "RecordPanel";
|
||||
|
||||
/** The home widgets, in order. */
|
||||
public static final List<String> HOME = List.of(SITE_SCORES, TREND, SLOWEST_PAGES, OPPORTUNITIES, FIELD_STATUS, RECENT_RUNS);
|
||||
public static final List<String> HOME = List.of(SETUP, SITE_SCORES, TREND, SLOWEST_PAGES, OPPORTUNITIES, FIELD_STATUS, RECENT_RUNS);
|
||||
|
||||
static final int TREND_WEEKS = 26;
|
||||
|
||||
@@ -415,6 +416,31 @@ public final class WebPerfWidgets
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setup: what is configured (pages, lab runner, budgets, field data) and
|
||||
** the next step for each (WebPerfSetupStatus).
|
||||
*******************************************************************************/
|
||||
public static class Setup extends AbstractWidgetRenderer
|
||||
{
|
||||
/*******************************************************************************
|
||||
** Render.
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public RenderWidgetOutput render(RenderWidgetInput input) throws QException
|
||||
{
|
||||
try
|
||||
{
|
||||
return (html(WebPerfSetupStatus.html(runtime(input))));
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
throw (new QException("Error loading setup status", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Field Data Status: what Google's field data (CrUX) says about the site,
|
||||
** honestly NO_DATA when Google has none.
|
||||
|
||||
@@ -280,3 +280,154 @@ ALTER TABLE ${web_performance.tablePrefix}regression ADD COLUMN failed_audits VA
|
||||
ALTER TABLE ${web_performance.tablePrefix}lab_run ADD COLUMN ttfb_ms INTEGER;
|
||||
ALTER TABLE ${web_performance.tablePrefix}field_snapshot ADD COLUMN evaluated_at TIMESTAMP WITHOUT TIME ZONE;
|
||||
ALTER TABLE ${web_performance.tablePrefix}change_event ADD COLUMN last_seen_at TIMESTAMP WITHOUT TIME ZONE;
|
||||
|
||||
-- changeset qbit-web-performance:12
|
||||
-- comment: Referential integrity (foreign keys), part 1: every foreign key column leads an index, so a parent delete checks its children by index. The other foreign key columns already lead one (target_id, run_id, change_event_id on comparison).
|
||||
CREATE INDEX IF NOT EXISTS idx_${web_performance.tablePrefix}lab_run_change_event ON ${web_performance.tablePrefix}lab_run (change_event_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_${web_performance.tablePrefix}regression_budget ON ${web_performance.tablePrefix}regression (budget_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_${web_performance.tablePrefix}regression_cause ON ${web_performance.tablePrefix}regression (cause_change_event_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_${web_performance.tablePrefix}regression_first_run ON ${web_performance.tablePrefix}regression (first_run_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_${web_performance.tablePrefix}regression_checkpoint_run ON ${web_performance.tablePrefix}regression (checkpoint_run_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_${web_performance.tablePrefix}comparison_target ON ${web_performance.tablePrefix}comparison (target_id);
|
||||
|
||||
-- Referential integrity (foreign keys), part 2: one changeset per foreign key, named
|
||||
-- fk_<child table>_<column>. Each first records and repairs rows whose parent is
|
||||
-- missing (a nullable column is set to NULL; a NOT NULL row is copied in full to
|
||||
-- qqq_fk_quarantine and deleted, PostgreSQL only), then adds the constraint. Each
|
||||
-- is marked ran when its constraint already exists (a host that added it itself).
|
||||
-- ON DELETE: owned details CASCADE (findings and the report of a run,
|
||||
-- comparisons of a site change); optional pointers SET NULL; tested pages and
|
||||
-- budgets RESTRICT, because history is kept (D8): disable a page or budget instead
|
||||
-- of deleting it.
|
||||
|
||||
-- changeset qbit-web-performance:13
|
||||
-- comment: Lab runs keep their tested page (D8, history is kept): a page with runs cannot be deleted, disable it instead (enabled = false). Orphan target_id values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_run_target_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}lab_run', 'target_id', CAST(c.id AS VARCHAR(100)), CAST(c.target_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:13' FROM ${web_performance.tablePrefix}lab_run c WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
UPDATE ${web_performance.tablePrefix}lab_run c SET target_id = NULL WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}lab_run ADD CONSTRAINT fk_${web_performance.tablePrefix}lab_run_target_id FOREIGN KEY (target_id) REFERENCES ${web_performance.tablePrefix}target (id) ON DELETE RESTRICT;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}lab_run DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}lab_run_target_id;
|
||||
|
||||
-- changeset qbit-web-performance:14 dbms:postgresql
|
||||
-- comment: Orphan cleanup before fk_${web_performance.tablePrefix}lab_finding_run_id: ${web_performance.tablePrefix}lab_finding rows whose run_id names a missing ${web_performance.tablePrefix}lab_run row are copied in full to qqq_fk_quarantine, then deleted (run_id is NOT NULL).
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_finding_run_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, row_data, changeset) SELECT '${web_performance.tablePrefix}lab_finding', 'run_id', CAST(c.id AS VARCHAR(100)), CAST(c.run_id AS VARCHAR(100)), 'DELETED', row_to_json(c)::text, 'qbit-web-performance:14' FROM ${web_performance.tablePrefix}lab_finding c WHERE c.run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.run_id);
|
||||
DELETE FROM ${web_performance.tablePrefix}lab_finding c WHERE c.run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.run_id);
|
||||
-- rollback SELECT 1;
|
||||
|
||||
-- changeset qbit-web-performance:15
|
||||
-- comment: Findings belong to their run: deleting a run deletes its findings.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_finding_run_id'
|
||||
ALTER TABLE ${web_performance.tablePrefix}lab_finding ADD CONSTRAINT fk_${web_performance.tablePrefix}lab_finding_run_id FOREIGN KEY (run_id) REFERENCES ${web_performance.tablePrefix}lab_run (id) ON DELETE CASCADE;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}lab_finding DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}lab_finding_run_id;
|
||||
|
||||
-- changeset qbit-web-performance:16
|
||||
-- comment: A finding's page (copied from its run) is kept like the run's. Orphan target_id values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_finding_target_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}lab_finding', 'target_id', CAST(c.id AS VARCHAR(100)), CAST(c.target_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:16' FROM ${web_performance.tablePrefix}lab_finding c WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
UPDATE ${web_performance.tablePrefix}lab_finding c SET target_id = NULL WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}lab_finding ADD CONSTRAINT fk_${web_performance.tablePrefix}lab_finding_target_id FOREIGN KEY (target_id) REFERENCES ${web_performance.tablePrefix}target (id) ON DELETE RESTRICT;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}lab_finding DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}lab_finding_target_id;
|
||||
|
||||
-- changeset qbit-web-performance:17 dbms:postgresql
|
||||
-- comment: Orphan cleanup before fk_${web_performance.tablePrefix}lab_report_run_id: ${web_performance.tablePrefix}lab_report rows whose run_id names a missing ${web_performance.tablePrefix}lab_run row are copied in full to qqq_fk_quarantine, then deleted (run_id is NOT NULL).
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_report_run_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, row_data, changeset) SELECT '${web_performance.tablePrefix}lab_report', 'run_id', CAST(c.id AS VARCHAR(100)), CAST(c.run_id AS VARCHAR(100)), 'DELETED', row_to_json(c)::text, 'qbit-web-performance:17' FROM ${web_performance.tablePrefix}lab_report c WHERE c.run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.run_id);
|
||||
DELETE FROM ${web_performance.tablePrefix}lab_report c WHERE c.run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.run_id);
|
||||
-- rollback SELECT 1;
|
||||
|
||||
-- changeset qbit-web-performance:18
|
||||
-- comment: The Lighthouse report belongs to its run: deleting a run deletes its report.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_report_run_id'
|
||||
ALTER TABLE ${web_performance.tablePrefix}lab_report ADD CONSTRAINT fk_${web_performance.tablePrefix}lab_report_run_id FOREIGN KEY (run_id) REFERENCES ${web_performance.tablePrefix}lab_run (id) ON DELETE CASCADE;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}lab_report DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}lab_report_run_id;
|
||||
|
||||
-- changeset qbit-web-performance:19
|
||||
-- comment: Regressions keep their page: a page with regressions cannot be deleted, disable it instead. Orphan target_id values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}regression_target_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}regression', 'target_id', CAST(c.id AS VARCHAR(100)), CAST(c.target_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:19' FROM ${web_performance.tablePrefix}regression c WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
UPDATE ${web_performance.tablePrefix}regression c SET target_id = NULL WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}regression ADD CONSTRAINT fk_${web_performance.tablePrefix}regression_target_id FOREIGN KEY (target_id) REFERENCES ${web_performance.tablePrefix}target (id) ON DELETE RESTRICT;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}regression DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}regression_target_id;
|
||||
|
||||
-- changeset qbit-web-performance:20
|
||||
-- comment: A regression keeps the budget it breached: a budget with regressions cannot be deleted, disable it instead (enabled = false). Orphan budget_id values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}regression_budget_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}regression', 'budget_id', CAST(c.id AS VARCHAR(100)), CAST(c.budget_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:20' FROM ${web_performance.tablePrefix}regression c WHERE c.budget_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}budget p WHERE p.id = c.budget_id);
|
||||
UPDATE ${web_performance.tablePrefix}regression c SET budget_id = NULL WHERE c.budget_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}budget p WHERE p.id = c.budget_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}regression ADD CONSTRAINT fk_${web_performance.tablePrefix}regression_budget_id FOREIGN KEY (budget_id) REFERENCES ${web_performance.tablePrefix}budget (id) ON DELETE RESTRICT;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}regression DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}regression_budget_id;
|
||||
|
||||
-- changeset qbit-web-performance:21
|
||||
-- comment: The likely cause is an optional pointer: deleting the site change clears it. Orphan values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}regression_cause_change_event_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}regression', 'cause_change_event_id', CAST(c.id AS VARCHAR(100)), CAST(c.cause_change_event_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:21' FROM ${web_performance.tablePrefix}regression c WHERE c.cause_change_event_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}change_event p WHERE p.id = c.cause_change_event_id);
|
||||
UPDATE ${web_performance.tablePrefix}regression c SET cause_change_event_id = NULL WHERE c.cause_change_event_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}change_event p WHERE p.id = c.cause_change_event_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}regression ADD CONSTRAINT fk_${web_performance.tablePrefix}regression_cause_change_event_id FOREIGN KEY (cause_change_event_id) REFERENCES ${web_performance.tablePrefix}change_event (id) ON DELETE SET NULL;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}regression DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}regression_cause_change_event_id;
|
||||
|
||||
-- changeset qbit-web-performance:22
|
||||
-- comment: A before-and-after comparison is computed for its site change: deleting the change deletes its comparisons. Orphan values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}comparison_change_event_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}comparison', 'change_event_id', CAST(c.id AS VARCHAR(100)), CAST(c.change_event_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:22' FROM ${web_performance.tablePrefix}comparison c WHERE c.change_event_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}change_event p WHERE p.id = c.change_event_id);
|
||||
UPDATE ${web_performance.tablePrefix}comparison c SET change_event_id = NULL WHERE c.change_event_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}change_event p WHERE p.id = c.change_event_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}comparison ADD CONSTRAINT fk_${web_performance.tablePrefix}comparison_change_event_id FOREIGN KEY (change_event_id) REFERENCES ${web_performance.tablePrefix}change_event (id) ON DELETE CASCADE;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}comparison DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}comparison_change_event_id;
|
||||
|
||||
-- changeset qbit-web-performance:23
|
||||
-- comment: The site change a run was attributed to is an optional pointer: deleting the change clears it. Orphan values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}lab_run_change_event_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}lab_run', 'change_event_id', CAST(c.id AS VARCHAR(100)), CAST(c.change_event_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:23' FROM ${web_performance.tablePrefix}lab_run c WHERE c.change_event_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}change_event p WHERE p.id = c.change_event_id);
|
||||
UPDATE ${web_performance.tablePrefix}lab_run c SET change_event_id = NULL WHERE c.change_event_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}change_event p WHERE p.id = c.change_event_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}lab_run ADD CONSTRAINT fk_${web_performance.tablePrefix}lab_run_change_event_id FOREIGN KEY (change_event_id) REFERENCES ${web_performance.tablePrefix}change_event (id) ON DELETE SET NULL;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}lab_run DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}lab_run_change_event_id;
|
||||
|
||||
-- changeset qbit-web-performance:24
|
||||
-- comment: Evidence pointer to the run that first showed the regression: deleting the run clears it. Orphan values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}regression_first_run_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}regression', 'first_run_id', CAST(c.id AS VARCHAR(100)), CAST(c.first_run_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:24' FROM ${web_performance.tablePrefix}regression c WHERE c.first_run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.first_run_id);
|
||||
UPDATE ${web_performance.tablePrefix}regression c SET first_run_id = NULL WHERE c.first_run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.first_run_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}regression ADD CONSTRAINT fk_${web_performance.tablePrefix}regression_first_run_id FOREIGN KEY (first_run_id) REFERENCES ${web_performance.tablePrefix}lab_run (id) ON DELETE SET NULL;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}regression DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}regression_first_run_id;
|
||||
|
||||
-- changeset qbit-web-performance:25
|
||||
-- comment: Evidence pointer to the confirmation run: deleting the run clears it. Orphan values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}regression_checkpoint_run_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}regression', 'checkpoint_run_id', CAST(c.id AS VARCHAR(100)), CAST(c.checkpoint_run_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:25' FROM ${web_performance.tablePrefix}regression c WHERE c.checkpoint_run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.checkpoint_run_id);
|
||||
UPDATE ${web_performance.tablePrefix}regression c SET checkpoint_run_id = NULL WHERE c.checkpoint_run_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}lab_run p WHERE p.id = c.checkpoint_run_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}regression ADD CONSTRAINT fk_${web_performance.tablePrefix}regression_checkpoint_run_id FOREIGN KEY (checkpoint_run_id) REFERENCES ${web_performance.tablePrefix}lab_run (id) ON DELETE SET NULL;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}regression DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}regression_checkpoint_run_id;
|
||||
|
||||
-- changeset qbit-web-performance:26
|
||||
-- comment: A per-page comparison keeps its page: a page with comparisons cannot be deleted, disable it instead. Orphan target_id values are recorded in qqq_fk_quarantine and set to NULL.
|
||||
-- preconditions onFail:MARK_RAN onError:HALT
|
||||
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.table_constraints WHERE LOWER(constraint_name) = 'fk_${web_performance.tablePrefix}comparison_target_id'
|
||||
CREATE TABLE IF NOT EXISTS qqq_fk_quarantine (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, table_name VARCHAR(100) NOT NULL, column_name VARCHAR(100) NOT NULL, row_id VARCHAR(100), missing_parent_id VARCHAR(100), action VARCHAR(20) NOT NULL, row_data TEXT, changeset VARCHAR(200), quarantined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO qqq_fk_quarantine (table_name, column_name, row_id, missing_parent_id, action, changeset) SELECT '${web_performance.tablePrefix}comparison', 'target_id', CAST(c.id AS VARCHAR(100)), CAST(c.target_id AS VARCHAR(100)), 'NULLED', 'qbit-web-performance:26' FROM ${web_performance.tablePrefix}comparison c WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
UPDATE ${web_performance.tablePrefix}comparison c SET target_id = NULL WHERE c.target_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${web_performance.tablePrefix}target p WHERE p.id = c.target_id);
|
||||
ALTER TABLE ${web_performance.tablePrefix}comparison ADD CONSTRAINT fk_${web_performance.tablePrefix}comparison_target_id FOREIGN KEY (target_id) REFERENCES ${web_performance.tablePrefix}target (id) ON DELETE RESTRICT;
|
||||
-- rollback ALTER TABLE ${web_performance.tablePrefix}comparison DROP CONSTRAINT IF EXISTS fk_${web_performance.tablePrefix}comparison_target_id;
|
||||
@@ -0,0 +1,58 @@
|
||||
bundle: web-performance
|
||||
version: 1
|
||||
layer: QBIT
|
||||
# Help for the Performance app and every web_performance_* table, in the QQQ
|
||||
# help-bundle format (qqq#1198). Each table entry says what the table is for and
|
||||
# how its rows get created, so an empty table explains itself. WebPerfHelp
|
||||
# applies it until the core HelpBundles registry ships in a QQQ release.
|
||||
# Summaries stay under 120 characters (WebPerfTablesGuardrailTest).
|
||||
entries:
|
||||
- key: app:webPerformance;slot:help
|
||||
summary: "Page speed for your site: Lighthouse lab tests, Google field data, budgets and regressions."
|
||||
content: |
|
||||
The Setup card on the home lists what is configured and the next step: sync the pages, give the qbit a Google API key, and review the budgets. A new installation starts with reference budgets (Google's good thresholds) already in place.
|
||||
|
||||
- key: table:web_performance_target;slot:help
|
||||
summary: "The pages that get tested: one row per URL, with its tier, latest scores and open regressions."
|
||||
content: |
|
||||
**How rows get created:** run Sync pages from sitemap (also scheduled), which adds every page the host's URL source returns and links it to its content record. You can also add a page by hand with New. Mark a page KEY to put it in the site scores and the frequent tests. Run site audit or Test page speed queues lab tests.
|
||||
|
||||
- key: table:web_performance_lab_run;slot:help
|
||||
summary: "Every Lighthouse test of a page: queued, running, finished or failed, with its scores and timings."
|
||||
content: |
|
||||
**How rows get created:** by the qbit. Test page speed, Run site audit and the schedules queue runs here, and the worker runs them through the lab runner (PageSpeed Insights when a Google API key is set). Nothing is added by hand. Without a key, runs wait in the queue. Retry re-queues a failed run.
|
||||
|
||||
- key: table:web_performance_lab_finding;slot:help
|
||||
summary: "What Lighthouse says to fix on each tested page: the audits that failed and how much they would save."
|
||||
content: |
|
||||
**How rows get created:** by the qbit, from each finished lab run. One row per failed or opportunity audit. It stays empty until a lab test succeeds.
|
||||
|
||||
- key: table:web_performance_lab_report;slot:help
|
||||
summary: "The complete Lighthouse response of each run, compressed, for download and later comparison."
|
||||
content: |
|
||||
**How rows get created:** by the qbit, one per successful lab run. Nothing to set up. Reports are kept forever unless the host sets reportRetentionDays, which deletes older reports (the run and its scores stay).
|
||||
|
||||
- key: table:web_performance_field_snapshot;slot:help
|
||||
summary: "What Google's field data (CrUX) says real Chrome users experience: p75 Core Web Vitals per URL or origin."
|
||||
content: |
|
||||
**How rows get created:** by the qbit. Refresh Google field data (and the daily schedule) asks Google for the site and each tested page. It needs the Google API key. A row says NO_DATA when Google has too little traffic to publish figures for that page.
|
||||
|
||||
- key: table:web_performance_budget;slot:help
|
||||
summary: "Limits a metric must stay within, per site, tier, page, content table or path; a breach raises a regression."
|
||||
content: |
|
||||
**How rows get created:** the qbit seeds reference budgets (Google's good thresholds for each Core Web Vital, and Lighthouse category scores for KEY pages), so a new installation already flags slow pages. Edit them, turn them off, or add your own with New. Lab and Google field data (CRUX) budgets are evaluated; budgets with source RUM (real users) are not evaluated yet, because no real-user source is wired in.
|
||||
|
||||
- key: table:web_performance_regression;slot:help
|
||||
summary: "A page that got slower or broke a budget: suspected, confirmed, then resolved or dismissed."
|
||||
content: |
|
||||
**How rows get created:** by the qbit. When a test breaks a budget or drifts from its baseline, it opens a suspected regression and confirms it after more runs. Mark resolved and Dismiss close one by hand. Empty means nothing is wrong.
|
||||
|
||||
- key: table:web_performance_change_event;slot:help
|
||||
summary: "Site changes (a deploy, a Lighthouse version, a CDN stage change) that trigger re-tests."
|
||||
content: |
|
||||
**How rows get created:** by the qbit. Check site changes (scheduled when deploy probes or change sources are configured) records a change, and the qbit notes when Lighthouse itself changes version. It stays empty until the host configures a deploy probe or change event source.
|
||||
|
||||
- key: table:web_performance_comparison;slot:help
|
||||
summary: "Before and after results around a site change, per page and metric."
|
||||
content: |
|
||||
**How rows get created:** run Compare before and after on a change event (it needs the CDN_COMPARE feature and a change event). Nothing to add by hand.
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.webperf;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import liquibase.Liquibase;
|
||||
import liquibase.database.Database;
|
||||
import liquibase.database.DatabaseFactory;
|
||||
import liquibase.database.jvm.JdbcConnection;
|
||||
import liquibase.resource.ClassLoaderResourceAccessor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The shipped changelog, run through real Liquibase on H2 (PostgreSQL mode):
|
||||
** it creates the nine tables, changeset 10 seeds the reference budgets, a
|
||||
** second update runs nothing, and the seed statement run again inserts nothing
|
||||
** and keeps an administrator's edit.
|
||||
*******************************************************************************/
|
||||
class WebPerfDefaultsChangelogTest
|
||||
{
|
||||
private static final String PREFIX = "web_performance_";
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void seededBudgetsThroughRealLiquibase_idempotent_andKeepEdits() throws Exception
|
||||
{
|
||||
try(Connection connection = connect())
|
||||
{
|
||||
update();
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM " + PREFIX + "budget")).isEqualTo(13);
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM " + PREFIX + "budget WHERE seeded = TRUE AND enabled = TRUE")).isEqualTo(13);
|
||||
for(String base : WebPerfSchema.TABLES)
|
||||
{
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM " + PREFIX + base)).as(base + " is queryable").isGreaterThanOrEqualTo(0);
|
||||
}
|
||||
int changesets = count(connection, "SELECT COUNT(*) FROM DATABASECHANGELOG");
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// a second update has nothing to run //
|
||||
////////////////////////////////////////////////////////////////
|
||||
update();
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM DATABASECHANGELOG")).isEqualTo(changesets);
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM " + PREFIX + "budget")).isEqualTo(13);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// an admin edits a seed; the seed statement (changeset 10) is run again: //
|
||||
// nothing is inserted and the edit survives //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
try(Statement statement = connection.createStatement())
|
||||
{
|
||||
statement.execute("UPDATE " + PREFIX + "budget SET threshold = 3000 WHERE name = 'LCP good (lab, mobile)'");
|
||||
statement.execute(seedStatement());
|
||||
}
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM " + PREFIX + "budget")).isEqualTo(13);
|
||||
assertThat(count(connection, "SELECT COUNT(*) FROM " + PREFIX + "budget WHERE name = 'LCP good (lab, mobile)' AND threshold = 3000")).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The INSERT of changeset 10, with the prefix filled in.
|
||||
*******************************************************************************/
|
||||
private static String seedStatement() throws Exception
|
||||
{
|
||||
String script;
|
||||
try(java.io.InputStream in = WebPerfDefaultsChangelogTest.class.getClassLoader().getResourceAsStream(WebPerfSchema.CHANGELOG))
|
||||
{
|
||||
script = new String(in.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
|
||||
}
|
||||
String seed = script.substring(script.indexOf("-- changeset qbit-web-performance:10"), script.indexOf("-- changeset qbit-web-performance:11"));
|
||||
seed = seed.substring(seed.indexOf("INSERT INTO")).trim().replaceAll(";$", "");
|
||||
return (seed.replace("${" + WebPerfSchema.CHANGELOG_PREFIX_PROPERTY + "}", PREFIX));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A connection to the shared in-memory database.
|
||||
*******************************************************************************/
|
||||
private static Connection connect() throws Exception
|
||||
{
|
||||
return (DriverManager.getConnection("jdbc:h2:mem:wpdefaults;MODE=PostgreSQL;DB_CLOSE_DELAY=-1", "sa", ""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** One real Liquibase update on its own connection (Liquibase closes it).
|
||||
*******************************************************************************/
|
||||
private static void update() throws Exception
|
||||
{
|
||||
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connect()));
|
||||
try(Liquibase liquibase = new Liquibase(WebPerfSchema.CHANGELOG, new ClassLoaderResourceAccessor(), database))
|
||||
{
|
||||
liquibase.setChangeLogParameter(WebPerfSchema.CHANGELOG_PREFIX_PROPERTY, PREFIX);
|
||||
liquibase.update("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static int count(Connection connection, String sql) throws Exception
|
||||
{
|
||||
try(Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(sql))
|
||||
{
|
||||
resultSet.next();
|
||||
return (resultSet.getInt(1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
* 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/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.webperf;
|
||||
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import liquibase.Contexts;
|
||||
import liquibase.LabelExpression;
|
||||
import liquibase.Liquibase;
|
||||
import liquibase.database.Database;
|
||||
import liquibase.database.DatabaseFactory;
|
||||
import liquibase.database.jvm.JdbcConnection;
|
||||
import liquibase.resource.ClassLoaderResourceAccessor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Referential integrity on PostgreSQL (the production database), with the
|
||||
** changelog run by Liquibase as a host runs it:
|
||||
**
|
||||
** - every table possible-value field that names one of the QBit's tables,
|
||||
** and every join, has a database foreign key (or an exemption with a
|
||||
** reason), so a new reference cannot be added without its constraint;
|
||||
** - rows whose parent is missing when the constraints are added are recorded
|
||||
** in qqq_fk_quarantine and repaired (nulled, or deleted with a full copy),
|
||||
** so the upgrade never fails on existing data;
|
||||
** - the foreign key changesets are no-ops on a database that already has the
|
||||
** constraints (a host that added them itself).
|
||||
**
|
||||
** Skipped when Docker is not available.
|
||||
*******************************************************************************/
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
class WebPerfForeignKeyTest
|
||||
{
|
||||
private static final String PREFIX = "web_performance_";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// references that are deliberately not foreign keys: "child.column" -> //
|
||||
// reason. None today (content_table + content_id is polymorphic, and has //
|
||||
// no possible-value source). //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private static final Map<String, String> EXEMPT = Map.of();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// the changesets before the foreign keys (1-11) //
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
private static final int CHANGESETS_BEFORE_FOREIGN_KEYS = 11;
|
||||
|
||||
@Container
|
||||
private static final PostgreSQLContainer<?> POSTGRES = new PostgreSQLContainer<>("postgres:17-alpine");
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Orphans are quarantined, every reference gets its constraint, and a
|
||||
** re-run of the foreign key changesets changes nothing.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testEveryReferenceHasAForeignKey() throws Exception
|
||||
{
|
||||
try(Connection connection = DriverManager.getConnection(POSTGRES.getJdbcUrl(), POSTGRES.getUsername(), POSTGRES.getPassword());
|
||||
Statement statement = connection.createStatement())
|
||||
{
|
||||
statement.execute("DROP SCHEMA public CASCADE");
|
||||
statement.execute("CREATE SCHEMA public");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// an existing install with rows whose parents are gone //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
migrate(connection, CHANGESETS_BEFORE_FOREIGN_KEYS);
|
||||
statement.execute("INSERT INTO web_performance_target (id, url) VALUES (1, 'https://www.example.com/')");
|
||||
statement.execute("INSERT INTO web_performance_lab_run (id, target_id) VALUES (1, 1), (2, 404)");
|
||||
statement.execute("INSERT INTO web_performance_lab_finding (id, run_id, target_id) VALUES (1, 1, 1), (2, 404, 1)");
|
||||
statement.execute("INSERT INTO web_performance_lab_report (id, run_id) VALUES (1, 404)");
|
||||
statement.execute("INSERT INTO web_performance_regression (id, target_id, budget_id, first_run_id) VALUES (1, 1, 404, 404)");
|
||||
|
||||
migrate(connection, null);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// every reference the meta-data declares has its constraint //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
Map<String, String> foreignKeys = foreignKeys(statement);
|
||||
List<String> missing = new ArrayList<>();
|
||||
for(String reference : references())
|
||||
{
|
||||
if(!foreignKeys.containsKey(reference) && !EXEMPT.containsKey(reference))
|
||||
{
|
||||
missing.add(reference);
|
||||
}
|
||||
}
|
||||
assertThat(missing).as("references without a foreign key (add one to the changelog, or an exemption with a reason)").isEmpty();
|
||||
assertThat(foreignKeys).containsEntry("web_performance_lab_finding.run_id", "web_performance_lab_run CASCADE")
|
||||
.containsEntry("web_performance_lab_run.target_id", "web_performance_target RESTRICT")
|
||||
.containsEntry("web_performance_regression.cause_change_event_id", "web_performance_change_event SET NULL");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// the orphans were recorded, then nulled or deleted //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
assertThat(rows(statement, "SELECT table_name || '.' || column_name || ' ' || row_id || '->' || missing_parent_id || ' ' || action || ' ' || (row_data IS NOT NULL) FROM qqq_fk_quarantine"))
|
||||
.containsExactlyInAnyOrder(
|
||||
"web_performance_lab_run.target_id 2->404 NULLED false",
|
||||
"web_performance_lab_finding.run_id 2->404 DELETED true",
|
||||
"web_performance_lab_report.run_id 1->404 DELETED true",
|
||||
"web_performance_regression.budget_id 1->404 NULLED false",
|
||||
"web_performance_regression.first_run_id 1->404 NULLED false");
|
||||
assertThat(rows(statement, "SELECT id || ' ' || COALESCE(CAST(target_id AS TEXT), '-') FROM web_performance_lab_run")).containsExactlyInAnyOrder("1 1", "2 -");
|
||||
assertThat(rows(statement, "SELECT CAST(id AS TEXT) FROM web_performance_lab_finding")).containsExactly("1");
|
||||
assertThat(rows(statement, "SELECT CAST(id AS TEXT) FROM web_performance_lab_report")).isEmpty();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// a host that already has the constraints: the changesets are marked //
|
||||
// ran and change nothing //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
statement.execute("DELETE FROM databasechangelog WHERE CAST(SUBSTRING(id FROM '[0-9]+$') AS INTEGER) > " + CHANGESETS_BEFORE_FOREIGN_KEYS);
|
||||
migrate(connection, null);
|
||||
assertThat(foreignKeys(statement)).isEqualTo(foreignKeys);
|
||||
assertThat(rows(statement, "SELECT CAST(COUNT(*) AS TEXT) FROM qqq_fk_quarantine")).containsExactly("5");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Run the changelog (all of it, or the first n changesets).
|
||||
*******************************************************************************/
|
||||
private static void migrate(Connection connection, Integer count) throws Exception
|
||||
{
|
||||
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
|
||||
Liquibase liquibase = new Liquibase(WebPerfSchema.CHANGELOG, new ClassLoaderResourceAccessor(), database);
|
||||
liquibase.setChangeLogParameter(WebPerfSchema.CHANGELOG_PREFIX_PROPERTY, PREFIX);
|
||||
if(count == null)
|
||||
{
|
||||
liquibase.update(new Contexts(), new LabelExpression());
|
||||
}
|
||||
else
|
||||
{
|
||||
liquibase.update(count, new Contexts(), new LabelExpression());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** "child.column" for every table possible-value field and join of the QBit.
|
||||
*******************************************************************************/
|
||||
private static List<String> references() throws Exception
|
||||
{
|
||||
QInstance qInstance = WebPerfTestSupport.newInstance();
|
||||
new WebPerfQBitProducer().withQBitConfig(WebPerfTestSupport.config().withTableNamePrefix(PREFIX)).produce(qInstance);
|
||||
|
||||
List<String> references = new ArrayList<>();
|
||||
for(QTableMetaData table : qInstance.getTables().values())
|
||||
{
|
||||
for(QFieldMetaData field : table.getFields().values())
|
||||
{
|
||||
if(field.getPossibleValueSourceName() != null && qInstance.getTable(field.getPossibleValueSourceName()) != null)
|
||||
{
|
||||
references.add(table.getName() + "." + field.getBackendName());
|
||||
}
|
||||
}
|
||||
}
|
||||
for(QJoinMetaData join : qInstance.getJoins().values())
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// the referencing side is the one whose field is not its key //
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
QTableMetaData left = qInstance.getTable(join.getLeftTable());
|
||||
QTableMetaData right = qInstance.getTable(join.getRightTable());
|
||||
join.getJoinOns().forEach(on -> references.add(on.getRightField().equals(right.getPrimaryKeyField())
|
||||
? left.getName() + "." + left.getField(on.getLeftField()).getBackendName()
|
||||
: right.getName() + "." + right.getField(on.getRightField()).getBackendName()));
|
||||
}
|
||||
assertThat(references).as("the QBit's references").hasSizeGreaterThanOrEqualTo(12);
|
||||
return (references);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** "child.column" -> "parent RULE" for every foreign key in the database.
|
||||
*******************************************************************************/
|
||||
private static Map<String, String> foreignKeys(Statement statement) throws Exception
|
||||
{
|
||||
Map<String, String> foreignKeys = new HashMap<>();
|
||||
try(ResultSet resultSet = statement.executeQuery("""
|
||||
SELECT tc.table_name || '.' || kcu.column_name, ccu.table_name || ' ' || rc.delete_rule
|
||||
FROM information_schema.table_constraints tc
|
||||
JOIN information_schema.key_column_usage kcu ON kcu.constraint_name = tc.constraint_name
|
||||
JOIN information_schema.referential_constraints rc ON rc.constraint_name = tc.constraint_name
|
||||
JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name
|
||||
WHERE tc.constraint_type = 'FOREIGN KEY'"""))
|
||||
{
|
||||
while(resultSet.next())
|
||||
{
|
||||
foreignKeys.put(resultSet.getString(1), resultSet.getString(2));
|
||||
}
|
||||
}
|
||||
return (foreignKeys);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The first column of each row of a query, as text.
|
||||
*******************************************************************************/
|
||||
private static List<String> rows(Statement statement, String sql) throws Exception
|
||||
{
|
||||
List<String> rows = new ArrayList<>();
|
||||
try(ResultSet resultSet = statement.executeQuery(sql))
|
||||
{
|
||||
while(resultSet.next())
|
||||
{
|
||||
rows.add(resultSet.getString(1));
|
||||
}
|
||||
}
|
||||
return (rows);
|
||||
}
|
||||
}
|
||||
@@ -206,6 +206,68 @@ class WebPerfP1Test
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The Setup card reports pages, budgets, the lab runner and field data from
|
||||
** the runtime's own resolution, with the next step for each.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSetupCard() throws Exception
|
||||
{
|
||||
String card = html(WebPerfWidgets.SETUP, Map.of());
|
||||
assertThat(card).contains("Needs setup").contains("Sync pages from sitemap").contains("Using defaults").contains("13 reference budgets");
|
||||
assertThat(card).as("a configured runner and CrUX client count as set up").contains("A lab runner is configured").contains("Checked daily");
|
||||
|
||||
WebPerfService service = service();
|
||||
service.applySync(service.planSync(List.of(SITE + "/")), Instant.now());
|
||||
store().update("INSERT INTO {budget} (name, scope, source, metric, comparator, threshold, severity, enabled, seeded) VALUES ('mine', 'SITE', 'LAB', 'LCP', '<=', 2000, 'WARNING', TRUE, FALSE)");
|
||||
card = html(WebPerfWidgets.SETUP, Map.of());
|
||||
assertThat(card).contains("1 page").contains("14 budgets are enabled, 1 of them your own");
|
||||
|
||||
store().update("UPDATE {budget} SET enabled = FALSE");
|
||||
assertThat(html(WebPerfWidgets.SETUP, Map.of())).contains("No budget is enabled");
|
||||
|
||||
config.withLabRunner(null).withCruxClient(null);
|
||||
assertThat(html(WebPerfWidgets.SETUP, Map.of())).contains("No Google API key is configured, so lab tests cannot run").contains("Google field data is not checked");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** reportRetentionDays deletes old Lighthouse Reports when a run stores its
|
||||
** own, and 0 (the default) keeps them forever.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testReportRetention() throws Exception
|
||||
{
|
||||
for(int days : new int[] { 0, 30 })
|
||||
{
|
||||
store().update("DELETE FROM {lab_report}");
|
||||
store().update("DELETE FROM {lab_finding}");
|
||||
store().update("DELETE FROM {lab_run}");
|
||||
store().update("DELETE FROM {budget}");
|
||||
config.withReportRetentionDays(days);
|
||||
google.respond(new FixtureServer.Response(200, FixtureServer.fixture("psi-kof22-home-mobile.json")));
|
||||
long oldRunId = store().insert("lab_run", new java.util.LinkedHashMap<>(Map.of("status", "FAILED")));
|
||||
store().insert("lab_report", new java.util.LinkedHashMap<>(Map.of("run_id", oldRunId, "bytes", 1,
|
||||
"create_date", Instant.now().minus(java.time.Duration.ofDays(40)))));
|
||||
WebPerfRuntime.of(qInstance, "web_performance_").allowReportPruneNow();
|
||||
WebPerfService service = service();
|
||||
service.applySync(service.planSync(List.of(SITE + "/")), Instant.now());
|
||||
service.enqueue(service.requestsFor(service.enabledTargets(false), "MANUAL", "test", Instant.now()), Instant.now());
|
||||
assertEquals(2, service.runDue(Instant.now()));
|
||||
|
||||
assertEquals(2, store().query("SELECT id FROM {lab_run} WHERE status = 'SUCCEEDED'").size(), "runs are untouched by pruning");
|
||||
assertThat(store().query("SELECT id FROM {lab_finding}")).as("findings are untouched by pruning").hasSizeGreaterThan(5);
|
||||
long old = store().query("SELECT id FROM {lab_report} WHERE run_id = ?", oldRunId).size();
|
||||
long fresh = store().query("SELECT id FROM {lab_report} WHERE run_id <> ?", oldRunId).size();
|
||||
assertEquals(2, fresh, "the new reports are kept");
|
||||
assertEquals(days == 0 ? 1 : 0, old, "retention " + days + " days");
|
||||
}
|
||||
assertThat(new WebPerfRuntime(config).reportPruneDue()).as("a new process does not prune right away").isFalse();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The worker runs a test, stores scores, findings, the report and the
|
||||
** page's latest results.
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright 2026 Kingsrook, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qbits.webperf;
|
||||
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
import com.kingsrook.qbits.webperf.metadata.WebPerfHelp;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.help.QHelpContent;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Guardrail (owner requirement 2026-10-14: "all tables should be populated and
|
||||
** the qbit should be fully using them"). For every web_performance_* table:
|
||||
** - runtime code (not just its metadata or the home widgets) reads or writes
|
||||
** it, so no table exists only on paper;
|
||||
** - it is either seeded by the shipped changelog or listed in STARTS_EMPTY
|
||||
** with why it starts empty;
|
||||
** - it has bundle help that says what it is for and how its rows get created.
|
||||
** A new table fails this test until it is wired, seeded or explained.
|
||||
*******************************************************************************/
|
||||
class WebPerfTablesGuardrailTest
|
||||
{
|
||||
private static final Path MAIN = Path.of("src", "main", "java", "com", "kingsrook", "qbits", "webperf");
|
||||
|
||||
/*******************************************************************************
|
||||
** Tables the shipped changelog seeds (WebPerfDefaultsChangelogTest proves it).
|
||||
*******************************************************************************/
|
||||
static final Map<String, String> SEEDED = Map.of(
|
||||
"budget", "changeset 10: Google's good thresholds and the Lighthouse category bands");
|
||||
|
||||
/*******************************************************************************
|
||||
** Tables that legitimately start empty, and where their rows come from.
|
||||
*******************************************************************************/
|
||||
static final Map<String, String> STARTS_EMPTY = Map.of(
|
||||
"target", "synced from the sitemap (Sync pages from sitemap) or added by hand; the page list is host content",
|
||||
"lab_run", "runtime: every queued or finished Lighthouse test",
|
||||
"lab_finding", "runtime: findings of each successful lab run",
|
||||
"lab_report", "runtime: the full response of each successful lab run",
|
||||
"field_snapshot", "runtime: Google field data checks",
|
||||
"regression", "runtime: a budget is broken or a score drifts (empty is healthy)",
|
||||
"change_event", "runtime: a deploy or content change is detected (needs a probe or source)",
|
||||
"comparison", "runtime: Compare before and after on a change event");
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@AfterEach
|
||||
void tearDown()
|
||||
{
|
||||
QContext.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table is used by runtime code.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableIsUsedAtRuntime() throws Exception
|
||||
{
|
||||
List<String> runtimeSource;
|
||||
try(Stream<Path> files = Files.walk(MAIN))
|
||||
{
|
||||
runtimeSource = files.filter(p -> p.toString().endsWith(".java"))
|
||||
.filter(p -> !p.startsWith(MAIN.resolve("metadata")) && !p.startsWith(MAIN.resolve("widgets")))
|
||||
.map(WebPerfTablesGuardrailTest::read).toList();
|
||||
}
|
||||
for(String base : WebPerfSchema.TABLES)
|
||||
{
|
||||
Pattern use = Pattern.compile("\\{" + base + "\\}|WebPerfSchema\\." + base.toUpperCase(Locale.ROOT) + "\\b");
|
||||
assertThat(runtimeSource.stream().anyMatch(source -> use.matcher(source).find()))
|
||||
.as(base + " must be read or written by runtime code, not only declared").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table is seeded or explained.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableIsSeededOrExplained() throws Exception
|
||||
{
|
||||
String changelog = Files.readString(Path.of("src", "main", "resources", WebPerfSchema.CHANGELOG), StandardCharsets.UTF_8);
|
||||
for(String base : WebPerfSchema.TABLES)
|
||||
{
|
||||
boolean seeded = SEEDED.containsKey(base);
|
||||
assertThat(seeded || STARTS_EMPTY.containsKey(base)).as(base + " must be seeded or listed in STARTS_EMPTY").isTrue();
|
||||
assertThat(seeded && STARTS_EMPTY.containsKey(base)).as(base + " cannot be both").isFalse();
|
||||
assertThat(changelog.contains("INSERT INTO ${web_performance.tablePrefix}" + base + " ")).as(base + " seeded iff the changelog inserts it").isEqualTo(seeded);
|
||||
}
|
||||
assertThat(WebPerfSchema.TABLES).containsAll(SEEDED.keySet()).containsAll(STARTS_EMPTY.keySet());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table and the app have bundle help that says how rows get created.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableHasEmptyStateHelp() throws Exception
|
||||
{
|
||||
QInstance qInstance = WebPerfTestSupport.newInstance();
|
||||
new WebPerfQBitProducer().withQBitConfig(WebPerfTestSupport.config()).produce(qInstance);
|
||||
WebPerfQBitConfig config = WebPerfTestSupport.config();
|
||||
|
||||
assertThat(WebPerfHelp.entries()).allSatisfy((key, entry) -> assertThat(entry.path("summary").asText().length()).as(key).isLessThanOrEqualTo(120));
|
||||
for(String base : WebPerfSchema.TABLES)
|
||||
{
|
||||
QTableMetaData table = qInstance.getTable(config.applyPrefix(base));
|
||||
List<QHelpContent> help = table.getHelpContent() == null ? null : table.getHelpContent().get(WebPerfHelp.SLOT);
|
||||
assertThat(help).as(base + " table help").isNotEmpty();
|
||||
assertThat(help.get(0).getContent()).as(base + " help says how rows get created").contains("How rows get created");
|
||||
}
|
||||
assertThat(qInstance.getApp(config.getAppName()).getHelpContent()).containsKey(WebPerfHelp.SLOT);
|
||||
assertThat(WebPerfHelp.entries()).hasSize(WebPerfSchema.TABLES.size() + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Help a host already wrote is kept; the bundle only fills empty slots.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void hostHelpIsNotOverridden() throws Exception
|
||||
{
|
||||
QInstance qInstance = WebPerfTestSupport.newInstance();
|
||||
WebPerfQBitConfig config = WebPerfTestSupport.config();
|
||||
new WebPerfQBitProducer().withQBitConfig(config).produce(qInstance);
|
||||
QTableMetaData table = qInstance.getTable(config.applyPrefix(WebPerfSchema.BUDGET));
|
||||
table.getHelpContent().remove(WebPerfHelp.SLOT);
|
||||
table.withHelpContent(WebPerfHelp.SLOT, new QHelpContent("host words"));
|
||||
|
||||
WebPerfHelp.apply(qInstance, config);
|
||||
|
||||
assertThat(table.getHelpContent().get(WebPerfHelp.SLOT).get(0).getContent()).isEqualTo("host words");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static String read(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (Files.readString(path, StandardCharsets.UTF_8));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw (new IllegalStateException(e));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -127,9 +127,18 @@ public final class WebPerfTestSupport
|
||||
|
||||
List<String> statements = new ArrayList<>();
|
||||
StringBuilder current = new StringBuilder();
|
||||
boolean skip = false;
|
||||
for(String line : script.split("\n"))
|
||||
{
|
||||
if(line.trim().startsWith("--"))
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// a changeset limited to other databases (the dbms:postgresql //
|
||||
// orphan cleanup) is skipped, as Liquibase skips it on H2 //
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
if(line.startsWith("-- changeset "))
|
||||
{
|
||||
skip = line.contains(" dbms:") && !line.contains("h2");
|
||||
}
|
||||
if(skip || line.trim().startsWith("--"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user