portal

sg-qwt 2023-09-14T17:32:11.921999Z

Recently discovered the mulog+portal combination, it is pretty cool. I'm wondering if I can run some custom query to gather some metrics(counter for example) from the portal sink? For example, if I publish mulog to cloudwatch, I can query the data like stats count(*) by app-name, mulog/event-name to gather matrics and insights, can I do the same with portal data?

seancorfield 2023-09-14T17:40:17.179479Z

Do you mean running queries across the atom containing the list of history (results) that Portal retains?

sg-qwt 2023-09-14T17:42:02.529199Z

yes, basically run query code on all history portal results, not sure if this is a valid use case:grinning:

djblue 2023-09-14T17:45:05.690929Z

So the easiest thing here might be to register the query function as a Portal command, something like (portal.api/register! #'my.query/fn) , then you can select the list and run the command via the command palette. Is that the type of UX you had in mind?

seancorfield 2023-09-14T17:45:57.545609Z

You can also control the atom (containing the history list) that Portal uses at startup so you can treat it just like regular Clojure data: https://github.com/seancorfield/vscode-calva-setup/blob/develop/calva/config.edn#L44-L90

👍 1
seancorfield 2023-09-14T17:47:49.226099Z

I have a REPL snippet to run arbitrary code on the most recent tap>'d value in Portal as well (see Tap Input Code immediately after the segment linked above).

djblue 2023-09-14T17:49:33.870179Z

The custom atom approach also has the benefit of allowing you to automatically compute these metrics as you accumulate logs

djblue 2023-09-14T17:52:52.793689Z

(def logs (atom {:metrics {}
                 :logs ^{:portal.viewer/default :portal.viewer/table} []}))

(defn submit [log]
  (swap! logs
         (fn [{:keys [metrics logs]}]
           (let [logs (conj logs log)]
             {:metrics (compute-metrics logs)
              :logs logs}))))

(portal.api/inspect logs)

seancorfield 2023-09-14T17:53:48.173799Z

@djblue I was just looking over the Portal code -- I don't think the default values atom is easy to get at, right? So you pretty much have to use a custom submit and your own history atom for this...

sg-qwt 2023-09-14T17:54:33.592329Z

Yeah, I think the Sean's custom atom approach is pretty much what I need. I'm quiet new to portal so I haven't tried the register function yet, I'll look into that as well. Is there api to just get the default atom instead of create a custom one?

djblue 2023-09-14T17:55:01.185409Z

Yeah, the default tap list atom is private since messing with it could break assumptions the default submit function makes

sg-qwt 2023-09-14T17:55:19.521009Z

ah, i see..

seancorfield 2023-09-14T17:55:41.290099Z

You could provide a history function in the API perhaps, that returns the current contents of that atom?

🤔 1