Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66c785e1e5
|
||
|
|
0d07adc814
|
||
|
|
ceac89aee3
|
||
|
|
75a8d55da2
|
||
|
|
75d6f7f489
|
||
|
|
2e4cbd1537
|
||
|
|
31536a2472
|
||
|
|
1f39169f46 | ||
|
|
35bf7d7a46
|
||
|
|
e3aa05e3f9
|
||
|
|
2fc62b584e
|
||
|
|
32644c0d8f
|
||
|
|
219a028162
|
||
|
|
8627c5d144
|
||
|
|
bd50e1f2d9 | ||
|
|
d42ccc178c | ||
|
|
98c545ad4f | ||
|
|
3372dc9f68 | ||
|
|
d67dec8448 | ||
|
|
fd34b1c6c8 | ||
|
|
00148af810 | ||
|
|
15a564258b | ||
|
|
4437720546
|
||
|
|
e4bf215310 | ||
|
|
d76391f6a4
|
||
|
|
fd0322b8dc | ||
|
|
3efff6de95 | ||
|
|
d4d5029691
|
||
|
|
3de57f534b
|
||
|
|
8ef66f6efe |
No files matched your search
+11
-57
@@ -1,60 +1,14 @@
|
||||
version: 2.1
|
||||
|
||||
setup: true
|
||||
orbs:
|
||||
qqq-orb: kingsrook/qqq-orb@0.6.9
|
||||
|
||||
commands:
|
||||
configure-package-install:
|
||||
steps:
|
||||
- run:
|
||||
name: Keep package installation unattended
|
||||
command: |
|
||||
# These build machines are discarded after the job.
|
||||
sudo install -d /etc/needrestart/conf.d
|
||||
printf '%s\n' '$nrconf{restart} = "l";' | sudo tee /etc/needrestart/conf.d/99-qqq-ci.conf >/dev/null
|
||||
|
||||
qqq-orb: kingsrook/qqq-orb@0.8
|
||||
workflows:
|
||||
test_only:
|
||||
jobs:
|
||||
- qqq-orb/mvn_test_only:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
filters:
|
||||
branches:
|
||||
ignore: /(develop|release\/.*)/
|
||||
|
||||
publish_snapshot:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: snapshot
|
||||
filters:
|
||||
branches:
|
||||
only: [develop]
|
||||
|
||||
publish_release_candidate:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: release_candidate
|
||||
filters:
|
||||
branches:
|
||||
only: [/release\/.*/]
|
||||
|
||||
publish_release:
|
||||
jobs:
|
||||
- qqq-orb/mvn_publish:
|
||||
pre-steps:
|
||||
- configure-package-install
|
||||
context: [qqq-maven-registry-credentials]
|
||||
branch_type: release
|
||||
filters:
|
||||
branches:
|
||||
ignore: /.*/
|
||||
tags:
|
||||
only: [/^v\d+\.\d+\.\d+$/]
|
||||
setup:
|
||||
jobs:
|
||||
- qqq-orb/generate_pipeline:
|
||||
orb_version: '0.8'
|
||||
filters:
|
||||
branches:
|
||||
ignore: automation/qbit-rc-pending
|
||||
tags:
|
||||
only: /^v\d+\.\d+\.\d+$/
|
||||
@@ -0,0 +1,7 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
jobs:
|
||||
maven:
|
||||
uses: self:KofTwentyTwo/ci-workflows/.gitea/workflows/maven.yaml@v1
|
||||
secrets: inherit
|
||||
@@ -0,0 +1,23 @@
|
||||
name: CodeQL
|
||||
'on':
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
- release/**
|
||||
- hotfix/**
|
||||
pull_request: {}
|
||||
schedule:
|
||||
- cron: 41 16 * * 0
|
||||
workflow_dispatch: {}
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
security-events: write
|
||||
packages: read
|
||||
concurrency:
|
||||
group: codeql-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
jobs:
|
||||
analyze:
|
||||
uses: QRun-IO/qqq-orb/.github/workflows/qbit-codeql.yml@c288a8864fe9054f68410e1d78f5863aea4c4d22
|
||||
@@ -1,25 +1,74 @@
|
||||
# Cut the next release candidate (QRun-IO/qqq docs/QRUN-QBIT-REPO-STANDARD.md, C6):
|
||||
# run this workflow by hand, or merge a develop PR labelled `release:rc`. It merges develop into
|
||||
# the release line and the release/* push runs CircleCI publish_release_candidate.
|
||||
name: Release candidate
|
||||
|
||||
on:
|
||||
'on':
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dry_run:
|
||||
description: Print the plan without merging or creating branches
|
||||
description: Plan a cut without changing release state
|
||||
type: boolean
|
||||
default: false
|
||||
finalize:
|
||||
description: Retry finalization of an existing cut; do not cut another RC
|
||||
type: boolean
|
||||
default: false
|
||||
recover:
|
||||
description: Recover the same published RC after a deployment timeout; never
|
||||
reupload
|
||||
type: boolean
|
||||
default: false
|
||||
circle_build:
|
||||
description: Original Circle publisher build number (recovery only)
|
||||
type: string
|
||||
default: ''
|
||||
merge_sha:
|
||||
description: Existing cut merge_sha (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
bump_sha:
|
||||
description: Existing cut bump_sha (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
branch:
|
||||
description: Existing cut branch (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
version:
|
||||
description: Existing cut version (finalize retry only)
|
||||
type: string
|
||||
default: ''
|
||||
pull_request:
|
||||
types: [closed]
|
||||
branches: [develop]
|
||||
|
||||
types:
|
||||
- closed
|
||||
branches:
|
||||
- develop
|
||||
repository_dispatch:
|
||||
types:
|
||||
- qbit-rc-published
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
actions: read
|
||||
checks: read
|
||||
jobs:
|
||||
release-rc:
|
||||
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release:rc'))
|
||||
uses: QRun-IO/.github/.github/workflows/qbit-release-rc.yml@main
|
||||
if: github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch'
|
||||
|| (github.event_name == 'pull_request' && github.event.pull_request.merged
|
||||
== true && github.event.pull_request.base.ref == 'develop' && contains(github.event.pull_request.labels.*.name,
|
||||
'release:rc'))
|
||||
uses: QRun-IO/qqq-orb/.github/workflows/qbit-release-rc.yml@cc30f599e63c8e41629c99d23395bac1adb8bc44
|
||||
with:
|
||||
dry_run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
|
||||
dry_run: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run || false
|
||||
}}
|
||||
finalize: ${{ github.event_name == 'repository_dispatch' || (github.event_name
|
||||
== 'workflow_dispatch' && inputs.finalize) }}
|
||||
recover: ${{ github.event_name == 'workflow_dispatch' && inputs.recover || false
|
||||
}}
|
||||
circle_build: ${{ github.event_name == 'workflow_dispatch' && inputs.circle_build
|
||||
|| '' }}
|
||||
merge_sha: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.merge_sha
|
||||
|| inputs.merge_sha || '' }}
|
||||
bump_sha: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.bump_sha
|
||||
|| inputs.bump_sha || '' }}
|
||||
branch: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.branch
|
||||
|| inputs.branch || '' }}
|
||||
version: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.version
|
||||
|| inputs.version || '' }}
|
||||
secrets: inherit
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
profile: qbit
|
||||
orb_version: '0.8'
|
||||
default_branch: develop
|
||||
java_version: '21'
|
||||
browsers: true
|
||||
api_checks: false
|
||||
docs_only: false
|
||||
release_on_main: false
|
||||
release_tag_policy: stable
|
||||
test_branch_policy: non-release
|
||||
publish:
|
||||
snapshot: true
|
||||
release_candidate: true
|
||||
release: true
|
||||
asciidoc: false
|
||||
release_completion: true
|
||||
@@ -11,6 +11,9 @@ All notable changes to this project are documented here. The format follows Keep
|
||||
Requires QQQ 4.1.0-RC.15 or later (central health checks, help bundles, the spec-managed UI API extension contract, and `ClusterCaches` for multi-node deployments).
|
||||
|
||||
### Fixed
|
||||
- Table standard: every `quick_search_*` table now has `createDate` and `modifyDate` (`DATE_TIME`, not editable, `CREATE_DATE` and `MODIFY_DATE` behaviors). `quick_search_config_tombstone`, `quick_search_diagnostic_event` and `quick_search_validation_run` gain `modifyDate`; the other five declared the fields but never filled them, because they had no behaviors. All writes go through QQQ's own insert and update actions, so no writer changed. Run the additive DDL in `docs/MIGRATION-1.1.md` ("Standard dates on every table") before deploying; it is safe while the previous release runs.
|
||||
- Single-node clusters: the Quick Search index no longer asks for a replica it cannot place, so a one-node OpenSearch stays green instead of yellow and `quick_search.opensearch` is no longer DEGRADED. New `indexReplicas` (default null: automatic, `min(maxAutoReplicas, data nodes - 1)`) and `maxAutoReplicas` (default 1) config; zero config gives 0 replicas on one node and 1 on larger clusters. The target is set on every new physical index and reconciled on existing ones at startup with `PUT /<index>/_settings` when it differs (idempotent, logged; a failure is logged and reported, never blocks startup; indexes with `auto_expand_replicas` and OpenSearch Serverless are left alone). The status snapshot and the `quick_search.opensearch` health details gain `unassignedReplicaShards`, `targetReplicas` and `replicaSettingsFailed`; yellow on a single node with every primary active (only replicas unassigned) is reported UP with a note. Yellow with an unassigned primary, or on a multi-node cluster, stays DEGRADED; red stays DOWN.
|
||||
- Priming config records at startup, and recording diagnostic events, build their system session with the instance, so it has its all-access keys. Startup logged "QInstance was not supplied when creating a QSystemUserSession" once per node.
|
||||
- Multi-node deployments: a Quick Search config change (an index row, its fields or the settings row, from the admin UI or a config process) now clears the cached config on every node, not only the node that made the change. The runtime's config cache (the config store snapshot and settings, and the per-table enabled flags) is registered with QQQ `ClusterCaches` as `qbit-quick-search.config`, and `QuickSearchRuntime.invalidateConfig()` publishes a cluster invalidation. The 30 s and 60 s TTLs remain as the safety net. `QuickSearchFieldRules`' warn-once table set is registered as node-local. `QuickSearchClusterCachesTest` audits the package for unregistered static caches and covers a remote invalidation.
|
||||
- Indexing bookkeeping is no longer record-audited: the `quick_search_index` runtime fields written by basepull, full reindex and real-time indexing (status, last basepull time, document count, last run, real-time error count) and the settings row's priming outcome (`lastPrimedAt`, summary) are written with `omitDmlAudit`. On a production host these wrote about 470 "Record was Edited during process: Update search index" audit rows an hour. Admin edits to an index, its fields or the settings are still audited.
|
||||
- Real-time indexing failures now increase the table's error count by the number of failed events. Successful basepulls and full reindexes reset the count. Counter update failures are logged without failing the source write.
|
||||
|
||||
@@ -227,6 +227,8 @@ The panel's status is Indexed, Stale, Not indexed, Disabled (the table is turned
|
||||
| `runHistoryRetentionDays` | 30 | Purge run records older than this; null keeps them |
|
||||
| `fullReindexStaleMinutes` | 30 | A running full reindex that shows no sign of life for this long is treated as stopped: it no longer blocks a new one, and basepull recovers its tables. Keep it well above the time one page of `sourceBatchSize` records takes; null means the default |
|
||||
| `bulkBatchSize`, `maxBulkRequestBytes`, `sourceBatchSize` | 500, 5 MiB, 1000 | Batch sizes |
|
||||
| `indexReplicas` | null (automatic) | Index `number_of_replicas`; null means `min(maxAutoReplicas, data nodes - 1)`, so a single node gets 0 and stays green. Set on new indexes, reconciled on existing ones at startup |
|
||||
| `maxAutoReplicas` | 1 | Most replicas automatic sizing asks for |
|
||||
| `maxFieldLength` | 10000 | Truncate each indexed value |
|
||||
| `maxSearchLimit` | 100 | Largest page size |
|
||||
| `applyRecordSecurityLocks` | `true` | Re-read hits through `QueryAction` |
|
||||
@@ -253,8 +255,8 @@ The panel's status is Indexed, Stale, Not indexed, Disabled (the table is turned
|
||||
- `quick_search_settings`: one row: `indexingPaused` (with `pausedAt`, `pausedBy`, `pauseReason`) and the last self-priming report (`lastPrimedAt`, `lastPrimingSummary`).
|
||||
- `quick_search_config_tombstone`: tables (blank `fieldName`) and fields an admin removed; priming never re-adds them.
|
||||
- `quick_search_index_run`: `runType` (`BASEPULL`, `RECONCILE`, `FULL_REINDEX`), `status` (`RUNNING`, `COMPLETED`, `FAILED`, `CANCELLED`), counts, `errorMessage`, `cancelRequested`, `cancelRequestedBy`.
|
||||
- `quick_search_diagnostic_event` (with `enableDiagnosticTools`): `eventType` (`SEARCH_FAILED`, `TOOL_RUN`, `REINDEX`, `RATE_LIMITED`), `source`, `outcome`, `userName`, `tableNames`, `searchTerm` (tool runs only), `durationMillis`, `errorClass`, `errorMessage` (text), `detail` (text), `hostName`, `createDate`. Purged after `runHistoryRetentionDays`.
|
||||
- `quick_search_validation_run` (with `enableDiagnosticTools`): `status` (`PASS`, `WARN`, `FAIL`), `triggerType` (`MANUAL`, `SCHEDULED`), `userName`, `tableNames`, `sampleSize`, `tablesChecked`, `failCount`, `warnCount`, `summary`, `reportHtml` (HTML), `reportJson` (text), `startTime`, `endTime`, `createDate`. Purged after `runHistoryRetentionDays`.
|
||||
- `quick_search_diagnostic_event` (with `enableDiagnosticTools`): `eventType` (`SEARCH_FAILED`, `TOOL_RUN`, `REINDEX`, `RATE_LIMITED`), `source`, `outcome`, `userName`, `tableNames`, `searchTerm` (tool runs only), `durationMillis`, `errorClass`, `errorMessage` (text), `detail` (text), `hostName`, `createDate`, `modifyDate`. Purged after `runHistoryRetentionDays`.
|
||||
- `quick_search_validation_run` (with `enableDiagnosticTools`): `status` (`PASS`, `WARN`, `FAIL`), `triggerType` (`MANUAL`, `SCHEDULED`), `userName`, `tableNames`, `sampleSize`, `tablesChecked`, `failCount`, `warnCount`, `summary`, `reportHtml` (HTML), `reportJson` (text), `startTime`, `endTime`, `createDate`, `modifyDate`. Purged after `runHistoryRetentionDays`.
|
||||
- `quick_search_failed_event`: real-time events that could not be applied; `status` `PENDING` or `EXHAUSTED` after 10 attempts. Deletes made while a full reindex of all tables runs are also recorded here with status `AWAITING_REINDEX`: the reindex applies them to the new index after the alias swap (basepull does not replay them). While a table is `REBUILDING`, drift detection is suspended for it. Only one full reindex runs at a time: starting one while another is running fails. A full reindex shows it is running through its `FULL_REINDEX` run records, which stay `RUNNING` with `modifyDate` refreshed after every page. If it is killed mid-run (pod restart, OOM, deploy), recovery is automatic once its run records have shown no sign of life for `fullReindexStaleMinutes` (30 by default): the next basepull, or the next full reindex, marks those run records `FAILED`, returns the tables to `ACTIVE` with `lastBasepullTime` moved back to the run's start, and turns the `AWAITING_REINDEX` rows `PENDING` so basepull replays the deletes. No data is lost. A run that was only slow and is judged stopped notices before its alias swap and fails without swapping, or, after its swap, stops applying its captured deletes; basepull skips a replayed delete whose record exists again.
|
||||
|
||||
### Starter defaults and empty-state help
|
||||
|
||||
@@ -238,3 +238,33 @@ The qbit now sets bundle help (`help/quick-search.yaml`) on the Quick Search Adm
|
||||
2. Grant `quick_search_index_field`, `quick_search_settings` and `quick_search_config_tombstone` permissions (read, and edit where admins should change them) next to the existing Quick Search grants.
|
||||
3. Upgrade and start. The Search Diagnostics widget should not say the searchable tables come from code, and shows the first priming's summary.
|
||||
4. Optionally move code-declared search config into the records and delete the annotations: the rows stay and are now the owner's.
|
||||
|
||||
## Standard dates on every table (after 1.1.0-RC.16)
|
||||
|
||||
Every `quick_search_*` table now has a `createDate` and a `modifyDate`: `DATE_TIME`, not editable, set by QQQ's `CREATE_DATE` and `MODIFY_DATE` behaviors. The QBit writes all of its tables with QQQ's own insert and update actions (no raw SQL), so the behaviors set them on every write; nothing else about the tables, the index documents or how a document is identified in the index changes.
|
||||
|
||||
- `quick_search_config_tombstone`, `quick_search_diagnostic_event` and `quick_search_validation_run` gain `modifyDate` (they had `createDate` only). For the tombstone and the two logs it equals `createDate` and never moves, since the QBit only inserts and deletes their rows.
|
||||
- The other five tables already declared both fields, but without the behaviors, so the QBit never filled them. They are filled now. On `quick_search_index_run`, `modifyDate` stays the full reindex heartbeat (the heartbeat writes it explicitly); any other update of a run row, such as completing it, now moves it too, which only makes the run look more recently alive.
|
||||
- The Search Diagnostics "last error" time reads `quick_search_index.modifyDate`, which now moves with every update of the row (including document counts), so it is the time of the last update of an index that has an error message, not strictly of the error.
|
||||
|
||||
### DDL (run before deploying)
|
||||
|
||||
A host that wrote its own DDL must have the columns before this release starts, because the QBit now writes them. Run `HOST-DDL-postgresql.sql`'s equivalent, one block per table (safe to run while the previous release is running, and safe to repeat):
|
||||
|
||||
```sql
|
||||
-- repeat for quick_search_index, quick_search_index_field, quick_search_index_run, quick_search_failed_event,
|
||||
-- quick_search_settings, quick_search_config_tombstone, quick_search_diagnostic_event, quick_search_validation_run
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = 'quick_search_config_tombstone' AND column_name = 'create_date') THEN
|
||||
ALTER TABLE quick_search_config_tombstone ADD COLUMN create_date TIMESTAMP WITHOUT TIME ZONE DEFAULT now();
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = 'quick_search_config_tombstone' AND column_name = 'modify_date') THEN
|
||||
ALTER TABLE quick_search_config_tombstone ADD COLUMN modify_date TIMESTAMP WITHOUT TIME ZONE DEFAULT now();
|
||||
UPDATE quick_search_config_tombstone SET modify_date = create_date WHERE create_date IS NOT NULL;
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
```
|
||||
|
||||
The columns are nullable with a default of `now()`, which PostgreSQL 11 and later adds without rewriting the table (the previous release, which does not write them, gets the current time from the default). Existing rows take their own creation time where the table has one (`create_date` for the new `modify_date`; `start_time` for a newly added `create_date` on `quick_search_index_run` and `quick_search_validation_run`), otherwise the time of the migration. The one-time `UPDATE` touches every row, so on a very large log table run it in id ranges. Names are the snake_case a host gets when it derives backend names from field names; without that, the columns are `"createDate"` and `"modifyDate"`. MySQL: `DATETIME DEFAULT CURRENT_TIMESTAMP`, and drop the `DO` wrapper. No setting, customizer or deployment order is needed beyond running the DDL first.
|
||||
@@ -18,6 +18,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<properties>
|
||||
<qqq.version>4.1.0-RC.26</qqq.version> <!-- feeds qbit-build-parent's qqq-bom-pom import -->
|
||||
<qbit.guardrails.enforce>true</qbit.guardrails.enforce>
|
||||
<qbit.guardrails.strictUiApiRoutes>true</qbit.guardrails.strictUiApiRoutes>
|
||||
<revision>1.1.0-SNAPSHOT</revision>
|
||||
@@ -32,7 +33,7 @@
|
||||
<parent>
|
||||
<groupId>com.kingsrook</groupId>
|
||||
<artifactId>qbit-build-parent</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<version>2.2.1</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.kingsrook.qbits</groupId>
|
||||
@@ -283,7 +284,7 @@
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<qqq.snapshot.version>4.1.0-RC.15</qqq.snapshot.version>
|
||||
<qqq.snapshot.version>4.1.0-RC.26</qqq.snapshot.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -296,18 +297,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -81,6 +81,7 @@ public class QuickSearchQBitConfig implements QBitConfig
|
||||
public static final int DEFAULT_VALIDATION_SAMPLE_SIZE = 50;
|
||||
public static final int MAX_VALIDATION_SAMPLE_SIZE = 1000;
|
||||
public static final int DEFAULT_DIAGNOSTIC_RUNS_PER_MINUTE = 30;
|
||||
public static final int DEFAULT_MAX_AUTO_REPLICAS = 1;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// a live full reindex refreshes its run record after every page; a page is //
|
||||
@@ -113,6 +114,8 @@ public class QuickSearchQBitConfig implements QBitConfig
|
||||
private Integer responseTimeoutMillis = 60000;
|
||||
private Integer maxConnections = 30;
|
||||
private Integer maxBulkRequestBytes = 5 * 1024 * 1024;
|
||||
private Integer indexReplicas;
|
||||
private Integer maxAutoReplicas = DEFAULT_MAX_AUTO_REPLICAS;
|
||||
private QCodeReference transportCustomizer;
|
||||
private QuickSearchStartupMode startupMode = QuickSearchStartupMode.FAIL_FAST;
|
||||
private Boolean enableRealTimeIndexing = true;
|
||||
@@ -443,6 +446,16 @@ public class QuickSearchQBitConfig implements QBitConfig
|
||||
{
|
||||
errors.add("basepullOverlapSeconds must not be negative for QuickSearchQBit");
|
||||
}
|
||||
|
||||
if(indexReplicas != null && indexReplicas < 0)
|
||||
{
|
||||
errors.add("indexReplicas must not be negative for QuickSearchQBit");
|
||||
}
|
||||
|
||||
if(maxAutoReplicas != null && maxAutoReplicas < 0)
|
||||
{
|
||||
errors.add("maxAutoReplicas must not be negative for QuickSearchQBit");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1495,6 +1508,73 @@ public class QuickSearchQBitConfig implements QBitConfig
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for indexReplicas: number_of_replicas for the Quick Search index.
|
||||
** Null (the default) means automatic: min(maxAutoReplicas, data nodes - 1),
|
||||
** so a single-node cluster gets 0 replicas and stays green. Applied when a
|
||||
** physical index is created and reconciled on existing indexes at startup.
|
||||
** Ignored for OpenSearch Serverless (awsServiceName aoss).
|
||||
*******************************************************************************/
|
||||
public Integer getIndexReplicas()
|
||||
{
|
||||
return (this.indexReplicas);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for indexReplicas
|
||||
*******************************************************************************/
|
||||
public void setIndexReplicas(Integer indexReplicas)
|
||||
{
|
||||
this.indexReplicas = indexReplicas;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for indexReplicas
|
||||
*******************************************************************************/
|
||||
public QuickSearchQBitConfig withIndexReplicas(Integer indexReplicas)
|
||||
{
|
||||
this.indexReplicas = indexReplicas;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for maxAutoReplicas: the most replicas automatic mode (indexReplicas
|
||||
** null) asks for; it never asks for more than data nodes - 1. Default 1.
|
||||
*******************************************************************************/
|
||||
public Integer getMaxAutoReplicas()
|
||||
{
|
||||
return (this.maxAutoReplicas);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for maxAutoReplicas
|
||||
*******************************************************************************/
|
||||
public void setMaxAutoReplicas(Integer maxAutoReplicas)
|
||||
{
|
||||
this.maxAutoReplicas = maxAutoReplicas;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for maxAutoReplicas
|
||||
*******************************************************************************/
|
||||
public QuickSearchQBitConfig withMaxAutoReplicas(Integer maxAutoReplicas)
|
||||
{
|
||||
this.maxAutoReplicas = maxAutoReplicas;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for transportCustomizer: QCodeReference to an OpenSearchTransportCustomizer
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -758,7 +758,7 @@ public class QuickSearchRuntime
|
||||
{
|
||||
return;
|
||||
}
|
||||
QContext.init(qInstance, new QSystemUserSession());
|
||||
QContext.init(qInstance, new QSystemUserSession(qInstance));
|
||||
try
|
||||
{
|
||||
configStore.tryPrime();
|
||||
|
||||
@@ -30,11 +30,41 @@ import com.kingsrook.qqq.openapi.model.Schema;
|
||||
/*******************************************************************************
|
||||
** Immutable administrative snapshot. Null measurements are unknown, never zero.
|
||||
** Counts come from persisted diagnostics; countsCheckedAt identifies their age.
|
||||
**
|
||||
** unassignedReplicaShards is the unassigned shard count when every primary is
|
||||
** active (so all unassigned shards are replicas), else null; targetReplicas and
|
||||
** replicaSettingsFailed report the index replica sizing (null when unknown).
|
||||
*******************************************************************************/
|
||||
public record QuickSearchStatus(State state, Boolean clusterReachable, String clusterHealth, Integer nodes, Integer activeShards, Integer unassignedShards,
|
||||
Integer unassignedReplicaShards, Integer targetReplicas, Boolean replicaSettingsFailed,
|
||||
Boolean indexingPaused, List<IndexRow> indexes, Integer pending, Integer exhausted, Boolean backlogTruncated,
|
||||
Boolean tablesTruncated, Instant lastSuccessfulSync, String lastError, Instant checkedAt, String homeHref) implements ToSchema
|
||||
{
|
||||
/*******************************************************************************
|
||||
** The 1.1.0-RC.14 shape, without the replica measurements (all unknown).
|
||||
*******************************************************************************/
|
||||
public QuickSearchStatus(State state, Boolean clusterReachable, String clusterHealth, Integer nodes, Integer activeShards, Integer unassignedShards,
|
||||
Boolean indexingPaused, List<IndexRow> indexes, Integer pending, Integer exhausted, Boolean backlogTruncated,
|
||||
Boolean tablesTruncated, Instant lastSuccessfulSync, String lastError, Instant checkedAt, String homeHref)
|
||||
{
|
||||
this(state, clusterReachable, clusterHealth, nodes, activeShards, unassignedShards, null, null, null, indexingPaused, indexes, pending, exhausted,
|
||||
backlogTruncated, tablesTruncated, lastSuccessfulSync, lastError, checkedAt, homeHref);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Yellow only because replicas cannot be placed on a single-node cluster:
|
||||
** one node, every primary active and every unassigned shard a replica.
|
||||
** Such a cluster cannot do better, so it is healthy rather than degraded.
|
||||
*******************************************************************************/
|
||||
public static boolean isSingleNodeReplicaYellow(String clusterHealth, Integer nodes, Integer unassignedReplicaShards)
|
||||
{
|
||||
return ("yellow".equals(clusterHealth) && Integer.valueOf(1).equals(nodes) && unassignedReplicaShards != null && unassignedReplicaShards > 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Published wire schema for the same immutable value used by Java hosts.
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -126,6 +126,9 @@ public class QuickSearchStatusSpec extends AbstractJsonEndpointSpec
|
||||
{
|
||||
status.put(name, field(Type.INTEGER, "Cluster health counter; null when unavailable.", true));
|
||||
}
|
||||
status.put("unassignedReplicaShards", field(Type.INTEGER, "Unassigned shards when every primary is active (all are replicas); null when unknown or a primary is not active.", true));
|
||||
status.put("targetReplicas", field(Type.INTEGER, "number_of_replicas Quick Search applies to its index; null when unknown or not managed (Serverless).", true));
|
||||
status.put("replicaSettingsFailed", field(Type.BOOLEAN, "Sizing or applying the index replicas failed at startup; null when not attempted.", true));
|
||||
status.put("indexingPaused", field(Type.BOOLEAN, "Indexing is paused; search can still serve.", true));
|
||||
status.put("indexes", new Schema().withType(Type.ARRAY).withItems(new Schema().withRef("#/components/schemas/QuickSearchIndexStatusV1"))
|
||||
.withDescription("At most 100 persisted index rows, ordered by id."));
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ public class DiagnosticEventRecorder implements AutoCloseable
|
||||
*******************************************************************************/
|
||||
private void insert(QInstance qInstance, String tableName, QuickSearchDiagnosticEvent event)
|
||||
{
|
||||
QSession session = new QSystemUserSession();
|
||||
QSession session = new QSystemUserSession(qInstance);
|
||||
try
|
||||
{
|
||||
QContext.init(qInstance, session);
|
||||
|
||||
@@ -135,6 +135,9 @@ public final class StatusDiagnostics
|
||||
Integer nodes = null;
|
||||
Integer active = null;
|
||||
Integer unassigned = null;
|
||||
Integer unassignedReplicas = null;
|
||||
Integer targetReplicas = null;
|
||||
Boolean replicaSettingsFailed = null;
|
||||
State state = degraded ? State.DEGRADED : State.OK;
|
||||
if(!truncated && !indexes.isEmpty() && indexes.stream().noneMatch(row -> Boolean.TRUE.equals(row.enabled())))
|
||||
{
|
||||
@@ -152,7 +155,15 @@ public final class StatusDiagnostics
|
||||
nodes = number(body, "number_of_nodes");
|
||||
active = number(body, "active_shards");
|
||||
unassigned = number(body, "unassigned_shards");
|
||||
if(IndexValidator.healthLevel(health) != DiagnosticsHtml.Level.OK || body.path("timed_out").asBoolean())
|
||||
unassignedReplicas = unassignedReplicaShards(body, unassigned);
|
||||
var replicaStatus = runtime.getClient().getReplicaStatus();
|
||||
if(replicaStatus != null)
|
||||
{
|
||||
targetReplicas = replicaStatus.targetReplicas();
|
||||
replicaSettingsFailed = replicaStatus.failed();
|
||||
}
|
||||
boolean singleNodeReplicas = QuickSearchStatus.isSingleNodeReplicaYellow(health, nodes, unassignedReplicas);
|
||||
if((IndexValidator.healthLevel(health) != DiagnosticsHtml.Level.OK && !singleNodeReplicas) || body.path("timed_out").asBoolean())
|
||||
{
|
||||
state = "red".equals(health) ? State.DOWN : State.DEGRADED;
|
||||
}
|
||||
@@ -167,7 +178,8 @@ public final class StatusDiagnostics
|
||||
lastError = "OpenSearch health is unavailable; see Quick Search diagnostics.";
|
||||
}
|
||||
}
|
||||
return (new QuickSearchStatus(state, reachable, health, nodes, active, unassigned, paused, indexes, pending, exhausted, backlog.size() > MAX_BACKLOG,
|
||||
return (new QuickSearchStatus(state, reachable, health, nodes, active, unassigned, unassignedReplicas, targetReplicas, replicaSettingsFailed,
|
||||
paused, indexes, pending, exhausted, backlog.size() > MAX_BACKLOG,
|
||||
truncated, lastSync, lastError, Instant.now(), homeHref));
|
||||
}
|
||||
|
||||
@@ -193,6 +205,30 @@ public final class StatusDiagnostics
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** From index-level cluster health: the unassigned shards when nothing is
|
||||
** initializing and every index has all its primaries active (so every
|
||||
** unassigned shard is a replica); null otherwise or when unknown.
|
||||
*******************************************************************************/
|
||||
static Integer unassignedReplicaShards(JsonNode body, Integer unassigned)
|
||||
{
|
||||
if(unassigned == null || !body.path("indices").isObject() || !Integer.valueOf(0).equals(number(body, "initializing_shards")))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
for(JsonNode index : body.path("indices"))
|
||||
{
|
||||
Integer primaries = number(index, "number_of_shards");
|
||||
if(primaries == null || !primaries.equals(number(index, "active_primary_shards")))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
}
|
||||
return (unassigned);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Preserve unknown counters from incomplete cluster responses.
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -187,6 +187,11 @@ public class QuickSearchHealthChecks implements HealthCheckSupplier
|
||||
{
|
||||
outcome = HealthCheckOutcome.up("OpenSearch is green");
|
||||
}
|
||||
else if(Boolean.TRUE.equals(status.clusterReachable()) && QuickSearchStatus.isSingleNodeReplicaYellow(status.clusterHealth(), status.nodes(), status.unassignedReplicaShards()))
|
||||
{
|
||||
outcome = HealthCheckOutcome.up("OpenSearch is yellow only because replicas cannot be assigned on a single node");
|
||||
outcome.getDetails().withValue("note", "replicas cannot be assigned on a single-node cluster");
|
||||
}
|
||||
else
|
||||
{
|
||||
outcome = HealthCheckOutcome.degraded("OpenSearch health is yellow or incomplete");
|
||||
@@ -195,6 +200,9 @@ public class QuickSearchHealthChecks implements HealthCheckSupplier
|
||||
detail(outcome, "nodes", status.nodes());
|
||||
detail(outcome, "activeShards", status.activeShards());
|
||||
detail(outcome, "unassignedShards", status.unassignedShards());
|
||||
detail(outcome, "unassignedReplicaShards", status.unassignedReplicaShards());
|
||||
detail(outcome, "targetReplicas", status.targetReplicas());
|
||||
detail(outcome, "replicaSettingsFailed", status.replicaSettingsFailed());
|
||||
return (outcome);
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -29,6 +29,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.audits.AuditLevel;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.audits.QAuditRules;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.DynamicDefaultValueBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
|
||||
@@ -119,8 +120,8 @@ public class QuickSearchConfigMetaDataHelper
|
||||
.withField(new QFieldMetaData("sortOrder", QFieldType.INTEGER))
|
||||
.withField(new QFieldMetaData("source", QFieldType.STRING).withIsEditable(false).withPossibleValueSourceName(config.applyTablePrefix(CONFIG_SOURCE_PVS)))
|
||||
.withField(new QFieldMetaData("ownerEdited", QFieldType.BOOLEAN).withLabel("Edited by Owner").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false))
|
||||
.withSection(new QFieldSection("identity", "Field", new QIcon("text_fields"), Tier.T1, List.of("id", "quickSearchIndexId", "fieldName", "weight", "role")))
|
||||
.withSection(new QFieldSection("matching", "Matching", new QIcon("tune"), Tier.T2, List.of("analyzer", "includeInSnippet", "includeLabel", "sortOrder")))
|
||||
.withSection(new QFieldSection("origin", "Origin", new QIcon("history"), Tier.T3, List.of("source", "ownerEdited", "createDate", "modifyDate"))));
|
||||
@@ -155,8 +156,8 @@ public class QuickSearchConfigMetaDataHelper
|
||||
.withField(new QFieldMetaData("lastPrimedAt", QFieldType.DATE_TIME).withLabel("Last Primed").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("lastPrimingSummary", QFieldType.TEXT).withLabel("Last Priming").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("lastPrimingNewTables", QFieldType.INTEGER).withLabel("Tables Added by Last Priming").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false))
|
||||
.withSection(new QFieldSection("pause", "Indexing", new QIcon("pause_circle"), Tier.T1, List.of("id", "indexingPaused", "pauseReason", "pausedAt", "pausedBy")))
|
||||
.withSection(new QFieldSection("priming", "Self-priming", new QIcon("auto_mode"), Tier.T2, List.of("lastPrimedAt", "lastPrimingSummary", "lastPrimingNewTables")))
|
||||
.withSection(new QFieldSection("dates", "Dates", new QIcon("calendar_today"), Tier.T3, List.of("createDate", "modifyDate"))));
|
||||
@@ -188,7 +189,8 @@ public class QuickSearchConfigMetaDataHelper
|
||||
.withField(new QFieldMetaData("fieldName", QFieldType.STRING).withLabel("Field (blank: whole table)").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("removedBy", QFieldType.STRING).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("reason", QFieldType.STRING).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withLabel("Removed").withIsEditable(false)));
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withLabel("Removed").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-10
@@ -23,6 +23,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.audits.AuditLevel;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.audits.QAuditRules;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.DynamicDefaultValueBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
@@ -103,8 +104,8 @@ public class QuickSearchTableMetaDataHelper
|
||||
.withField(new QFieldMetaData("realTimeErrorCount", QFieldType.INTEGER).withIsEditable(false)
|
||||
.withHelpContent(new QHelpContent("Real-time indexing failures since the last full reindex or basepull")))
|
||||
.withField(new QFieldMetaData("status", QFieldType.STRING).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false))
|
||||
.withSection(new QFieldSection("identity", "Search Index", new QIcon("manage_search"), Tier.T1,
|
||||
List.of("id", "tableName", "enabled", "status", "basepullIntervalMinutes", "basepullTimestampField")))
|
||||
.withSection(new QFieldSection("fields", "Searchable Fields", new QIcon("text_fields"), Tier.T2, null)
|
||||
@@ -153,8 +154,8 @@ public class QuickSearchTableMetaDataHelper
|
||||
.withField(new QFieldMetaData("errorMessage", QFieldType.TEXT).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("cancelRequested", QFieldType.BOOLEAN).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("cancelRequestedBy", QFieldType.STRING).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withLabel("Last Heartbeat").withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withLabel("Last Heartbeat").withIsEditable(false))
|
||||
.withSection(new QFieldSection("run", "Run", new QIcon("history"), Tier.T1, List.of("id", "quickSearchIndexId", "runType", "status", "startTime", "endTime")))
|
||||
.withSection(new QFieldSection("counts", "Counts", new QIcon("functions"), Tier.T2, List.of("recordsProcessed", "recordsIndexed", "errorCount", "errorMessage")))
|
||||
.withSection(new QFieldSection("cancel", "Cancel", new QIcon("cancel"), Tier.T2, List.of("cancelRequested", "cancelRequestedBy")))
|
||||
@@ -193,8 +194,8 @@ public class QuickSearchTableMetaDataHelper
|
||||
.withField(new QFieldMetaData("attempts", QFieldType.INTEGER).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("status", QFieldType.STRING).withIsEditable(false)
|
||||
.withPossibleValueSourceName(config.applyTablePrefix(QuickSearchConfigMetaDataHelper.EVENT_STATUS_PVS)))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false))
|
||||
.withSection(new QFieldSection("event", "Event", new QIcon("error_outline"), Tier.T1, List.of("id", "tableName", "recordId", "action", "status")))
|
||||
.withSection(new QFieldSection("error", "Error and retries", new QIcon("replay"), Tier.T2, List.of("errorMessage", "attempts")))
|
||||
.withSection(new QFieldSection("dates", "Dates", new QIcon("calendar_today"), Tier.T3, List.of("createDate", "modifyDate"))));
|
||||
@@ -232,8 +233,9 @@ public class QuickSearchTableMetaDataHelper
|
||||
.withField(new QFieldMetaData("errorMessage", QFieldType.TEXT).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("detail", QFieldType.TEXT).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("hostName", QFieldType.STRING).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withSection(new QFieldSection("identity", "Event", new QIcon("bug_report"), Tier.T1, List.of("id", "createDate", "eventType", "source", "outcome")))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false))
|
||||
.withSection(new QFieldSection("identity", "Event", new QIcon("bug_report"), Tier.T1, List.of("id", "createDate", "modifyDate", "eventType", "source", "outcome")))
|
||||
.withSection(new QFieldSection("request", "Request", new QIcon("search"), Tier.T2, List.of("userName", "tableNames", "searchTerm", "durationMillis", "hostName")))
|
||||
.withSection(new QFieldSection("error", "Error and detail", new QIcon("error_outline"), Tier.T2, List.of("errorClass", "errorMessage", "detail"))));
|
||||
}
|
||||
@@ -273,9 +275,10 @@ public class QuickSearchTableMetaDataHelper
|
||||
.withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json"))))
|
||||
.withField(new QFieldMetaData("startTime", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("endTime", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("createDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.CREATE_DATE).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME).withBehavior(DynamicDefaultValueBehavior.MODIFY_DATE).withIsEditable(false))
|
||||
.withSection(new QFieldSection("identity", "Run", new QIcon("fact_check"), Tier.T1, List.of("id", "status", "summary", "triggerType", "startTime", "endTime")))
|
||||
.withSection(new QFieldSection("scope", "Scope", new QIcon("table_chart"), Tier.T2, List.of("userName", "tableNames", "sampleSize", "tablesChecked", "failCount", "warnCount", "createDate")))
|
||||
.withSection(new QFieldSection("scope", "Scope", new QIcon("table_chart"), Tier.T2, List.of("userName", "tableNames", "sampleSize", "tablesChecked", "failCount", "warnCount", "createDate", "modifyDate")))
|
||||
.withSection(new QFieldSection("report", "Report", new QIcon("description"), Tier.T2, List.of("reportHtml")))
|
||||
.withSection(new QFieldSection("data", "Report data (JSON)", new QIcon("data_object"), Tier.T3, List.of("reportJson"))));
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public class QuickSearchConfigTombstone extends QRecordEntity
|
||||
@QField()
|
||||
private Instant createDate;
|
||||
|
||||
@QField()
|
||||
private Instant modifyDate;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for id
|
||||
@@ -224,4 +227,35 @@ public class QuickSearchConfigTombstone extends QRecordEntity
|
||||
this.createDate = createDate;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for modifyDate
|
||||
*******************************************************************************/
|
||||
public Instant getModifyDate()
|
||||
{
|
||||
return (this.modifyDate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for modifyDate
|
||||
*******************************************************************************/
|
||||
public void setModifyDate(Instant modifyDate)
|
||||
{
|
||||
this.modifyDate = modifyDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for modifyDate
|
||||
*******************************************************************************/
|
||||
public QuickSearchConfigTombstone withModifyDate(Instant modifyDate)
|
||||
{
|
||||
this.modifyDate = modifyDate;
|
||||
return (this);
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,9 @@ public class QuickSearchDiagnosticEvent extends QRecordEntity
|
||||
@QField()
|
||||
private Instant createDate;
|
||||
|
||||
@QField()
|
||||
private Instant modifyDate;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -509,4 +512,35 @@ public class QuickSearchDiagnosticEvent extends QRecordEntity
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for modifyDate
|
||||
*******************************************************************************/
|
||||
public Instant getModifyDate()
|
||||
{
|
||||
return (this.modifyDate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for modifyDate
|
||||
*******************************************************************************/
|
||||
public void setModifyDate(Instant modifyDate)
|
||||
{
|
||||
this.modifyDate = modifyDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for modifyDate
|
||||
*******************************************************************************/
|
||||
public QuickSearchDiagnosticEvent withModifyDate(Instant modifyDate)
|
||||
{
|
||||
this.modifyDate = modifyDate;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,6 +89,9 @@ public class QuickSearchValidationRun extends QRecordEntity
|
||||
@QField()
|
||||
private Instant createDate;
|
||||
|
||||
@QField()
|
||||
private Instant modifyDate;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -573,4 +576,35 @@ public class QuickSearchValidationRun extends QRecordEntity
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for modifyDate
|
||||
*******************************************************************************/
|
||||
public Instant getModifyDate()
|
||||
{
|
||||
return (this.modifyDate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for modifyDate
|
||||
*******************************************************************************/
|
||||
public void setModifyDate(Instant modifyDate)
|
||||
{
|
||||
this.modifyDate = modifyDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for modifyDate
|
||||
*******************************************************************************/
|
||||
public QuickSearchValidationRun withModifyDate(Instant modifyDate)
|
||||
{
|
||||
this.modifyDate = modifyDate;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
||||
+153
-3
@@ -34,6 +34,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.kingsrook.qbits.quicksearch.QuickSearchAuthMode;
|
||||
import com.kingsrook.qbits.quicksearch.QuickSearchQBitConfig;
|
||||
import com.kingsrook.qbits.quicksearch.QuickSearchableTableConfig;
|
||||
import com.kingsrook.qbits.quicksearch.config.QuickSearchFieldRules;
|
||||
@@ -127,11 +129,26 @@ public class QuickSearchOpenSearchClient implements Closeable
|
||||
private final String indexName;
|
||||
private final int maxBulkRequestBytes;
|
||||
private final ObjectMapper sizingMapper;
|
||||
private final Integer indexReplicas;
|
||||
private final Integer maxAutoReplicas;
|
||||
private final Boolean replicasManaged;
|
||||
|
||||
private volatile Boolean mappingOutdated = false;
|
||||
private volatile Boolean indexCreated = false;
|
||||
private volatile Instant indexCreatedAt;
|
||||
private Boolean closed = false;
|
||||
private volatile ReplicaStatus replicaStatus;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Outcome of the latest replica sizing: the target number_of_replicas, the
|
||||
** data nodes it was sized for (null when explicitly configured), how many
|
||||
** physical indexes were changed, and whether applying it failed.
|
||||
*******************************************************************************/
|
||||
public record ReplicaStatus(Integer targetReplicas, Integer dataNodes, Integer updatedIndexes, Boolean failed)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -146,6 +163,9 @@ public class QuickSearchOpenSearchClient implements Closeable
|
||||
this.indexName = config.getOpensearchIndexName();
|
||||
this.maxBulkRequestBytes = config.getMaxBulkRequestBytes() == null ? 5 * 1024 * 1024 : config.getMaxBulkRequestBytes();
|
||||
this.sizingMapper = new ObjectMapper().registerModule(new JavaTimeModule()).disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
this.indexReplicas = config.getIndexReplicas();
|
||||
this.maxAutoReplicas = config.getMaxAutoReplicas() == null ? QuickSearchQBitConfig.DEFAULT_MAX_AUTO_REPLICAS : config.getMaxAutoReplicas();
|
||||
this.replicasManaged = !(config.getEffectiveAuthMode() == QuickSearchAuthMode.AWS_SIGV4 && "aoss".equals(config.getEffectiveAwsServiceName()));
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +192,7 @@ public class QuickSearchOpenSearchClient implements Closeable
|
||||
LOG.info("OpenSearch index already exists", logPair("indexName", indexName));
|
||||
extendMapping();
|
||||
}
|
||||
reconcileReplicas();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -314,13 +335,21 @@ public class QuickSearchOpenSearchClient implements Closeable
|
||||
{
|
||||
try
|
||||
{
|
||||
Integer replicas = replicasForNewIndex();
|
||||
client.indices().create(CreateIndexRequest.of(r -> r
|
||||
.index(physicalIndex)
|
||||
.settings(s -> s
|
||||
.analysis(a -> a
|
||||
.settings(s ->
|
||||
{
|
||||
s.analysis(a -> a
|
||||
.analyzer(INDEX_ANALYZER, an -> an.custom(c -> c.tokenizer("standard").filter("lowercase", "edge_ngram_filter")))
|
||||
.analyzer(SEARCH_ANALYZER, an -> an.custom(c -> c.tokenizer("standard").filter("lowercase")))
|
||||
.filter("edge_ngram_filter", f -> f.definition(d -> d.edgeNgram(en -> en.minGram(2).maxGram(20))))))
|
||||
.filter("edge_ngram_filter", f -> f.definition(d -> d.edgeNgram(en -> en.minGram(2).maxGram(20)))));
|
||||
if(replicas != null)
|
||||
{
|
||||
s.numberOfReplicas(replicas);
|
||||
}
|
||||
return (s);
|
||||
})
|
||||
.mappings(buildMapping())));
|
||||
}
|
||||
catch(OpenSearchException | java.io.IOException e)
|
||||
@@ -331,6 +360,127 @@ public class QuickSearchOpenSearchClient implements Closeable
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Replicas a new physical index should ask for; null leaves the server
|
||||
** default (Serverless, or the cluster could not be sized; logged).
|
||||
*******************************************************************************/
|
||||
private Integer replicasForNewIndex()
|
||||
{
|
||||
if(!Boolean.TRUE.equals(replicasManaged))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
try
|
||||
{
|
||||
ReplicaStatus target = targetReplicas();
|
||||
replicaStatus = new ReplicaStatus(target.targetReplicas(), target.dataNodes(), 0, false);
|
||||
return (target.targetReplicas());
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
replicaStatus = new ReplicaStatus(null, null, 0, true);
|
||||
LOG.warn("Could not size Quick Search index replicas; the new index uses the server default", e, logPair("indexName", indexName));
|
||||
return (null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The configured indexReplicas, else min(maxAutoReplicas, data nodes - 1)
|
||||
** from cluster health, so a single-node cluster gets 0 and stays green.
|
||||
*******************************************************************************/
|
||||
ReplicaStatus targetReplicas() throws QException
|
||||
{
|
||||
if(indexReplicas != null)
|
||||
{
|
||||
return (new ReplicaStatus(indexReplicas, null, 0, false));
|
||||
}
|
||||
QuickSearchDiagnosticsOperations.RawResponse health = new QuickSearchDiagnosticsOperations(this).raw("GET", "/_cluster/health", null);
|
||||
QuickSearchDiagnosticsOperations.requireOk(health, "Cluster health unavailable");
|
||||
JsonNode dataNodes = health.body() == null ? null : health.body().path("number_of_data_nodes");
|
||||
if(dataNodes == null || !dataNodes.isNumber())
|
||||
{
|
||||
throw (new QException("Cluster health did not report number_of_data_nodes"));
|
||||
}
|
||||
return (new ReplicaStatus(autoReplicas(dataNodes.intValue(), maxAutoReplicas), dataNodes.intValue(), 0, false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Automatic replica count: a replica can only be assigned to a different
|
||||
** data node than its primary, so never more than data nodes - 1.
|
||||
*******************************************************************************/
|
||||
static int autoReplicas(int dataNodes, int maxAutoReplicas)
|
||||
{
|
||||
return (Math.max(0, Math.min(maxAutoReplicas, dataNodes - 1)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Bring number_of_replicas of the physical index(es) behind the alias to
|
||||
** the target. Idempotent (only differing indexes are updated) and failure
|
||||
** tolerant: a failure is logged and kept in {@link #getReplicaStatus()},
|
||||
** never thrown, so it cannot block startup. Indexes with
|
||||
** auto_expand_replicas set are left to OpenSearch. Null on Serverless.
|
||||
*******************************************************************************/
|
||||
public ReplicaStatus reconcileReplicas()
|
||||
{
|
||||
if(!Boolean.TRUE.equals(replicasManaged))
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
Integer target = null;
|
||||
Integer nodes = null;
|
||||
try
|
||||
{
|
||||
ReplicaStatus sized = targetReplicas();
|
||||
target = sized.targetReplicas();
|
||||
nodes = sized.dataNodes();
|
||||
QuickSearchDiagnosticsOperations operations = new QuickSearchDiagnosticsOperations(this);
|
||||
QuickSearchDiagnosticsOperations.RawResponse settings = operations.raw("GET", "/" + QuickSearchDiagnosticsOperations.encode(indexName) + "/_settings", null);
|
||||
QuickSearchDiagnosticsOperations.requireOk(settings, "Index settings unavailable");
|
||||
int updated = 0;
|
||||
for(Map.Entry<String, JsonNode> entry : settings.body().properties())
|
||||
{
|
||||
JsonNode index = entry.getValue().path("settings").path("index");
|
||||
String current = index.path("number_of_replicas").asText(null);
|
||||
String autoExpand = index.path("auto_expand_replicas").asText("false");
|
||||
if(!"false".equalsIgnoreCase(autoExpand) || String.valueOf(target).equals(current))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QuickSearchDiagnosticsOperations.RawResponse put = operations.raw("PUT", "/" + QuickSearchDiagnosticsOperations.encode(entry.getKey()) + "/_settings",
|
||||
"{\"index\":{\"number_of_replicas\":" + target + "}}");
|
||||
QuickSearchDiagnosticsOperations.requireOk(put, "Updating number_of_replicas failed");
|
||||
updated++;
|
||||
LOG.info("Updated Quick Search index replicas", logPair("physicalIndex", entry.getKey()), logPair("from", current),
|
||||
logPair("to", target), logPair("dataNodes", nodes));
|
||||
}
|
||||
replicaStatus = new ReplicaStatus(target, nodes, updated, false);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn("Could not reconcile Quick Search index replicas; continuing", e, logPair("indexName", indexName), logPair("targetReplicas", target));
|
||||
replicaStatus = new ReplicaStatus(target, nodes, 0, true);
|
||||
}
|
||||
return (replicaStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The latest replica sizing outcome; null before any (or on Serverless).
|
||||
*******************************************************************************/
|
||||
public ReplicaStatus getReplicaStatus()
|
||||
{
|
||||
return (replicaStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -154,6 +154,11 @@ components:
|
||||
\ backlog rows."
|
||||
nullable: true
|
||||
type: "integer"
|
||||
replicaSettingsFailed:
|
||||
description: "Sizing or applying the index replicas failed at startup; null\
|
||||
\ when not attempted."
|
||||
nullable: true
|
||||
type: "boolean"
|
||||
state:
|
||||
description: "Overall availability; incomplete diagnostics are DEGRADED."
|
||||
enum:
|
||||
@@ -167,6 +172,16 @@ components:
|
||||
description: "More than 100 index rows exist."
|
||||
nullable: false
|
||||
type: "boolean"
|
||||
targetReplicas:
|
||||
description: "number_of_replicas Quick Search applies to its index; null\
|
||||
\ when unknown or not managed (Serverless)."
|
||||
nullable: true
|
||||
type: "integer"
|
||||
unassignedReplicaShards:
|
||||
description: "Unassigned shards when every primary is active (all are replicas);\
|
||||
\ null when unknown or a primary is not active."
|
||||
nullable: true
|
||||
type: "integer"
|
||||
unassignedShards:
|
||||
description: "Cluster health counter; null when unavailable."
|
||||
nullable: true
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.kingsrook.qbits.quicksearch.annotations.QuickSearchField;
|
||||
import com.kingsrook.qbits.quicksearch.annotations.QuickSearchable;
|
||||
import com.kingsrook.qbits.quicksearch.opensearch.BulkIndexResult;
|
||||
import com.kingsrook.qbits.quicksearch.opensearch.OpenSearchDocument;
|
||||
import com.kingsrook.qbits.quicksearch.opensearch.QuickSearchDiagnosticsOperations;
|
||||
import com.kingsrook.qbits.quicksearch.opensearch.QuickSearchOpenSearchClient;
|
||||
import com.kingsrook.qbits.quicksearch.processes.FullReindexStep;
|
||||
import com.kingsrook.qbits.quicksearch.processes.ReconcileIndexStep;
|
||||
@@ -218,6 +219,14 @@ class OpenSearchIntegrationTest
|
||||
assertThat(physicalIndexes.iterator().next()).startsWith(INDEX_NAME + "-v" + QuickSearchOpenSearchClient.MAPPING_VERSION + "-");
|
||||
assertThat(client().isMappingOutdated()).isFalse();
|
||||
assertThat(client().isHealthy()).isTrue();
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// zero config on a single node: no replica, so the index is green //
|
||||
////////////////////////////////////////////////////////////////////
|
||||
String physicalIndex = physicalIndexes.iterator().next();
|
||||
QuickSearchDiagnosticsOperations operations = new QuickSearchDiagnosticsOperations(client());
|
||||
assertThat(operations.settings().body().path(physicalIndex).path("settings").path("index").path("number_of_replicas").asText()).isEqualTo("0");
|
||||
assertThat(operations.clusterHealth().body().path("status").asText()).isEqualTo("green");
|
||||
}
|
||||
|
||||
|
||||
@@ -520,6 +529,27 @@ class OpenSearchIntegrationTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Test 12: an index left with a replica it cannot place on one node (yellow)
|
||||
** is brought back to 0 replicas (green) by the startup reconcile, once.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
@Order(12)
|
||||
void testReconcileReplicas_singleNodeDropsUnassignableReplica() throws Exception
|
||||
{
|
||||
String physicalIndex = client().getPhysicalIndexes().iterator().next();
|
||||
QuickSearchDiagnosticsOperations operations = new QuickSearchDiagnosticsOperations(client());
|
||||
assertThat(operations.raw("PUT", "/" + physicalIndex + "/_settings", "{\"index\":{\"number_of_replicas\":1}}").isOk()).isTrue();
|
||||
assertThat(operations.clusterHealth().body().path("status").asText()).isEqualTo("yellow");
|
||||
|
||||
assertThat(client().reconcileReplicas()).isEqualTo(new QuickSearchOpenSearchClient.ReplicaStatus(0, 1, 1, false));
|
||||
assertThat(operations.settings().body().path(physicalIndex).path("settings").path("index").path("number_of_replicas").asText()).isEqualTo("0");
|
||||
assertThat(operations.clusterHealth().body().path("status").asText()).isEqualTo("green");
|
||||
assertThat(client().reconcileReplicas()).isEqualTo(new QuickSearchOpenSearchClient.ReplicaStatus(0, 1, 0, false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Rebuild one table in place and refresh so its documents are searchable.
|
||||
*******************************************************************************/
|
||||
|
||||
+5
-1
@@ -348,7 +348,11 @@ class QuickSearchQBitConfigValidationTest
|
||||
.withBasepullOverlapSeconds(-5)
|
||||
.withRunHistoryRetentionDays(0)
|
||||
.withFullReindexStaleMinutes(0)
|
||||
.withMaxFieldLength(0));
|
||||
.withMaxFieldLength(0)
|
||||
.withIndexReplicas(-1)
|
||||
.withMaxAutoReplicas(-1));
|
||||
assertThat(errors).anyMatch(e -> e.startsWith("indexReplicas"));
|
||||
assertThat(errors).anyMatch(e -> e.startsWith("maxAutoReplicas"));
|
||||
assertThat(errors).anyMatch(e -> e.startsWith("connectTimeoutMillis"));
|
||||
assertThat(errors).anyMatch(e -> e.startsWith("responseTimeoutMillis"));
|
||||
assertThat(errors).anyMatch(e -> e.startsWith("maxConnections"));
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.qbits.QBitMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSystemUserSession;
|
||||
import com.kingsrook.qbits.quicksearch.model.QuickSearchIndex;
|
||||
import com.kingsrook.qbits.quicksearch.model.QuickSearchIndexField;
|
||||
import com.kingsrook.qbits.quicksearch.publisher.IndexEventPublisher;
|
||||
@@ -223,4 +224,31 @@ class QuickSearchRuntimeTest extends BaseQuickSearchTest
|
||||
failFast.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Priming at startup without a QContext builds the system session with the
|
||||
** start instance (so it has the all-access keys), not from the empty context.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void primeConfigWithoutAContextGivesTheSystemSessionItsInstance()
|
||||
{
|
||||
QInstance qInstance = QContext.getQInstance();
|
||||
QuickSearchRuntime runtime = new QuickSearchRuntime(new QuickSearchQBitConfig().withBackendName(TEST_BACKEND_NAME).withOpensearchHost("127.0.0.1").withOpensearchPort(1).withOpensearchIndexName("t"));
|
||||
QCollectingLogger collectingLogger = QLogger.activateCollectingLoggerForClass(QSystemUserSession.class);
|
||||
try
|
||||
{
|
||||
runtime.setStartInstance(qInstance);
|
||||
QContext.clear();
|
||||
runtime.primeConfig();
|
||||
}
|
||||
finally
|
||||
{
|
||||
QLogger.deactivateCollectingLoggerForClass(QSystemUserSession.class);
|
||||
QContext.init(qInstance, new QSystemUserSession(qInstance));
|
||||
runtime.close();
|
||||
}
|
||||
assertThat(collectingLogger.getCollectedMessages()).noneSatisfy(m -> assertThat(m.getMessage()).contains("QInstance was not supplied"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,6 +80,7 @@ class QuickSearchStatusTest
|
||||
private QuickSearchQBitConfig config;
|
||||
private QInstance instance;
|
||||
private volatile String health = "green";
|
||||
private volatile String extraHealth = ",\"number_of_nodes\":1,\"active_shards\":1,\"unassigned_shards\":0";
|
||||
private volatile int requests;
|
||||
private CountDownLatch blocked;
|
||||
|
||||
@@ -106,7 +107,7 @@ class QuickSearchStatusTest
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
byte[] body = ("{\"status\":\"" + health + "\",\"number_of_nodes\":1,\"active_shards\":1,\"unassigned_shards\":0}").getBytes(StandardCharsets.UTF_8);
|
||||
byte[] body = ("{\"status\":\"" + health + "\"" + extraHealth + "}").getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().add("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
@@ -214,6 +215,36 @@ class QuickSearchStatusTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Yellow from replicas a single node cannot hold is OK; an inactive primary
|
||||
** or a second node keeps it DEGRADED.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void singleNodeReplicaYellow() throws Exception
|
||||
{
|
||||
health = "yellow";
|
||||
String index = ",\"indices\":{\"status-test-v2-1\":{\"number_of_shards\":1,\"active_primary_shards\":%d}}";
|
||||
extraHealth = ",\"number_of_nodes\":1,\"active_shards\":1,\"unassigned_shards\":1,\"initializing_shards\":0" + index.formatted(1);
|
||||
QuickSearchStatus single = StatusDiagnostics.read(config.getRuntime());
|
||||
assertThat(single.state()).isEqualTo(QuickSearchStatus.State.OK);
|
||||
assertThat(single.unassignedReplicaShards()).isEqualTo(1);
|
||||
|
||||
extraHealth = ",\"number_of_nodes\":1,\"active_shards\":0,\"unassigned_shards\":2,\"initializing_shards\":0" + index.formatted(0);
|
||||
QuickSearchStatus primaryMissing = StatusDiagnostics.read(config.getRuntime());
|
||||
assertThat(primaryMissing.state()).isEqualTo(QuickSearchStatus.State.DEGRADED);
|
||||
assertThat(primaryMissing.unassignedReplicaShards()).isNull();
|
||||
|
||||
extraHealth = ",\"number_of_nodes\":1,\"active_shards\":0,\"unassigned_shards\":1,\"initializing_shards\":1" + index.formatted(1);
|
||||
assertThat(StatusDiagnostics.read(config.getRuntime()).unassignedReplicaShards()).isNull();
|
||||
|
||||
extraHealth = ",\"number_of_nodes\":2,\"active_shards\":1,\"unassigned_shards\":1,\"initializing_shards\":0" + index.formatted(1);
|
||||
QuickSearchStatus multi = StatusDiagnostics.read(config.getRuntime());
|
||||
assertThat(multi.state()).isEqualTo(QuickSearchStatus.State.DEGRADED);
|
||||
assertThat(multi.unassignedReplicaShards()).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A blocked remote call has bounded caller latency and cannot grow a queue.
|
||||
*******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* 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.quicksearch;
|
||||
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.quicksearch.annotations.QuickSearchField;
|
||||
import com.kingsrook.qbits.quicksearch.annotations.QuickSearchable;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QAuthenticationType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.authentication.QAuthenticationMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.DynamicDefaultValueBehavior;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryBackendModule;
|
||||
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** QQQ table standard: every table has a createDate and a modifyDate, typed
|
||||
** DATE_TIME, not editable, maintained by the CREATE_DATE and MODIFY_DATE
|
||||
** behaviors. The QBit writes all of its tables with QQQ's own insert and
|
||||
** update actions (no raw SQL), so the behaviors are what sets the values;
|
||||
** these tests walk every table the producer declares, so a table added later
|
||||
** without the two dates fails here.
|
||||
*******************************************************************************/
|
||||
class QuickSearchTableStandardDatesTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
** A searchable entity for the produced instance.
|
||||
*******************************************************************************/
|
||||
@QuickSearchable(tableName = "person")
|
||||
static class PersonEntity
|
||||
{
|
||||
@QuickSearchField(weight = 3)
|
||||
private String name;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void setUp()
|
||||
{
|
||||
MemoryRecordStore.getInstance().reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@AfterEach
|
||||
void tearDown()
|
||||
{
|
||||
QContext.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Every table the producer declares has both dates, as the standard says.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyTableHasTheTwoStandardDates()
|
||||
{
|
||||
for(QTableMetaData table : quickSearchTables(producedInstance()))
|
||||
{
|
||||
QFieldMetaData createDate = table.getFields().get("createDate");
|
||||
QFieldMetaData modifyDate = table.getFields().get("modifyDate");
|
||||
|
||||
assertThat(createDate).as(table.getName() + " createDate").isNotNull();
|
||||
assertThat(createDate.getType()).as(table.getName() + " createDate type").isEqualTo(QFieldType.DATE_TIME);
|
||||
assertThat(createDate.getIsEditable()).as(table.getName() + " createDate editable").isFalse();
|
||||
assertThat(createDate.getBehaviors()).as(table.getName() + " createDate behaviors").contains(DynamicDefaultValueBehavior.CREATE_DATE);
|
||||
|
||||
assertThat(modifyDate).as(table.getName() + " modifyDate").isNotNull();
|
||||
assertThat(modifyDate.getType()).as(table.getName() + " modifyDate type").isEqualTo(QFieldType.DATE_TIME);
|
||||
assertThat(modifyDate.getIsEditable()).as(table.getName() + " modifyDate editable").isFalse();
|
||||
assertThat(modifyDate.getBehaviors()).as(table.getName() + " modifyDate behaviors").contains(DynamicDefaultValueBehavior.MODIFY_DATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The entities that stand for the tables carry both dates too, so a row read
|
||||
** back as an entity shows them.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void everyEntityHasTheTwoStandardDates()
|
||||
{
|
||||
List<Class<?>> entities = List.of(
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchIndex.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchIndexField.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchIndexRun.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchSettings.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchConfigTombstone.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchFailedEvent.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchDiagnosticEvent.class,
|
||||
com.kingsrook.qbits.quicksearch.model.QuickSearchValidationRun.class);
|
||||
assertThat(entities).hasSize(quickSearchTables(producedInstance()).size());
|
||||
for(Class<?> entity : entities)
|
||||
{
|
||||
assertThat(entity.getDeclaredFields()).extracting(java.lang.reflect.Field::getName)
|
||||
.as(entity.getSimpleName()).contains("createDate", "modifyDate");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Inserting a row, with QQQ's own insert action (the only way the QBit writes
|
||||
** these tables), sets both dates; an update moves modifyDate and leaves
|
||||
** createDate alone.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void insertSetsBothDatesAndUpdateMovesModifyDateOnly() throws Exception
|
||||
{
|
||||
QInstance qInstance = producedInstance();
|
||||
for(QTableMetaData table : quickSearchTables(qInstance))
|
||||
{
|
||||
QRecord inserted = new InsertAction().execute(new InsertInput(table.getName()).withRecord(minimalRecord(table))).getRecords().get(0);
|
||||
assertThat(inserted.getErrors()).as(table.getName() + " insert errors").isEmpty();
|
||||
|
||||
Instant createDate = inserted.getValueInstant("createDate");
|
||||
Instant modifyDate = inserted.getValueInstant("modifyDate");
|
||||
assertThat(createDate).as(table.getName() + " createDate after insert").isNotNull();
|
||||
assertThat(modifyDate).as(table.getName() + " modifyDate after insert").isNotNull();
|
||||
|
||||
String changeField = changeableField(table);
|
||||
if(changeField == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Thread.sleep(20);
|
||||
QRecord update = new QRecord().withValue(table.getPrimaryKeyField(), inserted.getValue(table.getPrimaryKeyField())).withValue(changeField, changedValue(table.getField(changeField)));
|
||||
QRecord updated = new UpdateAction().execute(new UpdateInput(table.getName()).withRecord(update)).getRecords().get(0);
|
||||
assertThat(updated.getErrors()).as(table.getName() + " update errors").isEmpty();
|
||||
|
||||
assertThat(updated.getValueInstant("modifyDate")).as(table.getName() + " modifyDate after update").isAfter(modifyDate);
|
||||
assertThat(updated.getValueInstant("createDate") == null || updated.getValueInstant("createDate").equals(createDate))
|
||||
.as(table.getName() + " createDate after update").isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** The full reindex heartbeat writes a bare modifyDate: that still works, and
|
||||
** the value is not older than what was there.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void heartbeatWriteOfModifyDateOnlyStillMovesModifyDate() throws Exception
|
||||
{
|
||||
QInstance qInstance = producedInstance();
|
||||
QTableMetaData runTable = qInstance.getTable("quick_search_index_run");
|
||||
QRecord inserted = new InsertAction().execute(new InsertInput(runTable.getName()).withRecord(minimalRecord(runTable))).getRecords().get(0);
|
||||
Instant before = inserted.getValueInstant("modifyDate");
|
||||
|
||||
Thread.sleep(20);
|
||||
QRecord heartbeat = new QRecord().withValue("id", inserted.getValue("id")).withValue("modifyDate", Instant.now());
|
||||
QRecord updated = new UpdateAction().execute(new UpdateInput(runTable.getName()).withRecord(heartbeat)).getRecords().get(0);
|
||||
assertThat(updated.getValueInstant("modifyDate")).isAfter(before);
|
||||
assertThat(updated.getErrors()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A record with only what the table requires.
|
||||
*******************************************************************************/
|
||||
private QRecord minimalRecord(QTableMetaData table)
|
||||
{
|
||||
QRecord record = new QRecord();
|
||||
switch(table.getName())
|
||||
{
|
||||
case "quick_search_index" -> record.withValue("tableName", "person");
|
||||
case "quick_search_index_field" -> record.withValue("quickSearchIndexId", 1).withValue("fieldName", "name");
|
||||
default ->
|
||||
{
|
||||
}
|
||||
}
|
||||
return (record);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** A plain text or number field, not a key, a date or a possible-value
|
||||
** picker, that an update can change; null if the table has none.
|
||||
*******************************************************************************/
|
||||
private String changeableField(QTableMetaData table)
|
||||
{
|
||||
return (table.getFields().values().stream()
|
||||
.filter(f -> !f.getName().equals(table.getPrimaryKeyField()))
|
||||
.filter(f -> f.getPossibleValueSourceName() == null)
|
||||
.filter(f -> f.getType() == QFieldType.STRING || f.getType() == QFieldType.INTEGER)
|
||||
.map(QFieldMetaData::getName)
|
||||
.findFirst().orElse(null));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private java.io.Serializable changedValue(QFieldMetaData field)
|
||||
{
|
||||
return (field.getType() == QFieldType.INTEGER ? Integer.valueOf(7) : "changed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private List<QTableMetaData> quickSearchTables(QInstance qInstance)
|
||||
{
|
||||
List<QTableMetaData> tables = qInstance.getTables().values().stream()
|
||||
.filter(t -> t.getName().startsWith("quick_search_"))
|
||||
.sorted((a, b) -> a.getName().compareTo(b.getName()))
|
||||
.toList();
|
||||
assertThat(tables).as("the tables this QBit declares").hasSize(8);
|
||||
return (tables);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private QInstance producedInstance()
|
||||
{
|
||||
try
|
||||
{
|
||||
QInstance qInstance = new QInstance();
|
||||
qInstance.addBackend(new QBackendMetaData().withName("memory").withBackendType(MemoryBackendModule.class));
|
||||
qInstance.withInstanceDefaultAuthentication(new QAuthenticationMetaData().withName("anonymous").withType(QAuthenticationType.FULLY_ANONYMOUS));
|
||||
qInstance.addTable(new QTableMetaData().withName("person").withBackendName("memory").withPrimaryKeyField("id")
|
||||
.withField(new QFieldMetaData("id", QFieldType.INTEGER).withIsEditable(false))
|
||||
.withField(new QFieldMetaData("name", QFieldType.STRING))
|
||||
.withField(new QFieldMetaData("modifyDate", QFieldType.DATE_TIME)));
|
||||
QContext.init(qInstance, new QSession());
|
||||
new QuickSearchQBitProducer().withConfig(new QuickSearchQBitConfig()
|
||||
.withStartupMode(QuickSearchStartupMode.DEGRADED)
|
||||
.withBackendName("memory")
|
||||
.withOpensearchHost("localhost")
|
||||
.withOpensearchPort(9200)
|
||||
.withOpensearchIndexName("table-standard")
|
||||
.withSearchableEntityClasses(List.of(PersonEntity.class))).produce(qInstance);
|
||||
return (qInstance);
|
||||
}
|
||||
catch(QException e)
|
||||
{
|
||||
throw (new IllegalStateException(e));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -168,6 +168,28 @@ class QuickSearchHealthChecksTest extends BaseQuickSearchTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Yellow is healthy only on one node with every unassigned shard a replica.
|
||||
*******************************************************************************/
|
||||
@ParameterizedTest
|
||||
@CsvSource({"yellow,1,1,UP", "yellow,1,0,DEGRADED", "yellow,1,,DEGRADED", "yellow,2,1,DEGRADED", "yellow,,1,DEGRADED",
|
||||
"green,1,0,UP", "red,1,1,DOWN"})
|
||||
void singleNodeReplicas(String color, Integer nodes, Integer unassignedReplicas, HealthStatus expected) throws Exception
|
||||
{
|
||||
when(cache.get(eq(runtime), any(Instant.class))).thenReturn(new QuickSearchStatus(State.OK, true, color, nodes, 1, 1, unassignedReplicas, 0, false,
|
||||
false, List.of(row(true, "ACTIVE", 12L, 12L, null, 0)), 0, 0, false, false, null, SENTINEL, Instant.now(), "/unused"));
|
||||
HealthCheckOutcome outcome = run("opensearch");
|
||||
assertThat(outcome.getStatus()).isEqualTo(expected);
|
||||
assertThat(outcome.getDetails().toJson()).contains("\"targetReplicas\":0", "\"replicaSettingsFailed\":false");
|
||||
if(expected == HealthStatus.UP && "yellow".equals(color))
|
||||
{
|
||||
assertThat(outcome.getDetails().toJson()).contains("\"unassignedReplicaShards\":1", "replicas cannot be assigned on a single-node cluster");
|
||||
}
|
||||
assertClean(outcome);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Boundary values, exhausted events, pause, truncation and missing measurements.
|
||||
*******************************************************************************/
|
||||
|
||||
+274
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Copyright 2024 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.quicksearch.opensearch;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qbits.quicksearch.QuickSearchAuthMode;
|
||||
import com.kingsrook.qbits.quicksearch.QuickSearchQBitConfig;
|
||||
import com.kingsrook.qbits.quicksearch.opensearch.QuickSearchOpenSearchClient.ReplicaStatus;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Replica sizing and reconcile against a stub OpenSearch HTTP server.
|
||||
*******************************************************************************/
|
||||
class QuickSearchReplicasTest
|
||||
{
|
||||
private HttpServer server;
|
||||
private List<String> requests;
|
||||
private List<String> bodies;
|
||||
private Integer dataNodes;
|
||||
private String settings;
|
||||
private Integer settingsStatus;
|
||||
private Integer putStatus;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Stub: _cluster/health reports dataNodes, GET _settings returns settings,
|
||||
** PUT _settings returns putStatus; every request is recorded.
|
||||
*******************************************************************************/
|
||||
@BeforeEach
|
||||
void setUp() throws IOException
|
||||
{
|
||||
requests = new ArrayList<>();
|
||||
bodies = new ArrayList<>();
|
||||
dataNodes = 1;
|
||||
settingsStatus = 200;
|
||||
putStatus = 200;
|
||||
settings = settingsBody("1", null);
|
||||
server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
server.createContext("/", this::handle);
|
||||
server.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@AfterEach
|
||||
void tearDown()
|
||||
{
|
||||
server.stop(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private void handle(HttpExchange exchange) throws IOException
|
||||
{
|
||||
String request = exchange.getRequestMethod() + " " + exchange.getRequestURI().getPath();
|
||||
requests.add(request);
|
||||
bodies.add(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8));
|
||||
int status = 200;
|
||||
String body = "{}";
|
||||
if(request.equals("GET /_cluster/health"))
|
||||
{
|
||||
body = dataNodes == null ? "{\"status\":\"green\"}" : "{\"status\":\"yellow\",\"number_of_data_nodes\":" + dataNodes + "}";
|
||||
}
|
||||
else if(request.startsWith("GET ") && request.endsWith("/_settings"))
|
||||
{
|
||||
status = settingsStatus;
|
||||
body = status == 200 ? settings : "{\"error\":{\"reason\":\"nope\"}}";
|
||||
}
|
||||
else if(request.startsWith("PUT ") && request.endsWith("/_settings"))
|
||||
{
|
||||
status = putStatus;
|
||||
body = status == 200 ? "{\"acknowledged\":true}" : "{\"error\":{\"reason\":\"blocked\"}}";
|
||||
}
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().add("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(status, bytes.length);
|
||||
exchange.getResponseBody().write(bytes);
|
||||
exchange.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static String settingsBody(String replicas, String autoExpand)
|
||||
{
|
||||
return ("{\"alias-v2-1\":{\"settings\":{\"index\":{\"number_of_shards\":\"1\",\"number_of_replicas\":\"" + replicas + "\""
|
||||
+ (autoExpand == null ? "" : ",\"auto_expand_replicas\":\"" + autoExpand + "\"") + "}}}}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private QuickSearchQBitConfig config()
|
||||
{
|
||||
return (new QuickSearchQBitConfig().withOpensearchUrl("http://127.0.0.1:" + server.getAddress().getPort()).withOpensearchIndexName("alias"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Automatic sizing never exceeds data nodes - 1 nor maxAutoReplicas.
|
||||
*******************************************************************************/
|
||||
@ParameterizedTest
|
||||
@CsvSource({"1,1,0", "2,1,1", "3,1,1", "3,2,2", "5,2,2", "0,1,0", "4,0,0"})
|
||||
void autoReplicas(int nodes, int max, int expected)
|
||||
{
|
||||
assertThat(QuickSearchOpenSearchClient.autoReplicas(nodes, max)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Zero config on one node: the replica is dropped, once.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void singleNodeDropsReplicaIdempotently() throws Exception
|
||||
{
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config()))
|
||||
{
|
||||
ReplicaStatus status = client.reconcileReplicas();
|
||||
assertThat(status).isEqualTo(new ReplicaStatus(0, 1, 1, false));
|
||||
assertThat(client.getReplicaStatus()).isEqualTo(status);
|
||||
assertThat(requests).contains("PUT /alias-v2-1/_settings");
|
||||
assertThat(bodies.get(requests.indexOf("PUT /alias-v2-1/_settings"))).isEqualTo("{\"index\":{\"number_of_replicas\":0}}");
|
||||
|
||||
settings = settingsBody("0", null);
|
||||
requests.clear();
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(0, 1, 0, false));
|
||||
assertThat(requests).noneMatch(request -> request.startsWith("PUT"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Multi-node clusters keep (or get) one replica by default.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void multiNodeKeepsOneReplica() throws Exception
|
||||
{
|
||||
dataNodes = 3;
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config()))
|
||||
{
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(1, 3, 0, false));
|
||||
assertThat(requests).noneMatch(request -> request.startsWith("PUT"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** An explicit indexReplicas wins and does not need cluster health.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void explicitReplicasOverrideAuto() throws Exception
|
||||
{
|
||||
settings = settingsBody("0", null);
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config().withIndexReplicas(2)))
|
||||
{
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(2, null, 1, false));
|
||||
assertThat(requests).doesNotContain("GET /_cluster/health");
|
||||
assertThat(bodies.get(requests.indexOf("PUT /alias-v2-1/_settings"))).isEqualTo("{\"index\":{\"number_of_replicas\":2}}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** An operator's auto_expand_replicas is left alone.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void autoExpandIsRespected() throws Exception
|
||||
{
|
||||
settings = settingsBody("1", "0-1");
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config()))
|
||||
{
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(0, 1, 0, false));
|
||||
assertThat(requests).noneMatch(request -> request.startsWith("PUT"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Failures are recorded, never thrown.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void failuresAreToleratedAndRecorded() throws Exception
|
||||
{
|
||||
putStatus = 403;
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config()))
|
||||
{
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(0, 1, 0, true));
|
||||
|
||||
settingsStatus = 500;
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(0, 1, 0, true));
|
||||
|
||||
dataNodes = null;
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(null, null, 0, true));
|
||||
assertThat(client.getReplicaStatus().failed()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** An unreachable cluster is a recorded failure too.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void unreachableIsRecorded() throws Exception
|
||||
{
|
||||
QuickSearchQBitConfig config = config();
|
||||
server.stop(0);
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config.withConnectTimeoutMillis(500)))
|
||||
{
|
||||
assertThat(client.reconcileReplicas()).isEqualTo(new ReplicaStatus(null, null, 0, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** OpenSearch Serverless manages replicas itself: nothing is sent.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void serverlessIsNotManaged() throws Exception
|
||||
{
|
||||
QuickSearchQBitConfig config = config().withAuthMode(QuickSearchAuthMode.AWS_SIGV4).withAwsServiceName("aoss").withAwsRegion("us-east-1");
|
||||
try(QuickSearchOpenSearchClient client = new QuickSearchOpenSearchClient(config))
|
||||
{
|
||||
assertThat(client.reconcileReplicas()).isNull();
|
||||
assertThat(client.getReplicaStatus()).isNull();
|
||||
assertThat(requests).isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -989,7 +989,10 @@ class FullReindexStepTest extends BaseQuickSearchTest
|
||||
}
|
||||
};
|
||||
|
||||
Instant before = Instant.now();
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// the MODIFY_DATE behavior stamps modifyDate to the millisecond, so compare at that //
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
Instant before = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
||||
step.indexAllRecords(mockClient, QuickSearchQBitContext.getTableConfig(TEST_ENTITY_TABLE), List.of(), PHYSICAL_INDEX,
|
||||
new QuickSearchIndexRun().withId(runId).withRunType(FullReindexStep.RUN_TYPE));
|
||||
|
||||
|
||||
Reference in new issue
Block a user