[PDB-2843] Exceptions when using functions Created: 2016/06/26  Updated: 2017/03/15  Resolved: 2016/08/02

Status: Closed
Project: PuppetDB
Component/s: PuppetDB
Affects Version/s: None
Fix Version/s: PDB 4.2.0

Type: Bug Priority: Normal
Reporter: Dylan Ratcliffe Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Story Points: 1

 Description   

When using any of the PQL functions it is very easy to get PuppetDB to throw a Input to munge-result-row does not match schema error. When this is thrown PuppetDB never responds to the query, causing it to timeout.

All queries below are calling the root endpoint i.e. http://(master):8080/pdb/query/v4?query=(query)

e.g. The following query:

fact_contents[value] { path ~> ["memory",".*","available_bytes"] }

Returns the following data as expected:

[
  {
    "value": 693243904
  },
  {
    "value": 693268480
  },
  {
    "value": 3061817344
  }
]

However if I try to average these numbers:

fact_contents[avg(value)] { path ~> ["memory",".*","available_bytes"] }

I get the following exception in the PuppetDB logs:

clojure.lang.ExceptionInfo: Input to munge-result-row does not match schema: [(named {:avg disallowed-key} row)]
        at puppetlabs.puppetdb.query.fact_contents$eval26634$munge_result_row__26639.invoke(fact_contents.clj:22) ~[na:na]
        at clojure.core$map$fn__4785.invoke(core.clj:2646) ~[puppetdb.jar:na]
        at clojure.lang.LazySeq.sval(LazySeq.java:40) ~[puppetdb.jar:na]
        at clojure.lang.LazySeq.seq(LazySeq.java:49) ~[puppetdb.jar:na]
        at clojure.lang.LazySeq.first(LazySeq.java:71) ~[puppetdb.jar:na]
        at clojure.lang.RT.first(RT.java:667) ~[puppetdb.jar:na]
        at clojure.core$first__4339.invokeStatic(core.clj:55) ~[puppetdb.jar:na]
        at clojure.core$first__4339.invoke(core.clj:55) ~[puppetdb.jar:na]
        at puppetlabs.puppetdb.query_eng$eval26835$produce_streaming_body__26840$fn__26841$fn__26845$fn__26847$fn__26848$fn__26851.invoke(query_eng.clj:182) ~[na:na]
        at clojure.core$comp$fn__4727.invoke(core.clj:2460) ~[puppetdb.jar:na]
        at clojure.core$comp$fn__4727.invoke(core.clj:2460) ~[puppetdb.jar:na]
        at puppetlabs.puppetdb.jdbc$with_query_results_cursor$fn__21251.invoke(jdbc.clj:344) ~[na:na]
        at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:620) ~[na:na]
        at clojure.java.jdbc$db_transaction_STAR_.doInvoke(jdbc.clj:568) ~[na:na]
        at clojure.lang.RestFn.invoke(RestFn.java:425) ~[puppetdb.jar:na]
        at puppetlabs.puppetdb.jdbc$with_query_results_cursor.invokeStatic(jdbc.clj:337) ~[na:na]
        at puppetlabs.puppetdb.jdbc$with_query_results_cursor.invoke(jdbc.clj:326) ~[na:na]
        at puppetlabs.puppetdb.query_eng$eval26835$produce_streaming_body__26840$fn__26841$fn__26845$fn__26847$fn__26848.invoke(query_eng.clj:179) ~[na:na]
        at puppetlabs.puppetdb.jdbc$with_transacted_connection_fn$fn__21230$fn__21231.invoke(jdbc.clj:306) ~[na:na]

However if I try seemingly the exact same thing using a different entity:

facts[value] { certname ~ "agent" and name = "uptime_seconds"}

Returns:

[
  {
    "value": 20844
  },
  {
    "value": 20757
  }
]

And If I try to average it:

facts[avg(value)] { certname ~ "agent" and name = "uptime_seconds"}

It works:

[
  {
    "avg": 20800.5
  }
]

This seems weird given that the input data for each function seems to be in the exact same format. This not only applicable to the avg() function. In situations where it fails, it will fail regardless of the function that is used.



 Comments   
Comment by Wyatt Alt [ 2016/06/27 ]

The input and output schemas for the fact-contents munge function need to be wrapped with query/wrap-with-supported-fns. While we're at it we should double check that other endpoints didn't slip through the cracks.

Comment by Ryan Senior [ 2016/08/08 ]

Released with 4.2.0

Generated at Sat Dec 07 20:52:43 PST 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.