Uploaded image for project: 'PuppetDB'
  1. PuppetDB
  2. PDB-5026

Report type filter causes error in subquery

    XMLWordPrintable

    Details

    • Template:
    • Team:
      Ghost
    • Story Points:
      5
    • Sprint:
      ghost-19.05.2021, ghost-19.05.2021, ghost-2.06.2021, ghost-16.06.2021, ghost-30.06.2021, ghost-14.07.2021
    • Method Found:
      Manual Test
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      If the options (limit, offset, order_by) are provided to a subquery that uses "from", the context isn't switched to the entity from the "from" syntax. This behaviour results in an error when the subquery is made on the reports table. Eg.

      ["from" "nodes"
          ["and"
              ["in"
               "certname"
               ["from"
               "reports"
                    ["extract" "certname" ["=" "type" "agent"]]
                    ["limit" 1]
                    ["order_by" [["certname" "desc"]]]]]
              ["=" "node_state" "active"]]]
      Results in the following error:
      'type' is not a queryable object for nodes. Known queryable objects are 'cached_catalog_status', 'catalog_environment', 'catalog_timestamp', 'certname', 'deactivated', 'expired', 'facts_environment', 'facts_timestamp', 'latest_report_corrective_change', 'latest_report_hash', 'latest_report_job_id', 'latest_report_noop', 'latest_report_noop_pending', 'latest_report_status', 'report_environment', and 'report_timestamp'

      The change consists in ensuring that context is correctly set and switched when a subquery with "from" form is used.
      Show
      If the options (limit, offset, order_by) are provided to a subquery that uses "from", the context isn't switched to the entity from the "from" syntax. This behaviour results in an error when the subquery is made on the reports table. Eg. ["from" "nodes"     ["and"         ["in"          "certname"          ["from"          "reports"               ["extract" "certname" ["=" "type" "agent"]]               ["limit" 1]               ["order_by" [["certname" "desc"]]]]]         ["=" "node_state" "active"]]] Results in the following error: 'type' is not a queryable object for nodes. Known queryable objects are 'cached_catalog_status', 'catalog_environment', 'catalog_timestamp', 'certname', 'deactivated', 'expired', 'facts_environment', 'facts_timestamp', 'latest_report_corrective_change', 'latest_report_hash', 'latest_report_job_id', 'latest_report_noop', 'latest_report_noop_pending', 'latest_report_status', 'report_environment', and 'report_timestamp' The change consists in ensuring that context is correctly set and switched when a subquery with "from" form is used.
    • QA Risk Assessment:
      Needs Assessment

      Description

      curl -X POST http://localhost:8080/pdb/query/v4   -H 'Content-Type:application/json'   -d '{"query": ["from", "nodes", ["in", "certname", ["from", "reports", ["extract", "certname"], ["limit", 1], ["order_by", [["certname", "desc"]]]]]] }'
      

      Produces the AST with the agent filter in the proper spot.

      ["from" "nodes"
        ["and"
          ["in"
           "certname"
           ["from"
            "reports"
            ["extract" "certname" ["=" "type" "agent"]]
            ["limit" 1]
            ["order_by" [["certname" "desc"]]]]]
          ["=" "node_state" "active"]]]
      

      But the query engine does not accept it, so somewhere in the query engine the context is not switched from nodes to reports when going into a subquery.

      2021-02-16 09:52:01,746 ERROR [qtp2018597706-31] [p.p.query-eng] Error executing query '["from" "nodes" ["and" ["in" "certname" ["from" "reports" ["extract" "certname"] ["limit" 1] ["order_by" [["certname" "desc"]]]]] ["=" "node_state" "active"]]]' with query options '{:limit nil, :offset nil, :order_by nil, :node-purge-ttl #object[org.joda.time.Period 0x30cc2c0b "P14D"], :add-agent-report-filter true}'. Returning a 400 error code.
      java.lang.IllegalArgumentException: 'type' is not a queryable object for nodes. Known queryable objects are 'cached_catalog_status', 'catalog_environment', 'catalog_timestamp', 'certname', 'deactivated', 'expired', 'facts_environment', 'facts_timestamp', 'latest_report_corrective_change', 'latest_report_hash', 'latest_report_job_id', 'latest_report_noop', 'latest_report_noop_pending', 'latest_report_status', 'report_environment', and 'report_timestamp'
              at puppetlabs.puppetdb.query_eng.engine$push_down_context.invokeStatic(engine.clj:2581)
              at puppetlabs.puppetdb.query_eng.engine$push_down_context.invoke(engine.clj:2570)
              at puppetlabs.puppetdb.query_eng.engine$compile_query.invokeStatic(engine.clj:2994)
              at puppetlabs.puppetdb.query_eng.engine$compile_query.invoke(engine.clj:2973)
              at puppetlabs.puppetdb.query_eng.engine$compile_user_query__GT_sql.invokeStatic(engine.clj:3017)
              at puppetlabs.puppetdb.query_eng.engine$compile_user_query__GT_sql.invoke(engine.clj:3010)
              at puppetlabs.puppetdb.query_eng$query__GT_sql$fn__34966.invoke(query_eng.clj:172)
              at puppetlabs.puppetdb.query_eng$maybe_log_sql.invokeStatic(query_eng.clj:109)
              at puppetlabs.puppetdb.query_eng$maybe_log_sql.invoke(query_eng.clj:104)
              at puppetlabs.puppetdb.query_eng$query__GT_sql.invokeStatic(query_eng.clj:123)
              at puppetlabs.puppetdb.query_eng$query__GT_sql.invoke(query_eng.clj:111)
              at puppetlabs.puppetdb.query_eng$deprecated_produce_streaming_body$fn__35123.invoke(query_eng.clj:418)
              at puppetlabs.puppetdb.jdbc$with_transacted_connection_fn$fn__28358$fn__28359.invoke(jdbc.clj:513)
              at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:771)
              at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:741)
              at puppetlabs.puppetdb.jdbc$with_transacted_connection_fn$fn__28358.invoke(jdbc.clj:512)
              at puppetlabs.puppetdb.jdbc$retry_sql$attempt__28352.invoke(jdbc.clj:471)
              at puppetlabs.puppetdb.jdbc$retry_sql.invokeStatic(jdbc.clj:481)
              at puppetlabs.puppetdb.jdbc$retry_sql.invoke(jdbc.clj:462)
              at puppetlabs.puppetdb.jdbc$with_transacted_connection_fn.invokeStatic(jdbc.clj:511)
              at puppetlabs.puppetdb.jdbc$with_transacted_connection_fn.invoke(jdbc.clj:503)
              at puppetlabs.puppetdb.query_eng$deprecated_produce_streaming_body.invokeStatic(query_eng.clj:414)
              at puppetlabs.puppetdb.query_eng$deprecated_produce_streaming_body.invoke(query_eng.clj:398)
              at puppetlabs.puppetdb.query_eng$eval35154$produce_streaming_body__35159$fn__35160.invoke(query_eng.clj:468)
              at puppetlabs.puppetdb.query_eng$eval35154$produce_streaming_body__35159.invoke(query_eng.clj:458)
      ...
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:135)
              at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:773)
              at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:905)
              at java.lang.Thread.run(Thread.java:748)
      

        Attachments

          Activity

            People

            Assignee:
            oana.tanasoiu Oana Tanasoiu
            Reporter:
            austin.blatt Austin Blatt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support