dave08
06/16/2024, 2:54 PM{"nodes": {"name": "...", ...., "pods": {...} } }
how can I get a table with all the pods and the name of the node they're on?Jolan Rensen [JB]
06/17/2024, 10:03 AMkeepParentNameForColumns = true
. However, in version 1.13.1 it had the wrong order, so to get the right order, you can manually rename each column with its path before flattening, like:
df
.rename { colsAtAnyDepth() }.into { it.path.joinToString(".") }
.flatten()
However, to give a more specific solution, could you share some more json? If you say "all nodes", it would assume it to have an array of objects, like { "nodes": [{ "name": "", pods: [{}, {}] }] }
.
In that case, you get what you want, you could explode and pivot your table, like in the attached picture.roman.belov
06/17/2024, 10:55 AMexplode
function will do the trickdave08
06/17/2024, 10:59 AMnodes: *
name: String
cpu:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
memory:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
pods: *
name: String
namespace: String
cpu:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
memory:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
clusterTotals:
cpu:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
memory:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
dave08
06/17/2024, 11:00 AMdave08
06/17/2024, 11:01 AMroman.belov
06/17/2024, 11:05 AMdave08
06/17/2024, 11:07 AMdave08
06/17/2024, 11:08 AMdave08
06/17/2024, 11:18 AMname: String
cpu.requests: String
cpu.requestsPercent: String
cpu.limits: String
cpu.limitsPercent: String
memory.requests: String
memory.requestsPercent: String
memory.limits: String
memory.limitsPercent: String
pods: *
name: String
namespace: String
cpu:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
memory:
requests: String
requestsPercent: String
limits: String
limitsPercent: String
dave08
06/17/2024, 11:20 AMJolan Rensen [JB]
06/17/2024, 11:35 AM.explode { pods }
which will convert the frame column into a column group, repeating the values of other columns where needed. I made a small notebook to show what I mean: https://gist.github.com/Jolanrensen/b3f6f4004c57600e25018b19f1f254c7dave08
06/17/2024, 11:49 AMname: String
name.pods: String
namespace.pods: String
requests.cpu: String
requestsPercent.cpu: String
limits.cpu: String
limitsPercent.cpu: String
requests.memory: String
requestsPercent.memory: String
limits.memory: String
limitsPercent.memory: String
And when I tried your renaming trick (which I'm not sure how it works in the first place...), it put pods before and after...dave08
06/17/2024, 11:53 AMname: String
pods.name.pods: String
pods.namespace.pods: String
pods.cpu.requests.pods.cpu: String
pods.cpu.requestsPercent.pods.cpu: String
pods.cpu.limits.pods.cpu: String
pods.cpu.limitsPercent.pods.cpu: String
pods.memory.requests.pods.memory: String
pods.memory.requestsPercent.pods.memory: String
pods.memory.limits.pods.memory: String
pods.memory.limitsPercent.pods.memory: String
Jolan Rensen [JB]
06/17/2024, 11:53 AMkeepParentNameForColumns
argument currently 😅. The trick works by selecting all columns at any depth (meaning also inside column groups, but not in nested dataframes) and renaming them to their path. So to do the renaming trick, you'd need to explode first, so all frame columns are turned into column groups, then rename and flatten, like:
https://gist.github.com/Jolanrensen/fd0c3a2e5ff91d3b51fe6b1132d8776e