Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PDB-5739) Reduce factsets "stable||volatile" merging #3972

Merged
merged 20 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
969b709
(PDB-5739) certname-names-query: migrate to certnames_status
rbrw Apr 24, 2024
e0808f8
(PDB-5739) clj-jdbc-termination-ex?: require SQLException
rbrw Apr 24, 2024
8b43bbe
(PDB-5739) Fix command service request-shutdown invocation
rbrw May 1, 2024
410177e
(PDB-5739) Prefer inventory in fact-related query docs
rbrw Apr 24, 2024
17ee84d
(PDB-5739) fact-query->sql: change stable||volatile to union
rbrw Apr 30, 2024
b0e92a4
(PDB-5739) fact-contents-core: change stable||volatile to union
rbrw Apr 30, 2024
1ef7736
(PDB-5739) factsets-query-base: change stable||volatile to union
rbrw Apr 24, 2024
18d7b84
(PDB-5739) drop-local-unused-joins-from-query: include cross-joins
rbrw Apr 25, 2024
47fb101
(PDB-5739) facts-query: change stable||volatile to union
rbrw Apr 25, 2024
d299c7a
(PDB-5739) -plan->sql AndExpression/OrExpression: produce vector
rbrw Apr 25, 2024
c9bd7ca
(PDB-5739) query-eng.engine: convert various raw operations to hsql
rbrw Apr 25, 2024
db5a70b
(PDB-5739) -plan->sql Query: nest via :nest not (str ...)
rbrw Apr 25, 2024
31a9755
(PDB-5739) jsonb-path-binary-expression: convert to hsql
rbrw Apr 25, 2024
7e00bac
(PDB-5739) hsql-hash-as-str hsql-hash-as-href: convert to hsql
rbrw Apr 25, 2024
853b806
(PDB-5739) fn-binary-expression-hsql: convert to hsql
rbrw Apr 25, 2024
a0bf73b
(PDB-5739) JsonContainsExpression: convert to hsql
rbrw Apr 25, 2024
979afa8
(PDB-5739) -plan->sql NullExpression: convert to hsql
rbrw Apr 25, 2024
f3ecea6
(PDB-5739) create-json-path-extraction: convert to hsql
rbrw Apr 29, 2024
e38db4b
(PDB-5739) inventory-query: convert stable||volatile to hsql
rbrw Apr 29, 2024
9df5ae2
(PDB-5745) rewrite-fact-query: convert to hsql
rbrw May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions documentation/api/query/v4/fact-contents.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ canonical: "/puppetdb/latest/api/query/v4/fact-contents.html"
[factsets]: ./factsets.markdown
[nodes]: ./nodes.markdown

You can query fact information with greater power by using the `/fact-contents`
endpoint. This endpoint provides the capability to descend into structured
facts and query tree nodes deep within this data by using the concept of paths
and values.
The `/fact-contents` endpoint provides selective access to factset
subtrees via `fact path`s. Note that the `inventory` endpoint will
often provide more flexible and efficient access to the same
information.


## Paths and Values
Structured facts can be thought of as trees. For example,
Expand Down
12 changes: 7 additions & 5 deletions documentation/api/query/v4/facts.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ canonical: "/puppetdb/latest/api/query/v4/facts.html"
[fact-contents]: ./fact-contents.markdown
[nodes]: ./nodes.markdown

You can query facts by making an HTTP request to the `/facts` endpoint.

In Puppet's world, you only interact with facts from one node at a time, so any given fact consists of only a **fact name** and a **value.** But because PuppetDB interacts with a whole population of nodes, each PuppetDB fact also includes a **certname** and an **environment.**
The `/facts` endpoint provides access to a represntation of node
factsets where a result is returned for each top-level key in the
node's structured factset. Note that the `inventory` endpoint will
often provide more flexible and efficient access to the same
information.

## `/pdb/query/v4/facts`

Expand All @@ -37,8 +39,8 @@ See [the AST query language page][ast].

### Query fields

* `name` (string): the name of the fact.
* `value` (string, numeric, Boolean): the value of the fact.
* `name` (string): the top-level name of the fact.
* `value` (json): the value of the fact.
* `certname` (string): the node associated with the fact.
* `environment` (string): the environment associated with the fact.

Expand Down
8 changes: 5 additions & 3 deletions documentation/api/query/v4/factsets.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ canonical: "/puppetdb/latest/api/query/v4/factsets.html"
[producers]: ./producers.markdown
[nodes]: ./nodes.markdown

You can query factsets by making an HTTP request to the `/factsets` endpoint.

A factset is the set of all facts for a single certname.
The `/factsets` endpoint provides access to a represntation of node
factsets where each result includes the structured facts for a node
broken down into a vector of top-level key/value pairs. Note that the
`inventory` endpoint will often provide more flexible and efficient
access to the same information.

## `/pdb/query/v4/factsets`

Expand Down
6 changes: 3 additions & 3 deletions documentation/api/query/v4/inventory.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ canonical: "/puppetdb/latest/api/query/v4/inventory.html"
[query]: query.markdown
[ast]: ./ast.markdown

The `/inventory` endpoint enables an alternative query syntax for digging into
structured facts, and can be used instead of the `facts`, `fact-contents`, and
`factsets` endpoints for most fact-related queries.
The `/inventory` endpoint provides an alternate and potentially more
efficient way to access structured facts as compared to the `facts`,
`fact-contents`, and `factsets` endpoints.

## `/pdb/query/v4/inventory`

Expand Down
3 changes: 2 additions & 1 deletion src/puppetlabs/puppetdb/command.clj
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,9 @@
(let [msg (trs "Unable to shut down delayed command scheduler, requesting server shutdown")]
(log/error msg)
(shut-down-after-command-scheduler-unresponsive
;; This fails request-shutdown schema validation during command-test
#(request-shutdown {:puppetlabs.trapperkeeper.core/exit
{:status 2 :messages [msg *err*]}})))))
{:status 2 :messages [[msg *err*]]}})))))

(def delay-pool-size
"Thread count for delaying messages for retry, and broadcast pool
Expand Down
15 changes: 2 additions & 13 deletions src/puppetlabs/puppetdb/jdbc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
(and (instance? ExceptionInfo ex)
(let [{:keys [rollback handling]} (ex-data ex)]
(and rollback
(instance? SQLException handling)
(= (sql-state :admin-shutdown)
(some-> handling .getSQLState))))))
(.getSQLState handling))))))

(defmacro with-db-connection [spec & body]
`(sql/with-db-connection [db# ~spec]
Expand Down Expand Up @@ -435,18 +436,6 @@
(.setType "text[]")
(.setValue (str \{ (str/join \, quoted) \})))))

;; Q: move/replace?
(defn create-json-path-extraction
"Given a base json field and a path of keys to traverse, construct the proper
SQL query of the form base->'key'->'key2'..."
[field path]
(str field
(when (seq path)
(->> (map single-quote path)
(str/join "->")
;; prefix for the first arrow in field->'key1'...
(str "->")))))

;; TODO this is no longer used by the main query engine (engine.clj), but it is
;; still used by the legacy query engines and should be removed once it is
;; handled by honeysql everywhere
Expand Down
10 changes: 6 additions & 4 deletions src/puppetlabs/puppetdb/query.clj
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,19 @@
FROM (SELECT certname,
producer_timestamp,
environment_id,
(jsonb_each((stable||volatile))).*
FROM factsets) fs
facts.*
FROM factsets,
lateral (select * from jsonb_each(stable)
union all select * from jsonb_each(volatile)) as facts) fs
LEFT JOIN environments env ON fs.environment_id = env.id
) AS facts
WHERE %s" (column-map->sql fact-columns) where)]
(apply vector sql params)))

(defn certname-names-query [active]
(if active
"SELECT name FROM certnames WHERE deactivated IS NULL AND expired IS NULL"
"SELECT name FROM certnames WHERE deactivated IS NOT NULL OR expired IS NOT NULL") )
"SELECT certname FROM certnames_status WHERE deactivated IS NULL AND expired IS NULL"
"SELECT certname FROM certnames_status WHERE deactivated IS NOT NULL OR expired IS NOT NULL"))

(defn compile-resource-equality
"Compile an = operator for a resource query. `path` represents the field
Expand Down
Loading
Loading